flatland.envs.rail_generators module

Rail generators (infrastructure manager, “Infrastrukturbetreiber”).

flatland.envs.rail_generators.complex_rail_generator(nr_start_goal=1, nr_extra=100, min_dist=20, max_dist=99999, seed=1) → Callable[[int, int, int, int], Tuple[flatland.core.transition_map.GridTransitionMap, Union[Dict, NoneType]]][source]
Parameters:
width : int

The width (number of cells) of the grid to generate.

height : int

The height (number of cells) of the grid to generate.

Returns:
numpy.ndarray of type numpy.uint16

The matrix with the correct 16-bit bitmaps for each cell.

flatland.envs.rail_generators.empty_rail_generator() → Callable[[int, int, int, int], Tuple[flatland.core.transition_map.GridTransitionMap, Union[Dict, NoneType]]][source]

Returns a generator which returns an empty rail mail with no agents. Primarily used by the editor

flatland.envs.rail_generators.rail_from_file(filename, load_from_package=None) → Callable[[int, int, int, int], Tuple[flatland.core.transition_map.GridTransitionMap, Union[Dict, NoneType]]][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) → Callable[[int, int, int, int], Tuple[flatland.core.transition_map.GridTransitionMap, Union[Dict, NoneType]]][source]

Utility to convert a rail given by a GridTransitionMap map with the correct 16-bit transitions specifications.

Parameters:
rail_map : GridTransitionMap object

GridTransitionMap object to return when the generator is called.

Returns:
function

Generator function that always returns the given rail_map object.

flatland.envs.rail_generators.rail_from_manual_specifications_generator(rail_spec)[source]

Utility to convert a rail given by manual specification as a map of tuples (cell_type, rotation), to a transition map with the correct 16-bit transitions specifications.

Parameters:
rail_spec : list of list of tuples

List (rows) of lists (columns) of tuples, each specifying a rail_spec_of_cell for the RailEnv environment as (cell_type, rotation), with rotation being clock-wise and in [0, 90, 180, 270].

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.random_rail_generator(cell_type_relative_proportion=[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0], seed=1) → Callable[[int, int, int, int], Tuple[flatland.core.transition_map.GridTransitionMap, Union[Dict, NoneType]]][source]

Dummy random level generator: - fill in cells at random in [width-2, height-2] - keep filling cells in among the unfilled ones, such that all transitions are legit; if no cell can be filled in without violating some transitions, pick one among those that can satisfy most transitions (1,2,3 or 4), and delete (+mark to be re-filled) the cells that were incompatible. - keep trying for a total number of insertions (e.g., (W-2)*(H-2)*MAX_REPETITIONS ); if no solution is found, empty the board and try again from scratch. - finally pad the border of the map with dead-ends to avoid border issues.

Dead-ends are not allowed inside the grid, only at the border; however, if no cell type can be inserted in a given cell (because of the neighboring transitions), deadends are allowed if they solve the problem. This was found to turn most un-genereatable levels into valid ones.

Parameters:
width : int

The width (number of cells) of the grid to generate.

height : int

The height (number of cells) of the grid to generate.

Returns:
numpy.ndarray of type numpy.uint16

The matrix with the correct 16-bit bitmaps for each cell.

flatland.envs.rail_generators.sparse_rail_generator(max_num_cities:int=5, grid_mode:bool=False, max_rails_between_cities:int=4, max_rails_in_city:int=4, seed=0) → Callable[[int, int, int, int], Tuple[flatland.core.transition_map.GridTransitionMap, Union[Dict, NoneType]]][source]

Generates railway networks with cities and inner city rails

Parameters:
max_num_cities : int

Max number of cities to build. The generator tries to achieve this numbers given all the parameters

grid_mode: Bool

How to distribute the cities in the path, either equally in a grid or random

max_rails_between_cities: int

Max number of rails connecting to a city. This is only the number of connection points at city boarder. Number of tracks drawn inbetween cities can still vary

max_rails_in_city: int

Number of parallel tracks in the city. This represents the number of tracks in the trainstations

seed: int

Initiate the seed

Returns:
Returns the rail generator object to the rail env constructor