Skip to content
Snippets Groups Projects
Commit 0933d128 authored by spmohanty's avatar spmohanty
Browse files

Add RailEnvTransitions as a separate derived class

parent 05f6003f
No related branches found
No related tags found
No related merge requests found
...@@ -229,46 +229,50 @@ class GridTransitions(Transitions): ...@@ -229,46 +229,50 @@ class GridTransitions(Transitions):
return cell_transition return cell_transition
""" class RailEnvTransitions(GridTransitions):
Special case of `GridTransitions' over a 2D-grid, with a pre-defined set """
of transitions mimicking the types of real Swiss rail connections. Special case of `GridTransitions' over a 2D-grid, with a pre-defined set
of transitions mimicking the types of real Swiss rail connections.
----------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------
The possible transitions for RailEnv from a cell to its neighboring ones The possible transitions for RailEnv from a cell to its neighboring ones
are represented over 16 bits. are represented over 16 bits.
Whether a transition is allowed or not depends on which direction an agent Whether a transition is allowed or not depends on which direction an agent
inside the cell is facing (0=North, 1=East, 2=South, 3=West) and which inside the cell is facing (0=North, 1=East, 2=South, 3=West) and which
direction the agent wants to move to direction the agent wants to move to
(North, East, South, West, relative to the cell). (North, East, South, West, relative to the cell).
Each transition (orientation, direction) can be allowed (1) or forbidden (0). Each transition (orientation, direction) can be allowed (1) or forbidden (0).
The 16 bits are organized in 4 blocks of 4 bits each, the direction that The 16 bits are organized in 4 blocks of 4 bits each, the direction that
the agent is facing. the agent is facing.
E.g., the most-significant 4-bits represent the possible movements (NESW) E.g., the most-significant 4-bits represent the possible movements (NESW)
if the agent is facing North, etc... if the agent is facing North, etc...
agent's direction: North East South West agent's direction: North East South West
agent's allowed movements: [nesw] [nesw] [nesw] [nesw] agent's allowed movements: [nesw] [nesw] [nesw] [nesw]
example: 0010 0000 1000 0000 example: 0010 0000 1000 0000
In the example, the agent can move from North to South and viceversa. In the example, the agent can move from North to South and viceversa.
""" """
""" """
transitions[] is indexed by case type/id, and returns the 4x4-bit [NESW] transitions[] is indexed by case type/id, and returns the 4x4-bit [NESW]
transitions available as a function of the agent's orientation transitions available as a function of the agent's orientation
(north, east, south, west) (north, east, south, west)
""" """
RailEnvTransitionsList = [int('0000000000000000', 2), transition_list = [int('0000000000000000', 2),
int('1000000000100000', 2), int('1000000000100000', 2),
int('1001001000100000', 2), int('1001001000100000', 2),
int('1000010000100001', 2), int('1000010000100001', 2),
int('1001011000100001', 2), int('1001011000100001', 2),
int('1100110000110011', 2), int('1100110000110011', 2),
int('0101001000000010', 2), int('0101001000000010', 2),
int('0000000000100000', 2)] int('0000000000100000', 2)]
RailEnvTransitions = GridTransitions(transitions=RailEnvTransitionsList, def __init__(self):
allow_diagonal_transitions=False) super(RailEnvTransitions, self).__init__(
transitions=self.transition_list,
allow_diagonal_transitions=False
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment