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

apply_action_independent(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

directionint

current direction of the train

Returns#

new_position

New position after applying the action

new_direction

New direction after applying the action

check_action_on_agent(action: RailEnvActions, position: Tuple[int, int], direction: Grid4TransitionsEnum) Tuple[bool, int, Tuple[int, int], bool][source]#

Gets new position and direction for the action.

Parameters#

action : RailEnvActions position: Tuple[int,int] direction : Grid4TransitionsEnum

Returns#

new_cell_validbool

whether the new position and new direction are valid in the grid

new_direction : int new_position : Tuple[int,int] transition_valid : bool

whether the transition from old to new position and direction is defined in the grid

check_bounds(position)[source]#
check_valid_action(action: RailEnvActions, position: Tuple[int, int], direction: Grid4TransitionsEnum)[source]#

Checks whether action at position and direction leads to a valid new position in the grid.

Fails if the grid is not valid or if MOVE_FORWARD in a symmetric switch or MOVE_LEFT in straight element.

Parameters#

action : RailEnvActions position : Tuple[int, int] direction: Grid4TransitionsEnum

Returns#

bool

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.

preprocess_left_right_action(action: RailEnvActions, position: Tuple[int, int], direction: Grid4TransitionsEnum)[source]#

LEFT/RIGHT is converted to FORWARD if left/right is not available.