flatland.envs.graph_rail_env module#
- class flatland.envs.graph_rail_env.GraphRailEnv(rail_generator: RailGenerator = None, line_generator: LineGenerator = None, number_of_agents=2, observation_builder: ObservationBuilder = None, malfunction_generator_and_process_data=None, malfunction_generator: MalfunctionGenerator = None, random_seed=None, timetable_generator=None, acceleration_delta=1.0, braking_delta=-1.0, rewards: Rewards = None, effects_generator: EffectsGenerator[GraphRailEnv] = None, distance_map: GraphDistanceMap = None)[source]#
Bases:
AbstractRailEnv[GraphTransitionMap,GraphResourceMap,str]- static from_graph(g: DiGraph, resource_map: Dict[str, str], agent_waypoints: Dict[int, List[List[str]]], agent_speeds: Dict[int, float] | None = None, observation_builder: ObservationBuilder = None, malfunction_generator: MalfunctionGenerator = None, timetable_generator: Callable[[List[EnvAgent], GraphDistanceMap, dict, RandomState], Timetable] | None = None, seed: int | None = None, rewards: Rewards = None) GraphRailEnv[source]#
Factory method to create a GraphRailEnv directly from a string-node graph and string-based agent waypoints - counterpart to from_rail_env, but graph-native from the start: g’s nodes and agent_waypoints’ leaves are plain configuration strings, never ((row, col), direction) grid tuples or Waypoint objects.
Parameters#
- g: nx.DiGraph
the rail topology, with actions/straight edge attributes and an optional prohibited_actions node attribute - see GraphTransitionMap.grid_to_digraph for the shape expected by RailEnv.step().
- resource_map: Dict[str, str]
maps each node in g to the resource (occupancy unit) used for conflict detection.
- agent_waypoints: Dict[int, List[List[str]]]
per agent handle, the list of waypoint alternative-groups (initial, any intermediate stops, target) - mirrors Line.agent_waypoints, but with plain node-id strings instead of Waypoint objects.
- agent_speeds: Dict[int, float], optional
per agent handle, the agent’s speed - defaults to 1.0 for every agent.
- timetable_generator: optional
(agents, distance_map, agents_hints, np_random) -> Timetable - defaults to ttg.ttgen_flatland2 (earliest_departure=0/latest_arrival=1000 for every agent). Pass e.g. lambda *a, **k: TimetableUtils.from_agents(source_agents, max_episode_steps) to reuse an existing timetable instead (mirrors how from_rail_env reuses its source env’s).
- static from_rail_env(rail_env: RailEnv, observation_builder: ObservationBuilder, seed: int | None = None, rewards: Rewards | None = None) GraphRailEnv[source]#
Parameters#
- rewards: Rewards, optional
the Rewards instance for graph_env to accumulate its own reward state into - must be a separate instance from rail_env.rewards (never the same object: Rewards accumulates mutable per-episode state, e.g. arrivals/departures/states, which rail_env and graph_env must not share/corrupt). Defaults to GraphRailEnv’s own default (None) if not given - pass a fresh instance matching rail_env.rewards’s type/config for parity. If the resulting graph_env.rewards type ends up different from rail_env.rewards’s, a UserWarning is raised (e.g. if rewards is left None while rail_env.rewards is not GraphRailEnv’s own default).