Skip to content

Commit

Permalink
delete kept vehicle after loading from state. refs #9891
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed May 17, 2024
1 parent 2f45435 commit c246242
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/microsim/MSStateHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,10 @@ MSStateHandler::closeVehicle() {
MSRailSignalControl::getInstance().vehicleStateChanged(v, MSNet::VehicleState::NEWROUTE, "loadState");
}
vc.handleTriggeredDepart(v, false);
if (v->hasArrived()) {
// state was created with active option --keep-after-arrival
vc.deleteKeptVehicle(v);
}
}
while (!myDeviceAttrs.empty()) {
const std::string attrID = myDeviceAttrs.back()->getString(SUMO_ATTR_ID);
Expand Down
9 changes: 7 additions & 2 deletions src/microsim/MSVehicleControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ MSVehicleControl::removePending() {
if (myKeepTime == 0) {
deleteVehicle(veh);
} else {
myEndedVehNo++;
MSNet::getInstance()->getEndOfTimestepEvents()->addEvent(new DeleteKeptVehicle(veh), SIMSTEP + myKeepTime);
deleteKeptVehicle(veh);
}
}
vehs.clear();
Expand All @@ -191,6 +190,12 @@ MSVehicleControl::removePending() {
}


void
MSVehicleControl::deleteKeptVehicle(SUMOVehicle* veh) {
myEndedVehNo++;
MSNet::getInstance()->getEndOfTimestepEvents()->addEvent(new DeleteKeptVehicle(veh), SIMSTEP + myKeepTime);
}

void
MSVehicleControl::vehicleDeparted(const SUMOVehicle& v) {
++myRunningVehNo;
Expand Down
3 changes: 3 additions & 0 deletions src/microsim/MSVehicleControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ class MSVehicleControl {
*/
virtual void deleteVehicle(SUMOVehicle* v, bool discard = false, bool wasKept = false);

/** @brief when a vehicle is kept after arrival, schedule later deletion **/
void deleteKeptVehicle(SUMOVehicle* veh);

void fixVehicleCounts() {
myLoadedVehNo++;
myEndedVehNo++;
Expand Down

0 comments on commit c246242

Please sign in to comment.