flatland.env_generation.env_generator module#
- flatland.env_generation.env_generator.env_generator(n_agents=7, x_dim=30, y_dim=30, n_cities=2, max_rail_pairs_in_city=4, grid_mode=False, max_rails_between_cities=2, p_level_free: float = 0, malfunction_duration_min=20, malfunction_duration_max=50, malfunction_interval=540, speed_ratios=None, line_length=2, seed=None, post_seed=None, obs_builder_object=None, acceleration_delta=1.0, braking_delta=-1.0, rewards: Rewards | None = None, effects_generator: EffectsGenerator[RailEnv] | None = None) Tuple[RailEnv, Dict, Dict][source]#
Create an env with a given spec using sparse_rail_generator. Defaults are taken from Flatland 3 Round 2 Test_0, see `Environment Configurations <https://flatland.aicrowd.com/challenges/flatland3/envconfig.html`_. Parameters name come from metadata.csv in debug-environments.zip
Parameters#
- n_agents: int
number of agents
- x_dim: int
number of columns
- y_dim: int
number of rows
- n_cities: int
Max number of cities to build. The generator tries to achieve this numbers given all the parameters. Goes into sparse_rail_generator.
- max_rail_pairs_in_city: int
Number of parallel tracks in the city. This represents the number of tracks in the train stations. Goes into sparse_rail_generator.
- grid_mode: bool
How to distribute the cities in the path, either equally in a grid or random. Goes into sparse_rail_generator.
- max_rails_between_cities: int
Max number of rails connecting to a city. This is only the number of connection points at city boarder.
- p_level_freefloat
Percentage of diamond-crossings which are level-free.
- malfunction_duration_min: int
Minimal duration of malfunction. Goes into ParamMalfunctionGen.
- malfunction_duration_max: int
Max duration of malfunction. Goes into ParamMalfunctionGen.
- malfunction_interval: int
Inverse of rate of malfunction occurrence. Goes into ParamMalfunctionGen.
- speed_ratios: Dict[float, float]
Speed ratios of all agents. They are probabilities of all different speeds and have to add up to 1. Goes into sparse_line_generator. Defaults to {1.0: 0.25, 0.5: 0.25, 0.33: 0.25, 0.25: 0.25}.
- line_lengthint
The length of the lines. Goes into sparse_line_generator. Defaults to 2.
- seed: int
Initiate random seed generators. Goes into reset.
- post_seed: int
Initiate random seed after the env is generated, goes into second reset with regenerate_rail=False, regenerate_schedule=False. Allows for backwards compatibility with flatland-3 client.py behaviour: at that stage, random state was not serialized in the pickles, so in order for malfunction generation to be deterministic, the envs were reset with a second seed from env var RANDOM_SEED - the same for all envs! Beware also from the difference in the behaviour of reset between env from `env_generator and a de-pickled one: in the former case, rail/line/schedule generation is performed with the current random state; in the latter case, rail/line/schedule are loaded from file (not changing!).
- obs_builder_object: Optional[ObservationBuilder]
Defaults to TreeObsForRailEnv(max_depth=3, predictor=ShortestPathPredictorForRailEnv(max_depth=50))
- acceleration_deltafloat
Defaults to 1.0
- braking_deltafloat
Defaults to -1.0
- rewardsRewards
Rewards function. Defaults to DefaultRewards.
- effects_generatorEffectsGenerator[RailEnv]
Effects generator. Defaults to None.
Returns#
- RailEnv
The generated environment reset with the given seed.
- observationsDict
Initial observations from reset()
- infoDict
Initial infos from reset()
- flatland.env_generation.env_generator.env_generator_legacy(n_agents=7, x_dim=30, y_dim=30, n_cities=2, max_rail_pairs_in_city=4, grid_mode=False, max_rails_between_cities=2, p_level_free: float = 0, malfunction_duration_min=20, malfunction_duration_max=50, malfunction_interval=540, speed_ratios=None, line_length=2, seed=None, post_seed=None, obs_builder_object=None, acceleration_delta=1.0, braking_delta=-1.0, rewards: Rewards | None = None, effects_generator: EffectsGenerator[RailEnv] | None = None) Tuple[RailEnv, Dict, Dict][source]#
Old deprecated behavior of stateful rail_generator: ignore seed passed from env int rail_generator, draw from random generator initialised every time by its own seed.