之前写的一篇博客将离散和连续的动作空间都修改了,这里做一下更正。
基于十字路口的环境,为了添加舒适性评判指标,需要增加动作空间,主要添加两个不同加速度值的离散动作。
需要修改以下几个地方:
1.首先修改自己定义的环境文件(myIntersection_env.py):
在action中以字典的形式添加动作:
ACTIONS: Dict[int, str] = {
0: 'SLOWER',
1: 'IDLE',
2: 'FASTER',
3:'MOREFASTER',
4:'MORESLOWER'
}
2.其次需要修改highway_env/commom/action中动作的定义字典
ACTIONS_LONGI = {
0: 'SLOWER',
1: 'IDLE',
2: 'FASTER',
3: 'MOREFASTER',
4: 'MORESLOWER'
}
3.然后要修改highway_env/env/commom/action中get_available_actions方法中的限制,需要添加代码:
if self.controlled_vehicle.speed_index <self.controlled_vehicle.target_speeds.size - 1 and self.longitudinal:
actions.append(self.actions_indexes['MOREFASTER'])
if self.controlled_vehicle.speed_index > 0 and self.longitudinal:
actions.append(self.actions_indexes['MORESLOWER'])
4.需要修改highway-env/highway_env/vehicle/controller.py中动作的选取方法
修改动作的选取方法(MDPVehicle(ControlledVehicle)类的act方法),添加以下代码:
elif action == "MOREFASTER":
self.speed_index = self.speed_to_index(self8/eed) + 2
elif action == "MORESLOWER":
self.speed_index = self.speed_to_index(self.speed) - 2
5.最后需要修改target_speed
"target_speeds": [0,2.5,5,7.5,10],为了让车去跟踪这个速度,是以目标车速去跟踪,也就是说车速的变化是尽量的去参照这个目标速度去跟踪。因此离散的动作空间需要通过修改index实现。
加速度体现在target_speed的差距,如果他们差距很大,引入self.time之后,可以发现他变化是没一秒变化一次。也就是说在target_speed上跨度越小,加速度就越小。
以上操作就完成了十字路口环境动作空间的修改。