plafosim.infrastructure module

class plafosim.infrastructure.Dummy(owner: object, dummy: int = -1, **kw_args)[source]

Bases: FormationAlgorithm

Dummy Platoon Formation Algorithm.

__init__(owner: object, dummy: int = -1, **kw_args)[source]

Initialize an instance of this formation algorithm to be used in a vehicle or an infrastructure.

Parameters:
  • owner (object) – The owning object that is execution this algorithm. This can be either a PlatooningVehicle or an Infrastructure.

  • dummy (int, optional) – The value for the dummy parameter

classmethod add_parser_argument_group(parser: ArgumentParser) _ArgumentGroup[source]

Create and return specific argument group for this algorithm to use in global argument parser.

Parameters:

parser (argparse.ArgumentParser) – The global argument parser

Returns:

The specific argument group for this algorithm

Return type:

argparse._ArgumentGroup

do_formation()[source]

Run platoon formation algorithm to search for a platooning opportunity and perform the corresponding join maneuver.

finish()[source]

Clean up the instance of the formation algorithm.

This includes mostly statistic recording.

_abc_impl = <_abc_data object>
property name

Print the name of the formation algorithm.

class plafosim.infrastructure.FormationAlgorithm(owner: object)[source]

Bases: ABC

Abstract base class for any type of platoon formation algorithm (i.e., assignment calculation).

Implementing sub-classes need to override the do_formation() method.

__init__(owner: object)[source]

Initialize an instance of a formation algorithm.

Parameters:

owner (object) – The owning object that is execution this algorithm. This can be either a PlatooningVehicle or an Infrastructure.

abstract add_parser_argument_group(parser: ArgumentParser) _ArgumentGroup[source]

Abstract method for performing any type of platoon formation (i.e., assignment calculation).

This methods needs to be overridden in implementing sub-classes.

Returns:

The specific argument group for this algorithm.

Return type:

argparse._ArgumentGroup

abstract do_formation()[source]

Abstract method for performing any type of platoon formation (i.e., assignment calculation).

This methods needs to be overridden in implementing sub-classes.

finish()[source]

Reserved for future use.

_abc_impl = <_abc_data object>
property name

Print the name of the formation algorithm.

class plafosim.infrastructure.Infrastructure(simulator: Simulator, iid: int, position: int, formation_algorithm: str, execution_interval: int, **kw_args)[source]

Bases: object

A class representing road side infrastructure / road side units.

The infrastructure can execute formation algorithms.

__init__(simulator: Simulator, iid: int, position: int, formation_algorithm: str, execution_interval: int, **kw_args)[source]

Initialize an Infrastructure instance.

Parameters:
  • simulator (Simulator) – The global simulator object

  • iid (int) – The id of the infrastructure

  • position (int) – The position (x) of the infrastructure

  • formation_algorithm (str) – The platoon formation (i.e., assignment calculation) algorithm to run

  • execution_interval (int) – The execution interval for the formation algorithm

_action(step: int)[source]

Triggers concrete actions of an infrastructure.

Parameters:

step (int) – The current simulation step

_get_neighbors()[source]
action(step: int)[source]

Triggers actions of an infrastructure.

Parameters:

step (int) – The current simulation step

finish()[source]

Clean up the instance of the infrastructure.

property iid: int

Return the id of an infrastructure.

property position: int

Return the position of an infrastructure.

class plafosim.infrastructure.PlatooningVehicle(simulator: Simulator, vid: int, vehicle_type: VehicleType, depart_position: int, arrival_position: int, desired_speed: float, depart_lane: int, depart_speed: float, depart_time: float, depart_delay: float = 0, communication_range: int = 1000, acc_headway_time: float = 1.0, cacc_spacing: float = 5.0, formation_algorithm: str = None, execution_interval: int = 1, pre_filled: bool = False, **kw_args)[source]

Bases: Vehicle

A vehicle that has platooning functionality.

__init__(simulator: Simulator, vid: int, vehicle_type: VehicleType, depart_position: int, arrival_position: int, desired_speed: float, depart_lane: int, depart_speed: float, depart_time: float, depart_delay: float = 0, communication_range: int = 1000, acc_headway_time: float = 1.0, cacc_spacing: float = 5.0, formation_algorithm: str = None, execution_interval: int = 1, pre_filled: bool = False, **kw_args)[source]

Initialize a platooning vehicle instance.

Parameters:
  • simulator (Simulator) – The global simulator object

  • vid (int) – The id of the vehicle

  • vehicle_type (VehicleType) – The vehicle type of the vehicle

  • depart_position (int) – The departure position of the vehicle

  • arrival_position (int) – The arrival position of the vehicle

  • desired_speed (float) – The desired driving speed of the vehicle

  • depart_lane (int) – The departure lane of the vehicle

  • depart_speed (float) – The departure speed of the vehicle

  • depart_time (float) – The actual departure time of the vehicle

  • depart_delay (float) – The time the vehicle had to wait before starting its trip

  • communication_range (int) – The maximum communication range of the vehicle

  • acc_headway_time (float) – The headway time for the ACC

  • cacc_spacing (float) – The constant spacing for the CACC

  • formation_algorithm (str) – The platoon formation algorithm to use

  • execution_interval (int) – The interval for executing the formation algorithm

  • pre_filled (bool) – Whether this vehicle was pre-filled

_action(step: float)[source]

Triggers specific actions of a PlatooningVehicle.

Parameters:

step (float) – The current simulation step

_calculate_emission(a: float, v: float, f: list, scale: float) float[source]

Calculate the emitted pollutant amount using the given speed and acceleration.

Parameters:
  • a (float) – The current acceleration

  • v (float) – The current speed

  • f (list) – The emission factors to use for current emission variable to be calculated

  • scale (float) – The scale to normalize the calculated value

Returns:

float

Return type:

The calculcated emission in ml/mg per s

_calculate_emissions()

Calculate the emitted pollutant amount using the given speed and acceleration based on the HBEFA3 model.

As the functions are defining emissions in g/hour, the function’s result is normed by 3.6 (seconds in an hour/1000) yielding mg/s. For fuel ml/s is returned. Negative acceleration results directly in zero emission.

The amount emitted by the given emission class when moving with the given velocity and acceleration [mg/s or ml/s]

_get_available_platoons() list[source]

Return the available platoon candidates of the vehicle.

This imitates neighbor maintenance by using a neighbor table.

Returns:

list(PlatooninVehicle)

Return type:

The list of available platoons

_join(platoon_id: int, leader_id: int)[source]

Lets a vehicle join a platoon.

Communication and fine-grained maneuver control is out-of-scope and thus omitted.

Parameters:
  • platoon_id (int) – The id of the target platoon

  • leader_id (int) – The id of the leader of the target platoon

_join_teleport(leader: PlatooningVehicle, last: PlatooningVehicle, new_position: float)[source]

Perform the actual teleporting of the join maneuver.

Parameters:
  • leader (PlatooningVehicle) – The leader of the target platoon

  • last (PlatooningVehicle) – The last vehicle of the target platoon

  • new_position (float) – The new position for joining the target platoon

_leave()[source]

Lets a vehicle leave a platoon.

Communication and fine-grained maneuver control is out-of-scope and thus omitted.

_left_lane_blocked() bool[source]

Check whether a vehicle can move to the left lane in order to leave its current platoon.

Returns:

bool

Return type:

Whether the left lane is blocked

_start()

Start this Vehicle.

_statistics()[source]

Write continuous statistics.

_teleport(new_position: float, new_lane: int, new_speed: float)[source]

Teleport a vehicle to a given position.

Parameters:
  • new_position (float) – The new position

  • new_lane (int) – The new lane

  • new_speed (float) – The new speed

action(step: int)

Triggers actions of a vehicle.

Parameters:

step (int) – The current simulation step

calculate_approaching_time(target_position: float, target_speed: float) float[source]

Calculate approximate time to approach the target position at target speed.

Parameters:
  • target_position (float) – The target position to approach

  • target_speed (float) – The target speed after approaching

Returns:

float

Return type:

The calculated approaching time

finish()[source]

Clean up the instance of the PlatooningVehicle.

This includes leaving the platoon and mostly statistics recording.

get_front_gap() float[source]

Return the gap to the vehicle in the front.

This imitates a measurement of the front radar sensor.

get_front_speed() float[source]

Return the speed to the vehicle in the front.

This imitates a measurement of the front radar sensor.

info() str[source]

Return information about the PlatooningVehicle.

is_in_platoon() bool[source]

Return whether the vehicle currently is in a platoon.

This is based on the current PlatoonRole. A joining or leaving vehicle is either not yet or still part of a platoon, thus the returned value should be true.

property acc_headway_time: float

Return the ACC headway time of the vehicle.

property arrival_position: int

Return the arrival position of the vehicle.

property blocked_front: bool

Return whether the vehicle is currently blocked by a slow vehicle in the front.

property cf_model: CF_Model

Return the currently activated car following model of the vehicle.

property color: tuple

Return the current color of the vehicle.

property depart_lane: int

Return the departure lane of the vehicle.

property depart_position: int

Return the departure position of the vehicle.

property depart_speed: float

Return the departure speed of the vehicle.

property depart_time: float

Return the departure time of the vehicle.

property desired_gap: float

Return the desired gap of the vehicle.

This is based on the currently active car following model.

property desired_headway_time: float

Return the desired headway time of the vehicle.

This is based on the currently active car following model.

property desired_speed: float

Return the desired driving speed of the vehicle.

If the vehicle is in a platoon, it returns the desired driving speed of the entire platoon.

property distance_in_platoon: float

Return the travelled distance within platoons.

property headway_time: float

Return the human headway time of the vehicle.

This is based on the vehicle type.

property in_maneuver: bool

Return whether the vehicle is currently in a maneuver.

property lane: int

Return the current lane of the vehicle.

property length: int

Return the length of the vehicle.

This is based on the vehicle type.

property max_acceleration: float

Return the maximum acceleration of the vehicle.

This is based on the vehicle type.

property max_deceleration: float

Return the maximum deceleration of the vehicle.

This is based on the vehicle type.

property max_speed: float

Return the maximum speed of the vehicle.

This is based on the vehicle type.

property min_gap: float

Return the minimum safety gap to the vehicle in front of the vehicle.

This is based on the vehicle type.

property platoon: Platoon

Return the platoon of the vehicle.

property platoon_role: PlatoonRole

Return the current platoon role of the vehicle.

property position: float

Return the current position of the vehicle.

property rear_position: int

Return the current rear position of the vehicle.

property speed: float

Return the current driving speed of the vehicle.

property time_in_platoon: int

Return the travelled time within platoons.

property travel_distance: float

Return the current traveled distance of the vehicle.

property travel_time: float

Return the current traveled time of the vehicle.

property vehicle_type: VehicleType

Return the VehicleType of the vehicle.

property vid: int

Return the id of the vehicle.

class plafosim.infrastructure.SpeedPosition(owner: object, alpha: float = 0.5, speed_deviation_threshold: float = 0.2, position_deviation_threshold: int = 1000, formation_centralized_kind: str = 'greedy', solver_time_limit: int = 60, record_solver_traces: bool = False, record_infrastructure_assignments: bool = False, **kw_args)[source]

Bases: FormationAlgorithm

Platoon Formation Algorithm based on Similarity, considering Speed and Position.

See papers

Julian Heinovski and Falko Dressler, “Where to Decide? Centralized vs. Distributed Vehicle Assignment for Platoon Formation,” arXiv, cs.MA, 2310.09580, October 2023. https://www.tkn.tu-berlin.de/bib/heinovski2023where-preprint/

and

Julian Heinovski and Falko Dressler, “Platoon Formation: Optimized Car to Platoon Assignment Strategies and Protocols,” Proceedings of 10th IEEE Vehicular Networking Conference (VNC 2018), Taipei, Taiwan, December 2018. https://www.tkn.tu-berlin.de/bib/heinovski2018platoon/

__init__(owner: object, alpha: float = 0.5, speed_deviation_threshold: float = 0.2, position_deviation_threshold: int = 1000, formation_centralized_kind: str = 'greedy', solver_time_limit: int = 60, record_solver_traces: bool = False, record_infrastructure_assignments: bool = False, **kw_args)[source]

Initialize an instance of this formation algorithm to be used in a vehicle or an infrastructure.

Parameters:
  • owner (object) – The owning object that is execution this algorithm. This can be either a PlatooningVehicle or an Infrastructure.

  • alpha (float) – The weighting factor alpha

  • speed_deviation_threshold (float) – The threshold for speed deviation

  • position_deviation_threshold (int) – The threshold for position deviation

  • formation_centralized_kind (str) – TODO

  • solver_time_limit (int) – The time limit in s to apply to the solver

  • record_solver_traces (bool) – Whether to record continuous solver traces

  • record_infrastructure_assignments (bool) – Whether to record infrastructure assignments

_do_formation_centralized()[source]

Run centralized greedy formation approach.

This selects candidates and triggers join maneuvers.

_do_formation_distributed()[source]

Run distributed greedy formation approach.

This selects a candidate and triggers a join maneuver.

_do_formation_optimal()[source]

Run centralized optimal formation approach.

This selects candidates and triggers join maneuvers.

_record_infrastructure_assignments(basename: str)[source]

Record infrastructure assignments.

Parameters:

basename (str) – The basename of the result file

classmethod add_parser_argument_group(parser: ArgumentParser) _ArgumentGroup[source]

Create and return specific argument group for this algorithm to use in global argument parser.

Parameters:

parser (argparse.ArgumentParser) – The global argument parser

Returns:

The specific argument group for this algorithm

Return type:

argparse._ArgumentGroup

cost_speed_position(ds: float, dp: float) float[source]

Return the overall cost (i.e., the weighted deviation) for a candidate.

Parameters:
  • ds (float) – The deviation in speed

  • dp (int) – The deviation in position

Returns:

The weighted relative deviation

Return type:

float

do_formation()[source]

Run platoon formation algorithms to search for a platooning opportunity and perform the corresponding join maneuver.

dp(vehicle: PlatooningVehicle, platoon: Platoon) float[source]

Return the deviation in position from a given platoon.

NOTE: In the original version of the paper, the deviation calculated here was not normalized.

Parameters:
  • vehicle (PlatooningVehicle) – The vehicle for which the deviation is calculated

  • platoon (Platoon) – The platoon to which the deviation is calculated

Returns:

The relative deviation in position

Return type:

float

ds(vehicle: PlatooningVehicle, platoon: Platoon) float[source]

Return the deviation in speed from a given platoon.

NOTE: In the original version of the paper, the deviation calculated here was not normalized.

Parameters:
  • vehicle (PlatooningVehicle) – The vehicle for which the deviation is calculated

  • platoon (Platoon) – The platoon to which the deviation is calculated

Returns:

The relative deviation in speed

Return type:

float

finish()[source]

Clean up the instance of the formation algorithm.

This includes mostly statistic recording.

_abc_impl = <_abc_data object>
property name

Print the name of the formation algorithm.

plafosim.infrastructure.attribute()

perf_counter() -> float

Performance counter for benchmarking.

plafosim.infrastructure.import_module(name, package=None)[source]

Import a module.

The ‘package’ argument is required when performing a relative import. It specifies the package to use as the anchor point from which to resolve the relative import to an absolute import.

plafosim.infrastructure.isclass(object)[source]

Return true if the object is a class.

Class objects provide these attributes:

__doc__ documentation string __module__ name of module in which this class was defined

plafosim.infrastructure.iter_modules(path=None, prefix='')[source]

Yields ModuleInfo for all submodules on path, or, if path is None, all top-level modules on sys.path.

‘path’ should be either None or a list of paths to look for modules in.

‘prefix’ is a string to output on the front of every module name on output.