flatland.envs.rail_grid_transition_map module#
- class flatland.envs.rail_grid_transition_map.RailGridTransitionMap(width, height, transitions: ~flatland.core.transitions.Transitions = <flatland.envs.grid.rail_env_grid.RailEnvTransitions object>, grid: ~numpy.ndarray | None = None)[source]#
Bases:
GridTransitionMap
[RailEnvActions
]- check_action_on_agent(action: RailEnvActions, configuration: Tuple[Tuple[int, int], int]) Tuple[bool, Tuple[Tuple[int, int], int], bool, RailEnvActions] [source]#
Returns#
- new_cell_valid: bool
is the new position and direction valid (i.e. is it within bounds and does it have > 0 outgoing transitions)
- new_position: [ConfigurationType]
New position after applying the action
- transition_valid: bool
Whether the transition from old and direction is defined in the grid. In other words, can the action be applied directly? False if - MOVE_FORWARD/DO_NOTHING when entering symmetric switch - MOVE_LEFT/MOVE_RIGHT corrected to MOVE_FORWARD in switches and dead-ends However, transition_valid for dead-ends and turns either with the correct MOVE_RIGHT/MOVE_LEFT or MOVE_FORWARD/DO_NOTHING.
- preprocessed_action: [ActionType]
Corrected action if not transition_valid.
The preprocessed action has the following semantics: - MOVE_LEFT/MOVE_RIGHT: turn left/right without acceleration - MOVE_FORWARD: move forward with acceleration (swap direction in dead-end, also works in left/right turns or symmetric-switches non-facing) - DO_NOTHING: if already moving, keep moving forward without acceleration (swap direction in dead-end, also works in left/right turns or symmetric-switches non-facing); if stopped, stay stopped.
- get_valid_directions_on_grid(row: int, col: int) List[int] [source]#
Returns directions in which the agent can move
- get_valid_move_actions_(agent_direction: Grid4TransitionsEnum, agent_position: Tuple[int, int]) Set[RailEnvNextAction] [source]#
Get the valid move actions (forward, left, right) for an agent.
- TODO The implementation could probably be more efficient and more elegant,
but given the few calls this has no priority now.
Parameters#
agent_direction : Grid4TransitionsEnum agent_position: Tuple[int,int]
Returns#
- Set of RailEnvNextAction (tuples of (action,position,direction))
Possible move actions (forward,left,right) and the next position/direction they lead to. It is not checked that the next cell is free.