Skip to main content

Automated scenario generation for CommonRoad based on SUMO traffic simulations.

Project description

CommonRoad Scenario Factory

PyPI pyversions PyPI version fury.io PyPI download month PyPI license

The CommonRoad Scenario Factory is a toolbox that combines many different tools from the whole CommonRoad ecosystem to efficiently process CommonRoad scenarios. Its current main use case is the generation of new CommonRoad scenarios with the traffic simulators OpenTrafficSim (OTS) and SUMO.

Quick Start

Installation

The CommonRoad Scenario Factory is available on PyPI and can be easily installed with pip:

$ pip install commonroad-scenario-factory

Additional Requirements

Most required dependencies are already included, but some have to be installed manually on your system:

  • Java Runtime Environment: Required for running simulations with OpenTrafficSim (OTS).
  • osmium: Required for extracting segments from pre-downloaded OSM maps.

SUMO and OTS are distributed as python packages and included as dependencies. Therefore, they do not need to be installed separately.

Example Usage

This example will setup a basic scenario generation pipeline with SUMO and output new scenarios to /tmp/scenario-factory:

from pathlib import Path

from scenario_factory.globetrotter import Coordinates, OsmApiMapProvider, RegionMetadata
from scenario_factory.pipelines import (
    create_globetrotter_pipeline,
    create_scenario_generation_pipeline,
)
from scenario_factory.pipeline_steps import (
    pipeline_add_metadata_to_scenario,
    pipeline_simulate_scenario_with_sumo,
    pipeline_assign_tags_to_scenario,
    pipeline_write_scenario_to_file,
)
from scenario_factory.scenario_config import ScenarioFactoryConfig
from scenario_factory.simulation import SimulationConfig, SimulationMode

radius = 0.1
seed = 5678
simulation_steps = 500
cr_scenario_time_steps = 50
coords_str = "48.2570465,11.6580003"
output_path = Path("/tmp/scenario-factory")
output_path.mkdir(exist_ok=True)


map_provider = OsmApiMapProvider()
simulation_config = SimulationConfig(
    mode=SimulationMode.RANDOM_TRAFFIC_GENERATION,
    simulation_steps=simulation_steps,
    seed=seed,
)
scenario_config = ScenarioFactoryConfig(
    seed=seed, cr_scenario_time_steps=cr_scenario_time_steps, source="example"
)

base_pipeline = (
    create_globetrotter_pipeline(radius, map_provider)
    .map(pipeline_add_metadata_to_scenario)
    .map(pipeline_simulate_scenario_with_sumo(simulation_config))
)

scenario_generation_pipeline = create_scenario_generation_pipeline(
    scenario_config.criterions, scenario_config.filters
)

pipeline = (
    base_pipeline.chain(scenario_generation_pipeline)
    .map(pipeline_assign_tags_to_scenario)
    .map(pipeline_write_scenario_to_file(output_path))
)

coordinates = Coordinates.from_str(coords_str)
region = RegionMetadata.from_coordinates(coordinates)

print(f"Starting scenario generation for coordinates {coords_str}.")
result = pipeline.execute([region], num_threads=2, num_processes=2)
result.print_cum_time_per_step()
print(f"Generated {len(result.values)} scenario(s) at {output_path}.")

Documentation

The full documentation can be found at cps.pages.gitlab.lrz.de/commonroad/scenario-factory.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

commonroad_scenario_factory-2.0.0.tar.gz (12.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

commonroad_scenario_factory-2.0.0-py3-none-any.whl (12.6 MB view details)

Uploaded Python 3

File details

Details for the file commonroad_scenario_factory-2.0.0.tar.gz.

File metadata

  • Download URL: commonroad_scenario_factory-2.0.0.tar.gz
  • Upload date:
  • Size: 12.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.10.18 Linux/5.15.0-87-generic

File hashes

Hashes for commonroad_scenario_factory-2.0.0.tar.gz
Algorithm Hash digest
SHA256 e4b91f796de4799b6f972aa480fb78ec1c640890c051b32be94293b70de82261
MD5 959f7098948f0136a087ef1a8ab1ae76
BLAKE2b-256 bb516f755f9ca27e821de73b109da962066df86919d0975b7324bfd582c0c36e

See more details on using hashes here.

File details

Details for the file commonroad_scenario_factory-2.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for commonroad_scenario_factory-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f2e173b874ffc1b6bfc9dce099b19ba49d4a33181de3b9bcf850f727d79338ff
MD5 b46e869053d3a386943d15441339bb19
BLAKE2b-256 f3c081720fe453210b5566f90e9017083c839c94398b1495241edf41a12a452a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page