function A = choose_action( S, choices )
% 选择动作1,2,3,4,分别对应上下左右的动作
% greedy policy
global Maze_row Maze_col epsilon;
% 找到S对应的坐标
col = mod(S, Maze_col); % 列
if col == 0
col = Maze_col;
end
row = ceil(S/Maze_col); % 行
a = rand;
if col>1 && col<Maze_col && row>1 && row<Maze_row
if a>epsilon || ~any(choices)% 在初始状态都为0的时候保证随机选取,而不是总选择第一个
A = ceil(4*rand);
return
else
[maximum ,A] = max(choices);
return
end
elseif row == 1
if col == 1 % 在坐标(1,1), A=1 or 2
S_choices = [choices(1), choices(2)];
if a>epsilon || ~any(S_choices)
A = ceil(2*rand);
return
else
[maximum ,A] = max(S_choices);
return
end
elseif col == Maze_col % position(1,7), A = 1 or 4
S_choices = [choices(1), choices(4)];
if a>epsilon || ~any(S_choices)
A = ceil(2*rand);
else
[maximum ,A] = max(S_choices);
end
if A == 2
A = 4;
return
else
return
end
else % position between from (1,1) to (1,7) , action 1, 2, or 4
S_choices = [choices(1), choices(2), choices(4)];
if a>epsilon || ~any(S_choices)
A = ceil(3*rand);
else
[maximum ,A] = max(S_choices);
end
if A == 3
A = 4;
return
else
return
end
end
elseif row == Maze_row
if col == 1 % 在坐标(6,1), A=2 or 3
S_choices = [choices(2), choices(3)];
if a>epsilon || ~any(S_choices)
A = ceil(2*rand);
A = A+1;
return
else
[maximum ,A] = max(S_choices);
A = A+1;
return
end
elseif col == Maze_col % position(6,7), A = 3 or 4
S_choices = [choices(3), choices(4)];
if a>epsilon || ~any(S_choices)
A = ceil(2*rand);
A = A+2;
return
else
[maximum ,A] = max(S_choices);
A = A+2;
return
end
else % position between from (6,1) to (6,7) , action 2, 3, or 4
S_choices = [choices(2), choices(3), choices(4)];
if a>epsilon || ~any(S_choices)
A = ceil(3*rand);
A = A+1;
return
else
[maximum ,A] = max(S_choices);
A = A+1;
return
end
end
elseif col == 1 % 不包括顶点 A=1,2 or 3
S_choices = [choices(1), choices(2), choices(3)];
if a>epsilon || ~any(S_choices)
A = ceil(3*rand);
return
else
[maximum ,A] = max(S_choices);
return
end
elseif col == Maze_col % 不包括顶点 A=1,3 or 4
S_choices = [choices(1), choices(3), choices(4)];
if a>epsilon || ~any(S_choices)
A = ceil(3*rand);
else
[maximum ,A] = max(S_choices);
end
if A == 1
return
else
A = A+1;
return
end
end
end
matlab源代码强化学习算法二维地图.rar
版权申诉
5星 · 超过95%的资源 39 浏览量
2021-12-13
09:36:41
上传
评论
收藏 2KB RAR 举报
klaus_Xx
- 粉丝: 0
- 资源: 12
最新资源
- Flume进阶-自定义拦截器jar包
- Dubins曲线算法讲解和在运动规划中的使用.pdf
- 上市公司-股票性质数据-工具变量(民企、国企、央企)2003-2022年.dta
- 上市公司-股票性质数据-工具变量(民企、国企、央企)2003-2022年.xlsx
- Reeds+Shepp曲线算法讲解和实现.pdf
- 毕业设计基于SpringBoot+MyBatisPlus+MySQL+Vue的外卖配送信息系统源代码+数据库
- 词向量(Word Embeddings)是自然语言处理(NLP)领域的一种重要技术.txt
- Surfer,线性函数
- MyBatis 的动态 SQL 是其核心特性之一.txt
- 时代的sdddsddsddsd
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈