您现在的位置:首页 >> 机器学习 >> 内容

基于强化学习的路径规划matlab仿真,对比QLearning和SARSA

时间:2024/7/9 5:17:41 点击:

  核心提示:0Z_007m,包括程序操作录像+参考文献...

1.完整项目描述和程序获取

>面包多安全交易平台:https://mbd.pub/o/bread/ZpiUmphu

>如果链接失效,可以直接打开本站店铺搜索相关店铺:

点击店铺

>如果链接失效,程序调试报错或者项目合作可以加微信或者QQ联系。

2.部分仿真图预览


3.算法概述

   强化学习(Reinforcement Learning, RL)是一种机器学习方法,它使代理(agent)通过与环境互动,学习采取何种行动以最大化累积奖励。在路径规划问题中,强化学习被用于自动探索环境,找到从起点到终点的最佳路径。其中,QLearning和SARSA是两种经典的价值迭代方法。

4.部分源码

.................................................................

    % 保存每轮数据

    step_save(iters) = step;

    Rwd1(iters) = Rwd3;

    Rwd2(iters) = Rwd3/step;

    Rwd3 = 0; % 重置累积奖励

    

    

    % 在到达目标后的额外步骤处理

    [next, temp] = func_next(current, action, Maps,temp, Rm, Cm);

    rewardNew = Rwd_stop;

    if func_Overlap(next,xy1) ~= 0

        if next.row == Rm && next.col >= 2 && next.col < Cm % 悬崖情况

            rewardNew = Rwd_n;

            next = xy0; % 回到起点

        end

    else

        rewardNew = Rwd_p;

    end

    

    

 

    % 再次应用Epsilon-greedy策略

    randN = 0 + (rand(1) * 1);

    if(randN > Lsearch)

        [~,nextAction] = max(Qtable0(next.row,next.col,:));

    else

        nextAction = round(1 + (rand(1) * 3));

    end

    

    nextQ    = Qtable0(next.row,next.col,nextAction);

    Qcur     = Qtable0(current.row, current.col, action);

    Qtable0(current.row, current.col, action) = Qcur + Lr * (rewardNew + Gma*nextQ - Qcur);

    

 

    if  iters == Miter

        temp2 = func_Episode(Qtable0,Rm,Cm,xy0,xy1,Maps,Nact);

      

 

        figure(2);

        subplot(311); 

        plot(1:iters, Rwd1, 'b');

        ylabel('每轮奖励之和')

        axis([0 iters min(Rwd1)-10 max(Rwd1+10)])

 

        subplot(312); 

        plot(1:iters, step_save, 'b');

        ylabel('步数');

        axis([0 iters 0 max(step_save+10)])

        xlabel('试验次数')

 

 

        subplot(313); 

        plot(1:iters, Rwd2, 'b');

        ylabel('每轮奖励平均值')

        axis([0 iters min(Rwd2)-10 max(Rwd2+10)])

        drawnow

    else

        Qtable1=Qtable0;

 

    end

    

    iters = iters + 1; % 迭代计数器增加

end

 

 

save R2.mat

0Z_007m

---

作者:我爱C编程 来源:我爱C编程
本站最新成功开发工程项目案例
相关文章
相关评论
发表我的评论
  • 大名:
  • 内容:
本类固顶
  • 没有
  • FPGA/MATLAB商业/科研类项目合作(www.store718.com) © 2025 版权所有 All Rights Reserved.
  • Email:1480526168@qq.com 站长QQ: 1480526168