Module Common

File Reader

CommonRoadFileReader class

class commonroad.common.file_reader.CommonRoadFileReader(filename, file_format=None)[source]

Reads CommonRoad files in XML or protobuf format. The corresponding stored scenario and planning problem set are created by the reader.

open(lanelet_assignment=False)[source]

Opens and loads CommonRoad scenario and planning problems from file.

Parameters:

lanelet_assignment (bool) – Activates calculation of lanelets occupied by obstacles

Return type:

Tuple[Scenario, PlanningProblemSet]

Returns:

Scenario and planning problems

open_lanelet_network()[source]

Opens and loads CommonRoad lanelet network from file.

Return type:

LaneletNetwork

Returns:

File Writer

CommonRoadFileWriter class

class commonroad.common.file_writer.CommonRoadFileWriter(scenario, planning_problem_set, author=None, affiliation=None, source=None, tags=None, location=None, decimal_precision=4, file_format=FileFormat.XML)[source]

Writes CommonRoad files in XML or protobuf format. The corresponding scenario and planning problem set are stored by the writer.

static check_validity_of_commonroad_file(commonroad_str, file_format=FileFormat.XML)[source]

Checks validity of CommonRoad scenario and planning problem stored in XML or protobuf format.

Parameters:
  • commonroad_str (Union[str, bytes]) – Commonroad instance stored as string

  • file_format (FileFormat) – Format of file

Return type:

bool

Returns:

Valid or not

write_scenario_to_file(filename=None, overwrite_existing_file=OverwriteExistingFile.ASK_USER_INPUT)[source]

Writes CommonRoad scenario to file.

Parameters:
  • filename (Optional[str]) – Name of file

  • overwrite_existing_file (OverwriteExistingFile) – Overwriting mode

Returns:

Scenario

write_to_file(filename=None, overwrite_existing_file=OverwriteExistingFile.ASK_USER_INPUT, check_validity=False)[source]

Writes CommonRoad scenario and planning problems to file.

Parameters:
  • filename (Optional[str]) – Name of file

  • overwrite_existing_file (OverwriteExistingFile) – Overwriting mode

  • check_validity (bool) – Validity check or not

Returns:

Scenario and planning problems

OverwriteExistingFile class

class commonroad.common.file_writer.OverwriteExistingFile(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Specifies whether an existing file will be overwritten or skipped

ASK_USER_INPUT = 0
ALWAYS = 1
SKIP = 2

Solution Reader and Writer

The following classes help with creating a CommonRoad solution xml file from a trajectory that solves CommonRoad benchmarks. The files can be submitted on our website. Create a Solution and write using the CommonRoadSolutionWriter.

VehicleType class

class commonroad.common.solution.VehicleType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
FORD_ESCORT = 1
BMW_320i = 2
VW_VANAGON = 3
TRUCK = 4

VehicleModel class

class commonroad.common.solution.VehicleModel(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
PM = 0
ST = 1
KS = 2
MB = 3
KST = 4

Detailed information about the listed vehicle models in Vehicle Model Documentation.

CostFunction class

class commonroad.common.solution.CostFunction(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
JB1 = 0
SA1 = 1
WX1 = 2
SM1 = 3
SM2 = 4
SM3 = 5
MW1 = 6
TR1 = 7

Detailed information about the listed cost functions in Cost Function Documentation.

PlanningProblemSolution class

class commonroad.common.solution.PlanningProblemSolution(planning_problem_id, vehicle_model, vehicle_type, cost_function, trajectory)[source]
property vehicle_model: VehicleModel

VehicleModel of the PlanningProblemSolution

property cost_function: CostFunction

CostFunction of the PlanningProblemSolution

property trajectory: Trajectory

Trajectory of the PlanningProblemSolution

property trajectory_type: TrajectoryType

TrajectoryType of the PlanningProblemSolution. Dynamically assigned when there is a change of trajectory.

property vehicle_id: str

Returns the vehicle id as string.

Example:

VehicleModel = PM VehicleType = FORD_ESCORT Vehicle ID = PM1

property cost_id: str

Returns cost function id as str.

Example:

CostFunction = JB1 Cost ID = JB1

Returns:

Cost function ID

Solution class

class commonroad.common.solution.Solution(scenario_id, planning_problem_solutions, date=datetime.datetime(2024, 5, 20, 1, 8, 52, 103964), computation_time=None, processor_name=None)[source]

Stores a solution to a CommonRoad benchmark and additional meta data.

property planning_problem_solutions: List[PlanningProblemSolution]
property benchmark_id: str

Returns the benchmark id of the solution as string.

Example:

Scenario ID = TEST VehicleModel = PM VehicleType = FORD_ESCORT CostFunction = JB1 Version = 2020a

Benchmark ID = PM1:JB1:TEST:2020a

Collaborative Solution Example:

Scenario ID = TEST 1st VehicleModel = PM 1st VehicleType = FORD_ESCORT 1st CostFunction = JB1 2nd VehicleModel = PM 2nd VehicleType = VW_VANAGON 2nd CostFunction = SA1 Version = 2020a

Benchmark ID = [PM1,PM3]:[JB1,SA1]:TEST:2020a

property vehicle_ids: List[str]

Returns the list of vehicle ids of all PlanningProblemSolutions of the Solution

Example:

1st PlanningProblemSolution Vehicle ID = PM1 2nd PlanningProblemSolution Vehicle ID = PM3

Vehicle IDS = [PM1, PM3]

Returns:

List of vehicle IDs

property cost_ids: List[str]

Returns the list of cost ids of all PlanningProblemSolutions of the Solution

Example:

1st PlanningProblemSolution Cost ID = JB1 2nd PlanningProblemSolution Cost ID = SA1

Cost IDS = [JB1, SA1]

property planning_problem_ids: List[int]

Returns the list of planning problem ids of all PlanningProblemSolutions of the Solution

Example:

1st PlanningProblemSolution planning_problem_id = 0 2nd PlanningProblemSolution planning_problem_id = 1

planning_problem_ids = [0, 1]

property trajectory_types: List[TrajectoryType]

Returns the list of trajectory types of all PlanningProblemSolutions of the Solution

Example:

1st PlanningProblemSolution trajectory_type = TrajectoryType.PM 2nd PlanningProblemSolution trajectory_type = TrajectoryType.KS

trajectory_types = [TrajectoryType.PM, TrajectoryType.KS]

Returns:

List of trajectory types

property computation_time: None | float

Return the computation time [s] for the trajectory.

create_dynamic_obstacle()[source]

Creates dynamic obstacle(s) from solution(s) for every planning problem.

Return type:

Dict[int, DynamicObstacle]

CommonRoadSolutionReader class

class commonroad.common.solution.CommonRoadSolutionReader[source]

Reads solution xml files created with the CommonRoadSolutionWriter

classmethod open(filepath)[source]

Opens and parses the Solution XML file located on the given path.

Parameters:

filepath (str) – Path to the file.

Return type:

Solution

Returns:

Solution

classmethod fromstring(file)[source]

Parses the given Solution XML string.

Parameters:

file (str) – xml file as string

Return type:

Solution

Returns:

Solution

CommonRoadSolutionWriter class

class commonroad.common.solution.CommonRoadSolutionWriter(solution)[source]
dump(pretty=True)[source]

Dumps the Solution XML as string.

Parameters:

pretty (bool) – If set to true, prettifies the xml string.

Return type:

str

Returns:

string - Solution XML as string.

write_to_file(output_path='./', filename=None, overwrite=False, pretty=True)[source]

Writes the Solution XML to a file.

Parameters:
  • output_path (str) – Output dir where the Solution XML file should be written to. Writes to the same folder where it is called from if not specified.

  • filename (str) – Name of the Solution XML file. If not specified, sets the name as ‘solution_BENCHMARKID.xml’ where the BENCHMARKID is the benchmark_id of the solution.

  • overwrite (bool) – If set to True, overwrites the file if it already exists.

  • pretty (bool) – If set to True, prettifies the Solution XML string before writing to file.

Util

Interval class

class commonroad.common.util.Interval(start, end)[source]
intersection(other)[source]

Returns the intersections with another interval. :type other: Interval :param other: Interval :rtype: Optional[Interval] :return: Interval or None if intersection is empty

AngleInterval class

class commonroad.common.util.AngleInterval(start, end)[source]

Allows only angles from interval [-2pi,2pi]