flatland.envs.timetable_generators module#

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

class flatland.envs.timetable_generators.FileTimetableGenerator(filename: Path, load_from_package: bool = None)[source]#

Bases: object

generate(*args, **kwargs) → Timetable[source]#
static save(filename: Path, tt: Timetable)[source]#
static wrap(timetable_generator: timetable_generator, tt_pkl: Path) → timetable_generator[source]#
flatland.envs.timetable_generators.timetable_from_file(filename: str | Path = None, load_from_package=None, env_dict=None) → timetable_generator[source]#

Utility to load timetable generator from persisted env - uses env_dict if populated, otherwise tries to load from file / package.

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#

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

initial positions, directions, targets speeds

flatland.envs.timetable_generators.timetable_generator(agents: List[EnvAgent], distance_map: DistanceMap, agents_hints: dict, np_random: RandomState = None) → Timetable[source]#

Calculates earliest departure and latest arrival times for the agents This is the new addition in Flatland 3 Also calculates the max episodes steps based on the density of the timetable

inputs:

agents - List of all the agents rail_env.agents distance_map - Distance map of positions to targets of each agent in each direction agent_hints - Uses the number of cities np_random - RNG state for seeding

returns:

Timetable with the latest_arrivals, earliest_departures and max_episdode_steps

N.B. travel times are a heuristic: each segment (between consecutive waypoints) counts the sum of its edge lengths plus 1, as len(shortest_path) (see DistanceMap.shortest_path_length()), rounded up to whole steps. The total, divided by the agent’s max speed, determines max_episode_steps, the departure window and latest arrival; intermediate waypoint times add the segment lengths without dividing by the speed. Hence the step onto the map is counted per segment and scaled by the speed, giving slow agents and agents with intermediate waypoints some extra slack in total, whereas slow agents’ intermediate waypoint times are relatively tight. See EnvAgent.get_travel_time_on_shortest_path() for the travel time used for rewards.

flatland.envs.timetable_generators.ttgen_flatland2(agents: List[EnvAgent], distance_map: DistanceMap, agents_hints: dict, np_random: RandomState = None) → Timetable[source]#