flatland.envs.rail_grid_transition_map module#
- class flatland.envs.rail_grid_transition_map.RailGridTransitionMap(width, height, transitions: ~flatland.core.transitions.Transitions = <flatland.core.grid.rail_env_grid.RailEnvTransitions object>, random_seed=None, grid: ~numpy.ndarray | None = None)[source]#
Bases:
GridTransitionMap
- check_action_on_agent(action: RailEnvActions, position: Tuple[int, int], direction: Grid4TransitionsEnum)[source]#
Apply the action on the train regardless of locations of other trains. Checks for valid cells to move and valid rail transitions.
Parameters#
- actionRailEnvActions
Action to execute
- positionIntVector2D
current position of the train
- directionGrid4TransitionsEnum
current direction of the train
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
New position after applying the action
- new_direction
New direction 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: RailEnvActions
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_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.