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, RandomState], Tuple[RailGridTransitionMap, Dict | None]] [source]#
- class flatland.envs.rail_generators.FileRailFromGridGen(filename: Path)[source]#
Bases:
RailGen
- generate(width: int, height: int, num_agents: int, num_resets: int = 0, np_random: RandomState | None = None) Tuple[RailGridTransitionMap, Dict | None] [source]#
- static save(filename: Path, prod: Tuple[RailGridTransitionMap, Dict | None])[source]#
- static to_dict(prod: Tuple[RailGridTransitionMap, Dict | None])[source]#
- static wrap(rail_generator: Callable[[int, int, int, int, RandomState], Tuple[RailGridTransitionMap, Dict | None]], rail_pkl: Path) Callable[[int, int, int, int, RandomState], Tuple[RailGridTransitionMap, 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[RailGridTransitionMap, 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[RailGridTransitionMap, Dict | None] [source]#
- flatland.envs.rail_generators.RailGeneratorProduct#
A rail generator returns a RailGenerator Product, which is just a RailGridTransitionMap followed by an (optional) dict/
alias of
Tuple
[RailGridTransitionMap
,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: int | None = 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
- static fix_transitions(grid_transition_map: GridTransitionMap, rcPos: List[Tuple[int, int]], direction: Tuple[int, int] = -1, random_generator: RandomState | None = None)[source]#
Fixes broken transitions
- generate(width: int, height: int, num_agents: int, num_resets: int = 0, np_random: RandomState | None = None) Tuple[RailGridTransitionMap, 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
np_random: RandomState
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, RandomState], Tuple[RailGridTransitionMap, Dict | None]] [source]#
- flatland.envs.rail_generators.rail_from_file(filename: str | Path | None = None, load_from_package=None, env_dict=None) Callable[[int, int, int, int, RandomState], Tuple[RailGridTransitionMap, Dict | None]] [source]#
Utility to load rail generator from persisted env - uses env_dict if populated, otherwise tries to load from file / package. Beware: it only allows to re-generate the same rail again. A call to reset with a new seed will not generate a new rail. TODO flatland-association/flatland-rl#242 implement registry for all generators (rail, line, timetable, malfunction) similar to ray.tune.registry
Parameters#
- filenameUnion[str, Path]
pickle file with persisted env, defaults to None.
- load_from_packagestr
package, defaults to None.
- env_dict: dict
env_dict, defaults to None.
Returns#
- function
Generator function that always returns a RailGridTransitionMap 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, RandomState], Tuple[RailGridTransitionMap, Dict | None]] [source]#
- flatland.envs.rail_generators.sparse_rail_generator(*args: object, **kwargs: object) Callable[[int, int, int, int, RandomState], Tuple[RailGridTransitionMap, Dict | None]] [source]#