Skip to content

Commit

Permalink
checking for existence of pedestrian before removal
Browse files Browse the repository at this point in the history
  • Loading branch information
behrisch committed Feb 13, 2024
1 parent d7608e1 commit 5213374
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/microsim/transportables/MSPModel_JuPedSim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,21 +355,23 @@ MSPModel_JuPedSim::execute(SUMOTime time) {
if (time - myLastRemovalTime >= vanishingArea.second.period) {
const JPS_AgentId agentID = JPS_AgentIdIterator_Next(agentsInVanishingAreaIterator);
if (agentID != 0) {
auto lambda = [agentID](PState * p) {
auto lambda = [agentID](const PState * const p) {
return p->getAgentId() == agentID;
};
std::vector<PState*>::const_iterator iterator = std::find_if(myPedestrianStates.begin(), myPedestrianStates.end(), lambda);
PState* state = *iterator;
MSPerson* person = state->getPerson();
// Code below only works if the removal happens at the last stage.
const bool finalStage = person->getNumRemainingStages() == 1;
if (finalStage) {
WRITE_MESSAGEF(TL("Person '%' in vanishing area '%' was removed from the simulation."), person->getID(), vanishingArea.first);
while (!state->getStage()->moveToNextEdge(person, time, 1, nullptr));
registerArrived();
JPS_Simulation_MarkAgentForRemoval(myJPSSimulation, agentID, nullptr);
myPedestrianStates.erase(iterator);
myLastRemovalTime = time;
if (iterator != myPedestrianStates.end()) {
const PState* const state = *iterator;
MSPerson* const person = state->getPerson();
// Code below only works if the removal happens at the last stage.
const bool finalStage = person->getNumRemainingStages() == 1;
if (finalStage) {
WRITE_MESSAGEF(TL("Person '%' in vanishing area '%' was removed from the simulation."), person->getID(), vanishingArea.first);
while (!state->getStage()->moveToNextEdge(person, time, 1, nullptr));
registerArrived();
JPS_Simulation_MarkAgentForRemoval(myJPSSimulation, agentID, nullptr);
myPedestrianStates.erase(iterator);
myLastRemovalTime = time;
}
}
}
}
Expand Down

0 comments on commit 5213374

Please sign in to comment.