flatland.envs.rail_env_utils module#
- flatland.envs.rail_env_utils.env_generator(n_agents: int = 7, x_dim: int = 30, y_dim: int = 30, n_cities: int = 2, max_rail_pairs_in_city: int = 4, grid_mode: bool = False, max_rails_between_cities: int = 2, malfunction_duration_min: int = 20, malfunction_duration_max: int = 50, malfunction_interval: int = 540, speed_ratios: Dict[float, float] | None = None, seed: int = 42, obs_builder_object: ObservationBuilder | None = None) RailEnv [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.
- 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}.
- seed: int
Initiate random seed generators. Goes into reset.
- obs_builder_object: Optional[ObservationBuilder]
Defaults to TreeObsForRailEnv(max_depth=3, predictor=ShortestPathPredictorForRailEnv(max_depth=50))
Returns#
- RailEnv
The generated environment reset with the given seed.
- flatland.envs.rail_env_utils.load_flatland_environment_from_file(file_name: str, load_from_package: str | None = None, obs_builder_object: ObservationBuilder | None = None, record_steps=False) RailEnv [source]#
Parameters#
- file_namestr
The pickle file.
- load_from_packagestr
The python module to import from. Example: ‘env_data.tests’ This requires that there are __init__.py files in the folder structure we load the file from.
- obs_builder_object: ObservationBuilder
The obs builder for the RailEnv that is created.
Returns#
- RailEnv
The environment loaded from the pickle file.