flatland.envs.line_generators module#

Line generators: Railway Undertaking (RU) / Eisenbahnverkehrsunternehmen (EVU).

class flatland.envs.line_generators.BaseLineGen(speed_ratio_map: Mapping[float, float] | None = None, seed: int = 1, line_length: int = 2)[source]#

Bases: object

generate(rail: GridTransitionMap, num_agents: int, hints: dict | None = None, num_resets: int = 0, np_random: RandomState | None = None) Line[source]#
class flatland.envs.line_generators.SparseLineGen(speed_ratio_map: Mapping[float, float] | None = None, seed: int = 1, line_length: int = 2)[source]#

Bases: BaseLineGen

static decide_orientation(rail, start, target, possible_orientations, np_random: RandomState) int[source]#
generate(rail: GridTransitionMap, num_agents: int, hints: dict | None = None, num_resets: int = 0, np_random: RandomState | None = None) Line[source]#

Assigns tasks to all the agents.

Parameters#

railGridTransitionMap

Rail infrastructure given by the rail_generator

num_agentsint

Number of agents to include in the line

hintsdict

Hints provided by the rail_generator These include positions of start/target positions

num_resets: int

How often the generator has been reset.

np_random : RandomState

Returns#

Line:

the line

flatland.envs.line_generators.line_from_file(filename, load_from_package: str | None = None) Callable[[GridTransitionMap, int, Any | None, int | None, RandomState | None], Line][source]#

Utility to load pickle file

Parameters#

filename : Pickle file generated by env.save() or editor load_from_package : str

package

Returns#

Tuple[List[Tuple[int,int]], List[Tuple[int,int]], List[Tuple[int,int]], List[float]]

initial positions, directions, targets speeds

flatland.envs.line_generators.sparse_line_generator(speed_ratio_map: Mapping[float, float] | None = None, seed: int = 1, line_length: int = 2) Callable[[GridTransitionMap, int, Any | None, int | None, RandomState | None], Line][source]#
flatland.envs.line_generators.speed_initialization_helper(nb_agents: int, speed_ratio_map: Mapping[float, float] | None = None, np_random: RandomState | None = None) List[float][source]#

Parameters#

nb_agentsint

The number of agents to generate a speed for

speed_ratio_mapMapping[float,float]

A map of speeds mapping to their ratio of appearance. The ratios must sum up to 1.

np_random : RandomState

Returns#

List[float]

A list of size nb_agents of speeds with the corresponding probabilistic ratios.