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.1.0.tar.gz (91.3 kB 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.1.0-py3-none-any.whl (125.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: commonroad_scenario_factory-2.1.0.tar.gz
  • Upload date:
  • Size: 91.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.10.18 Linux/5.15.0-87-generic

File hashes

Hashes for commonroad_scenario_factory-2.1.0.tar.gz
Algorithm Hash digest
SHA256 9ac044275eba8eaffb4e7c9c23660e99b60fbb468d4eac808ffd538d54e45928
MD5 059f167767dec98f9ac862ef46a8ae46
BLAKE2b-256 47602ed7dabef33026311895b33c98cdd05f9d2acc96b1126db52b834b0edf48

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for commonroad_scenario_factory-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 334c073a9148a02a40806aa1e47293320559ccc27d26c06fb1424f2fca8f190a
MD5 294e8f332c77dea1a7da705b63a67e28
BLAKE2b-256 4e35e7f0729a81ab0318fba9e446046e20f957c8a887ef6c1373c1f5947ae151

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