plafosim.algorithms.speed_position module
- class plafosim.algorithms.speed_position.FormationAlgorithm(owner: object)[source]
Bases:
ABCAbstract 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.
- _abc_impl = <_abc_data object>
- property name
Print the name of the formation algorithm.
- class plafosim.algorithms.speed_position.PlatoonRole(value)[source]
Bases:
EnumA collection of available platoon roles.
- FOLLOWER = 2
- JOINER = 3
- LEADER = 1
- LEAVER = 4
- NONE = 0
- class plafosim.algorithms.speed_position.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:
FormationAlgorithmPlatoon 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,” IEEE Transactions on Intelligent Transportation Systems, vol. 25 (11), pp. 17317–17334, November 2024. https://www.tkn.tu-berlin.de/bib/heinovski2024where/
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.algorithms.speed_position.initialize_infrastructure_assignments(basename: str)[source]
Initialize the infrastructure assignments result file.
- Parameters:
basename (str) – The basename of the result file
- plafosim.algorithms.speed_position.initialize_solver_traces(basename: str)[source]
Initialize the solver trace file.
- Parameters:
basename (str) – The basename of the trace file
- plafosim.algorithms.speed_position.record_solver_trace(basename: str, step: float, iid: int, variables: int, constraints: int, run_time: float, result_status: int, solution_value: float, best_bound: float, solution_quality: float)[source]
Record one line in the solver trace file.
- Parameters:
basename (str) – The basename of the trace file
step (float) – The current simulation step
iid (int) – The id of the infrastructure which executed the solver run
variables (int) – The number of variables
constraints (int) – The number of constraints
run_time (float) – The run time of the solver
result_status (int) – The result status of the solver
solution_value (float) – The solution value of the solver
best_bound (float) – The best bound of the problem
solution_quality (float) – The quality of the solution
- plafosim.algorithms.speed_position.strtobool(val)[source]
Convert a string representation of truth to true (1) or false (0).
True values are ‘y’, ‘yes’, ‘t’, ‘true’, ‘on’, and ‘1’; false values are ‘n’, ‘no’, ‘f’, ‘false’, ‘off’, and ‘0’. Raises ValueError if ‘val’ is anything else.
- plafosim.algorithms.speed_position.timer()
perf_counter() -> float
Performance counter for benchmarking.