Skip to content

Commit

Permalink
MSAbstractLaneChangeModel: add checkChangeBeforeCommitting() method t…
Browse files Browse the repository at this point in the history
…o be invoked by MSLaneChanger before moving a vehicle to an adjacent lane

By default, this method does nothing making it backward compatible
  • Loading branch information
michele-segata committed May 2, 2024
1 parent 0a3da5a commit ec8e4c2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/microsim/MSLaneChanger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,11 @@ MSLaneChanger::checkChange(
<< "\n";
}
#endif

if (state & LCA_WANTS_LANECHANGE && blocked == 0) {
blocked = vehicle->getLaneChangeModel().checkChangeBeforeCommitting(vehicle, state);
state |= blocked;
}
vehicle->getLaneChangeModel().saveLCState(laneOffset, oldstate, state);
if (blocked == 0 && (state & LCA_WANTS_LANECHANGE)) {
// this lane change will be executed, save gaps
Expand Down
14 changes: 14 additions & 0 deletions src/microsim/lcmodels/MSAbstractLaneChangeModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,20 @@ class MSAbstractLaneChangeModel {
*/
virtual LaneChangeModel getModelID() const = 0;

/** @brief Informs the vehicle that it is about to be moved on an adjacent lane.
* The method can be used to re-evaluate the state of the vehicle and potentially abort the lane change.
* By default, if the method is not overridden by the lane change model implementation, nothing is altered and the vehicle will perform the lane change.
* @param veh the lane changing vehicle
* @param state current lane change state
* @return the blocked status of the vehicle. If the vehicle should perform the lane change, the method should return 0, corresponding to non-blocked.
* Otherwise the method should return a non-zero state, corresponding to the type of blockage.
*/
virtual int checkChangeBeforeCommitting(const MSVehicle* veh, int state) const {
UNUSED_PARAMETER(veh);
UNUSED_PARAMETER(state);
return 0;
}

/** @brief Save the state of the laneChangeModel
* @param[in] out The OutputDevice to write the information into
*/
Expand Down

0 comments on commit ec8e4c2

Please sign in to comment.