flatland.envs.rail_generators module#
Rail generators: infrastructure manager (IM) / Infrastrukturbetreiber (ISB).
- class flatland.envs.rail_generators.EmptyRailGen(*args, **kwargs)[source]#
Bases:
RailGen
Returns a generator which returns an empty rail mail with no agents. Primarily used by the editor
- generate(width: int, height: int, num_agents: int, num_resets: int = 0, np_random: RandomState | None = None) Callable[[int, int, int, int], Tuple[GridTransitionMap, Dict | None]] [source]#
- class flatland.envs.rail_generators.RailFromGridGen(rail_map, optionals=None)[source]#
Bases:
RailGen
- generate(width: int, height: int, num_agents: int, num_resets: int = 0, np_random: RandomState | None = None) Tuple[GridTransitionMap, Dict | None] [source]#
- class flatland.envs.rail_generators.RailGen(*args, **kwargs)[source]#
Bases:
object
Base class for RailGen(erator) replacement
WIP to replace bare generators with classes / objects without unnamed local variables which prevent pickling.
- generate(width: int, height: int, num_agents: int, num_resets: int = 0, np_random: RandomState | None = None) Tuple[GridTransitionMap, Dict | None] [source]#
- flatland.envs.rail_generators.RailGeneratorProduct#
A rail generator returns a RailGenerator Product, which is just a GridTransitionMap followed by an (optional) dict/
alias of
Tuple
[GridTransitionMap
,Dict
|None
]
- class flatland.envs.rail_generators.SparseRailGen(max_num_cities: int = 2, grid_mode: bool = False, max_rails_between_cities: int = 2, max_rail_pairs_in_city: int = 2, seed=None, p_level_free: float = 0)[source]#
Bases:
RailGen
- static argsort(seq)[source]#
Same as Numpy sort but for lists Parameters ———- seq: List
list that we would like to sort from smallest to largest
Returns#
Returns the sorted list
- generate(width: int, height: int, num_agents: int, num_resets: int = 0, np_random: RandomState | None = None) Tuple[GridTransitionMap, Dict | None] [source]#
Parameters#
- width: int
Width of the environment
- height: int
Height of the environment
- num_agents:
Number of agents to be placed within the environment
- num_resets: int
Count for how often the environment has been reset
Returns#
Returns the grid_map –> The railway infrastructure Hints: agents_hints’: {
‘num_agents’: how many agents have starting and end spots ‘agent_start_targets_cities’: touples of agent start and target cities ‘train_stations’: locations of train stations for start and targets ‘city_orientations’ : orientation of cities
- get_closest_neighbour_for_direction(closest_neighbours, out_direction)[source]#
Given a list of clostest neighbours in each direction this returns the city index of the neighbor in a given direction. Direction is a 90 degree cone facing the desired directiont. Example:
North: The closes neighbour in the North direction is within the cone spanned by a line going North-West and North-East
Parameters#
- closest_neighbours: List
List of length 4 containing the index of closes neighbour in the corresponfing direction: [North-Neighbour, East-Neighbour, South-Neighbour, West-Neighbour]
- out_direction: int
Direction we want to get city index from North: 0, East: 1, South: 2, West: 3
Returns#
Returns the index of the closest neighbour in the desired direction. If none was present the neighbor clockwise or counter clockwise is returned
- flatland.envs.rail_generators.empty_rail_generator() Callable[[int, int, int, int], Tuple[GridTransitionMap, Dict | None]] [source]#
- flatland.envs.rail_generators.rail_from_file(filename, load_from_package=None) Callable[[int, int, int, int], Tuple[GridTransitionMap, Dict | None]] [source]#
Utility to load pickle file
Parameters#
filename : Pickle file generated by env.save() or editor
Returns#
- function
Generator function that always returns a GridTransitionMap object with the matrix of correct 16-bit bitmaps for each rail_spec_of_cell.
- flatland.envs.rail_generators.rail_from_grid_transition_map(rail_map, optionals=None) Callable[[int, int, int, int], Tuple[GridTransitionMap, Dict | None]] [source]#