plafosim.mobility module
- class plafosim.mobility.ACC_SPEED_DF(predecessor_speed, speed, acc_lambda, desired_gap, predecessor_gap, desired_headway_time)
Bases:
tuple
- _asdict()
Return a new dict which maps field names to their values.
- classmethod _make(iterable)
Make a new ACC_SPEED_DF object from a sequence or iterable
- _replace(**kwds)
Return a new ACC_SPEED_DF object replacing specified fields with new values
- count(value, /)
Return number of occurrences of value.
- index(value, start=0, stop=9223372036854775807, /)
Return first index of value.
Raises ValueError if the value is not present.
- _field_defaults = {}
- _fields = ('predecessor_speed', 'speed', 'acc_lambda', 'desired_gap', 'predecessor_gap', 'desired_headway_time')
- _fields_defaults = {}
- acc_lambda
Alias for field number 2
- desired_gap
Alias for field number 3
- desired_headway_time
Alias for field number 5
- predecessor_gap
Alias for field number 4
- predecessor_speed
Alias for field number 0
- speed
Alias for field number 1
- class plafosim.mobility.CF_Model(value)[source]
Bases:
Enum
Car Following models that vehicles can use for their mobility.
- ACC = 1
- CACC = 2
- HUMAN = 0
- class plafosim.mobility.Enum(value)[source]
Bases:
object
Generic enumeration.
Derive from this class to define new enumerations.
- _member_type_
alias of
object
- _generate_next_value_(start, count, last_values)[source]
Generate the next value when not given.
name: the name of the member start: the initial start value or None count: the number of existing members last_value: the last value assigned or None
- _member_map_ = {}
- _member_names_ = []
- _value2member_map_ = {}
- name
The name of the Enum member.
- value
The value of the Enum member.
- class plafosim.mobility.FAKE_PREDECESSOR(vid, position, speed, length)
Bases:
tuple
- _asdict()
Return a new dict which maps field names to their values.
- classmethod _make(iterable)
Make a new FAKE_PREDECESSOR object from a sequence or iterable
- _replace(**kwds)
Return a new FAKE_PREDECESSOR object replacing specified fields with new values
- count(value, /)
Return number of occurrences of value.
- index(value, start=0, stop=9223372036854775807, /)
Return first index of value.
Raises ValueError if the value is not present.
- _field_defaults = {}
- _fields = ('vid', 'position', 'speed', 'length')
- _fields_defaults = {}
- length
Alias for field number 3
- position
Alias for field number 1
- speed
Alias for field number 2
- vid
Alias for field number 0
- class plafosim.mobility.SAFE_SPEED_DF(predecessor_speed, speed, max_deceleration, predecessor_gap, desired_gap, desired_headway_time)
Bases:
tuple
- _asdict()
Return a new dict which maps field names to their values.
- classmethod _make(iterable)
Make a new SAFE_SPEED_DF object from a sequence or iterable
- _replace(**kwds)
Return a new SAFE_SPEED_DF object replacing specified fields with new values
- count(value, /)
Return number of occurrences of value.
- index(value, start=0, stop=9223372036854775807, /)
Return first index of value.
Raises ValueError if the value is not present.
- _field_defaults = {}
- _fields = ('predecessor_speed', 'speed', 'max_deceleration', 'predecessor_gap', 'desired_gap', 'desired_headway_time')
- _fields_defaults = {}
- desired_gap
Alias for field number 4
- desired_headway_time
Alias for field number 5
- max_deceleration
Alias for field number 2
- predecessor_gap
Alias for field number 3
- predecessor_speed
Alias for field number 0
- speed
Alias for field number 1
- plafosim.mobility.assert_index_equal(one, two) bool [source]
Ensure the indices of two Sequences/DataFrames are equal.
- Parameters:
one (pandas.Sequence / pandas.DataFrame) – The first object for the comparison
two (pandas.Sequence / pandas.DataFrame) – The second object for the comparsion
- Returns:
bool
- Return type:
Whether the two indices are equal
- plafosim.mobility.clamp_speed(new_speed: Series, vdf: DataFrame, step_length: float) Series [source]
Clamp (two-way limit) a new speed value to vehicle’s maximum.
- plafosim.mobility.clip_position(position: Series, vdf: DataFrame) Series [source]
Return the clipped positions (i.e., by arrival position) of vehicles within a pandas Dataframe.
- Parameters:
position (pandas.Series) – The series containing the positions to be clipped index: vid columns: [position, length, lane, ..]
vdf (pandas.DataFrame) – The Dataframe containing the vehicles as rows index: vid columns: [position, length, lane, ..]
- Returns:
The series of clipped positions index: vid
- Return type:
pandas.Series
- plafosim.mobility.compute_lane_changes(vdf: DataFrame, max_lane: int, step_length: float) DataFrame [source]
Find desired and safe lane changes.
compute all speed gains
“apply” all speed gains
compute all keep rights
“apply” all keep rights
This is based on Krauss’ multi lane traffic: laneChange() congested = (v_safe < v_thresh) and (v^0_safe < v_thresh) favorable(right->left) = (v_safe < v_max) and (not congested) favorable(left->right) = (v_safe >= v_max) and (v^0_safe >= v_max) if ((favorable(i->j) or (rand < p_change)) and safe(i->j)) then change(i->j) for vehicles on the right lane: if (v > v^0_safe) and (not congested) then v <- v^0_safe
- Parameters:
vdf (pandas.DataFrame) – The Dataframe containing the vehicles as rows index: vid columns: [position, length, lane, ..]
max_lane (int) – The largest lane id
step_length (float) – The length of a simulation step
- Returns:
The Dataframe containing the vehicles as rows index: vid columns: [lane, reason]
- Return type:
pandas.DataFrame
- plafosim.mobility.compute_new_speeds(vdf: DataFrame, step_length: float) Series [source]
Compute the new speed for all vehicles in the simulation.
Can compute “potential” new speed for different target lanes. Assume vdf already contains predecessor and successor data. Just pass the right predecessor/successor data for different lanes.
- Parameters:
vdf (pandas.DataFrame) – The Dataframe containing the vehicles as rows index: vid columns: [position, length, lane, ..]
step_length (float) – The length of a simulation step
- Returns:
The series of new speeds index: vid
- Return type:
pandas.Series
- plafosim.mobility.get_crashed_vehicles(vdf: DataFrame) list [source]
Return the list of crashed vehicles’ ids.
- Parameters:
vdf (pandas.DataFrame) – The Dataframe containing the vehicles as rows index: vid columns: [position, length, lane, ..]
- Returns:
list(int)
- Return type:
the list of vehicles that crashed
- plafosim.mobility.get_predecessors(vdf: DataFrame, predecessor_map: DataFrame, target_lane: Series) DataFrame [source]
Return DataFrame of successors to the vehicles on a target lane.
- plafosim.mobility.get_successors(vdf: DataFrame, successor_map: DataFrame, target_lane: Series) DataFrame [source]
Return DataFrame of successors to the vehicles on a target lane.
- plafosim.mobility.is_gap_safe(front_position: float, front_speed: float, front_max_deceleration: float, front_length: float, back_position: float, back_speed: float, back_max_acceleration: float, back_min_gap: float, step_length: float) bool [source]
Return whether the gap between the front and back vehicle is safe.
Safe means: - the front vehicle can decelerate as hard as possible for one step - the back vehicle can accelerate as hard as possible for one step - the vehicle will not crash
Assumes euclidean/non-ballistic position updates.
- Parameters:
front_position (float) – The position of the front vehicle in m
front_speed (float) – The speed of the front vehicle in m/s
front_max_deceleration (float) – The maximum deceleration of the front vehicle in m/s2
front_length (length) – The length of the front vehicle in m
back_position (float) – The position of the back vehicle in m
back_speed (float) – The speed of the back vehicle in m/s
back_max_acceleration (float) – The maximum acceleration of the back vehicle in m/s2
back_min_gap (float) – The minimum gap of the back vehicle in m
step_length (float) – The length of a simulation step in s
- Returns:
bool
- Return type:
Whether the gap between the two vehicles is safe
- plafosim.mobility.lane_predecessors(vdf: DataFrame, max_lane: int) DataFrame [source]
Find the current (potential) predecessor for each lane and each vehicle.
This means: Which other vehicle would be the predecessor if a vehicle was on lane column. A predecessor id of -1 means there is no predecessor.
Preconditions: - vdf.sorted_values([‘position’, ‘lane’], ascending=False)
- Parameters:
vdf (pandas.DataFrame) – The Dataframe containing the vehicles as rows index: vid columns: [position, length, lane, ..]
max_lane (int) – The largest lane id
- plafosim.mobility.lane_successors(vdf: DataFrame, max_lane: int) DataFrame [source]
Find the current (potential) successors for each lane and each vehicle.
This means: Which other vehicle would be the successor if a vehicle was on lane column. A successor id of -1 means there is no successor.
Preconditions: - vdf.sorted_values([‘position’, ‘lane’], ascending=False)
- Parameters:
vdf (pandas.DataFrame) – The Dataframe containing the vehicles as rows index: vid columns: [position, length, lane, ..]
max_lane (int) – The largest lane id
- plafosim.mobility.namedtuple(typename, field_names, *, rename=False, defaults=None, module=None)[source]
Returns a new subclass of tuple with named fields.
>>> Point = namedtuple('Point', ['x', 'y']) >>> Point.__doc__ # docstring for the new class 'Point(x, y)' >>> p = Point(11, y=22) # instantiate with positional args or keywords >>> p[0] + p[1] # indexable like a plain tuple 33 >>> x, y = p # unpack like a regular tuple >>> x, y (11, 22) >>> p.x + p.y # fields also accessible by name 33 >>> d = p._asdict() # convert to a dictionary >>> d['x'] 11 >>> Point(**d) # convert from a dictionary Point(x=11, y=22) >>> p._replace(x=100) # _replace() is like str.replace() but targets named fields Point(x=100, y=22)
- plafosim.mobility.safe_speed(speed_predecessor, speed_current, gap_to_predecessor, desired_headway_time, max_deceleration, desired_gap)[source]
- plafosim.mobility.safe_speed_df(vdf: DataFrame) Series [source]
Compute the safe speed according to the Krauss model, DataFrame variant.
See S. Krauss, Microscopic Modeling of Traffic Flow: Investigation of Collision Free Vehicle Dynamics, 1998, Equation (4.21). v_safe = v_leader + (gap - gap_desired) / tau_b + tau gap_desired = tau * v_leader tau_b = v_avg / b b = typical deceleration of drivers tau = reaction time of drivers
safety is guaranteed, if step length <= tau and gap_desired >= v_leader * step_length <=> if the true reaction time (i.e., the length of one time step) is smaller than or equal to the reaction time that each driver assumes
- Parameters:
vdf (pandas.DataFrame) – The Dataframe containing the vehicles as rows index: vid columns: [position, length, lane, ..]
- plafosim.mobility.speed_acc_df(vdf: DataFrame, step_length: float) Series [source]
Compute new speed for ACC vehicles, DataFrame variant.
Clamping is done outside this function.
See Eq. 6.18 of R. Rajamani, Vehicle Dynamics and Control, 2nd. Springer, 2012.
- Parameters:
vdf (pandas.DataFrame) – The Dataframe containing the vehicles as rows index: vid columns: [position, length, lane, ..]
step_length (float) – The length of a simulation step in s
- plafosim.mobility.speed_human_df(vdf: DataFrame) Series [source]
Compute new speed for human vehicles, DataFrame variant.
Basically just safe speed, clamping is done outside this function.
- Parameters:
vdf (pandas.DataFrame) – The Dataframe containing the vehicles as rows index: vid columns: [position, length, lane, ..]
- plafosim.mobility.update_position(vdf: DataFrame, step_length: float) DataFrame [source]
Update the position of vehicles within a pandas Dataframe.
This is based on Krauss’ single lane traffic: adjust position (move) x(t + step_size) = x(t) + v(t)*step_size
- Parameters:
vdf (pandas.DataFrame) – The Dataframe containing the vehicles as rows index: vid columns: [position, length, lane, ..]
step_length (float) – The length of the simulated step
- Returns:
The Dataframe containing the vehicles as rows index: vid columns: [position, length, lane, ..]
- Return type:
pandas.DataFrame