MDP模型
一个扫地机械人的模型如下


确定情况的清洁机械人MDP
状态空间:X={0,1,2,3,4,5},其中:状态0和5为终止状态。
动作空间:U={-1,1}。
迁移函数:
奖赏函数:
确定情况下基于模型的值迭代算法

代码实现
1 | # -*- coding: UTF-8 -*- |
随机情况的清洁机械人MDP
随机情况下状态空间和动作空间与确定情况下的一样,主要是迁移函数和奖赏函数的不同,这里不在给出,在代码实现中体现。
随机情况下基于模型的值迭代算法

代码实现(异步版本)
1 | # -*- coding: UTF-8 -*- |
note
python 3.x 的版本已经没有 cmp() 函数,在进行列表、字典的比较时引入operator模块。operator模块使用与任何对象。
python中实现一个do-while循环:
1
2
3
4while True:
stuff()
if fail_condition:
breakor
1
2
3stuff()
while not fail_condition:
stuff()一个小tip:编写for循环时,对于用于存储列表中每个值的临时变量,可指定任何名称。然而,选择描述单个列表元素的有意义的名称大有帮助。例如,对于小猫列表、小狗列表和一般性列表,像下面这样编写for循环的第一行代码是不错的选择:
1
2
3for cat in cats:
for dog in dogs:
for item in list_of_items:这些命名约定有助于你明白for循环中将对每个元素执行的操作。使用单数和复数式名称,可帮助你判断代码段处理的是单个列表元素还是整个列表。