基于Qlearning的室内路径规划控制算法的matlab程序

1.问题描述:

 

假设我们的楼层内共有5个房间,房间之间通过一道门相连,正如下图所示。我们将房间编号为房间0到房间4,楼层的外部可以被看作是一间大房间,编号为5。注意到房间1和房间4可以直接通到房间5。可能在任意一间房间中放置一个智能体(机器人),并期望该智能体能够从该房间开始走出这栋楼(可以认为是我们的目标房间)。换句话说,智能体的目的地是房间5。为了设置这间房间作为目标,我们为每一道门(节点之间的边)赋予一个奖励值。能够直接通到目标房间的门赋予一及时奖励值100,而其他的未与目标房间直接相连的门赋予奖励值0。因为每一道门都有两个方向,因此,每一道门在图中将描述为两个箭头。

2.部分程序:

 

    % Two input: R and gamma
    % immediate reward matrix; 
    % row and column = states; -Inf = no door between room
    R=[-inf,-inf,-inf,-inf,   0, -inf;
       -inf,-inf,-inf,   0,-inf, 100;
       -inf,-inf,-inf,   0,-inf, -inf;
       -inf,   0,   0,-inf,   0, -inf;
          0,-inf,-inf,   0,-inf, 100;
       -inf,   0,-inf,-inf,   0, 100];

    gamma=0.80;            % learning parameter

    q=zeros(size(R));      % initialize Q as zero,q的行数和列数等于矩阵R的。
    q1=ones(size(R))*inf;  % initialize previous Q as big number
    count=0;               % counter

    for episode=0:50000
       % random initial state
       y=randperm(size(R,1));%产生1到6的随机数%a=size(R,1)把矩阵R的行数返回给a,b=size(R,2)把矩阵R的列数返回给b
       state=y(1);           %取1到6的随机数的第一个数
       
       % select any action from this state
       x=find(R(state,:)>=0);        % find possible action of this state.返回矩阵R第state行所有列中不小于零的数据的下标
       if size(x,1)>0,
          x1=RandomPermutation(x);   % randomize the possible action
          x1=x1(1);                  % select an action 
       end

       qMax=max(q,[],2);
       q(state,x1)= R(state,x1)+gamma*qMax(x1);   % get max of all actions 
       state=x1;
       
       % break if convergence: small deviation on q for 1000 consecutive
       if sum(sum(abs(q1-q)))<0.0001 & sum(sum(q >0))
          if count>1000,
             episode        % report last episode
             break          % for
          else
             count=count+1; % set counter if deviation of q is small
          end
       else
          q1=q;
          count=0; % reset counter when deviation of q from previous q is large
       end
    end 

    %normalize q
    g=max(max(q));
    if g>0, 
       q=100*q/g;
    end
      

3.仿真结论:

D28

 

  • 2
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

fpga和matlab

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值