我是 Open Ai Gym 的新手,目前在出租车环境中运行强化学习 (RL),我的研究要求我能够调用状态元组(或在 出租车中称为“状态空间”。 py 文件)用于某些数据挖掘/状态- Action 对操作。
有函数调用吗?
例如:State(123) = (taxi_row, taxi_col, passenger_location, destination)
在 RL 中,状态和 Action 以矩阵形式表示,column = state, row = action。
在源代码 (taxi.py) 中,其所谓的“状态空间由 (taxi_row, taxi_col, passenger_location , 目的地)"
请您参考如下方法:
你可以这样做:
>>> import gym
>>> env = gym.make('Taxi-v2')
>>> from gym.envs.toy_text.taxi import *
>>>
>>>
>>> x = TaxiEnv()
>>> random_state = 123
>>> taxi_row, taxi_col, passenger_index, destination_index = x.decode(random_state)
>>> taxi_row
1
>>> taxi_col
1
>>> passenger_index
0
>>> destination_index
3
在您的问题中,您需要 passenger_location 和 destination。但是我使用的代码返回了 passenger_index 和 destination_index。因此,如果您了解环境 map ,就可以轻松获取位置。
下面是环境中使用的简单 map :
MAP = [
"+---------+",
"|R: | : :G|",
"| : | : : |",
"| : : : : |",
"| | : | : |",
"|Y| : |B: |",
"+---------+",
]
在这张 map 中,我们有四个不同的位置(R、G、Y、B)。现在,你可以很容易地知道乘客的位置和目的地,就像这样:
乘客位置:
- 0:R(编辑)
- 1:G(绿色)
- 2:Y(黄色)
- 3:B(蓝)
- 4:在出租车里
目的地:
- 0:R(编辑)
- 1:G(绿色)
- 2:Y(黄色)
- 3:B(蓝)
希望这能回答您的问题!!
