Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JuPedSim] Added pedestrian removal in predefined area, at predefined rate. #14308

Merged
merged 2 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/microsim/transportables/MSPModel_JuPedSim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ MSPModel_JuPedSim::execute(SUMOTime time) {
UNUSED_PARAMETER(result);
assert(result == false); // The person has not arrived yet.
stage->activateEntryReminders(person);
// Adapt speed to lane's speed limit.
JPS_CollisionFreeSpeedModelState modelState = JPS_Agent_GetCollisionFreeSpeedModelState(agent, nullptr);
const double newMaxSpeed = MIN2(candidateLane->getSpeedLimit(), person->getMaxSpeed());
if (newMaxSpeed != JPS_CollisionFreeSpeedModelState_GetV0(modelState)) {
Expand All @@ -348,6 +349,32 @@ MSPModel_JuPedSim::execute(SUMOTime time) {
++stateIt;
}

// Remove pedestrians that are in a predefined area, at a predefined rate.
for (const auto& vanishingArea : myVanishingAreas) {
std::vector<JPS_Point> vanishingAreaBoundary = vanishingArea.second.vanishingAreaBoundary;
JPS_AgentIdIterator agentsInVanishingAreaIterator = JPS_Simulation_AgentsInPolygon(myJPSSimulation, vanishingAreaBoundary.data(), vanishingAreaBoundary.size());
SUMOTime elapsedTime = time - myLastRemovalTime;
if (elapsedTime >= vanishingArea.second.period) {
const JPS_AgentId agentID = JPS_AgentIdIterator_Next(agentsInVanishingAreaIterator);
if (agentID != 0) {
auto lambda = [agentID](PState* 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;
}
}
}
}

JPS_ErrorMessage_Free(message);

return DELTA_T;
Expand Down Expand Up @@ -794,6 +821,14 @@ MSPModel_JuPedSim::initialize() {
preparePolygonForJPS(maxAreaConnectedComponentPolygon);
preparePolygonForDrawing(maxAreaConnectedComponentPolygon, maxAreaPolygonId);

for (const auto& polygonWithID : myNetwork->getShapeContainer().getPolygons()) {
if (polygonWithID.second->getShapeType() == "jupedsim.vanishing_area") {
std::vector<JPS_Point> vanishingAreaBoundary = convertToJPSPoints(polygonWithID.second->getShape());
SUMOTime period = (SUMOTime)(1.0 / std::stod(polygonWithID.second->getParameter("frequency", "1.0"))) * 1000; // SUMOTime is in ms.
myVanishingAreas.insert(std::make_pair(polygonWithID.second->getID(), VanishingAreaData{vanishingAreaBoundary, period}));
}
}

JPS_ErrorMessage message = nullptr;
myJPSGeometry = JPS_GeometryBuilder_Build(myJPSGeometryBuilder, &message);
if (myJPSGeometry == nullptr) {
Expand Down
6 changes: 6 additions & 0 deletions src/microsim/transportables/MSPModel_JuPedSim.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ class MSPModel_JuPedSim : public MSPModel {
JPS_CollisionFreeSpeedModelBuilder myJPSModelBuilder;
JPS_OperationalModel myJPSModel;
JPS_Simulation myJPSSimulation;
struct VanishingAreaData {
std::vector<JPS_Point> vanishingAreaBoundary;
SUMOTime period;
};
std::map<std::string, VanishingAreaData> myVanishingAreas;
SUMOTime myLastRemovalTime;

static const int GEOS_QUADRANT_SEGMENTS;
static const double GEOS_MITRE_LIMIT;
Expand Down
3 changes: 3 additions & 0 deletions tests/sumo/pedestrian_model/jupedsim/testsuite.sumo
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
two_edges

# This test checks the mechanism that removes pedestrians at a certain rate who enter a vanishing area.
vanishing_area

# This test checks that when a pedestrian walks on a new edge, the max speed of the new edge is taken into account.
speed_change

Expand Down
33 changes: 33 additions & 0 deletions tests/sumo/pedestrian_model/jupedsim/vanishing_area/errors.sumo
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Warning: While generating geometry 2 connected components were detected, 97.51% of total pedestrian area is covered by the first.
Warning: Error while adding person 'pf_0.10' as JuPedSim agent: Model constraint violation: Agent (1596.52, 1889.3) too close to agent (1596.6354138289284, 1889.5504644398566): distance 0.2757766986904751
Warning: Error while adding person 'pf_1.10' as JuPedSim agent: Model constraint violation: Agent (1790.93, 1898.96) too close to agent (1790.9555326732425, 1899.2345921887609): distance 0.27577669867371
Warning: Error while adding person 'pf_2.10' as JuPedSim agent: Model constraint violation: Agent (1799.82, 2076.16) too close to agent (1799.547239134107, 2076.023280800467): distance 0.3051075703477827
Warning: Error while adding person 'pf_0.13' as JuPedSim agent: Model constraint violation: Agent (1596.52, 1889.3) too close to agent (1596.683918716202, 1889.6511419438034): distance 0.38751775471503447
Warning: Error while adding person 'pf_2.13' as JuPedSim agent: Model constraint violation: Agent (1799.82, 2076.16) too close to agent (1799.4877626211392, 2075.9944977492087): distance 0.3711774116635181
Warning: Error while adding person 'pf_0.14' as JuPedSim agent: Model constraint violation: Agent (1596.52, 1889.3) too close to agent (1596.7632573800906, 1889.047500514146): distance 0.350613951982994
Warning: Error while adding person 'pf_2.14' as JuPedSim agent: Model constraint violation: Agent (1799.82, 2076.16) too close to agent (1799.8652752292621, 2076.4051194550375): distance 0.2492657088784829
Warning: Error while adding person 'pf_2.15' as JuPedSim agent: Model constraint violation: Agent (1799.82, 2076.16) too close to agent (1799.7861648899782, 2076.1121116151007): distance 0.05863541658785216
Warning: Error while adding person 'pf_0.20' as JuPedSim agent: Model constraint violation: Agent (1596.52, 1889.3) too close to agent (1596.660097519101, 1889.6040315553146): distance 0.3347573770439075
Warning: Error while adding person 'pf_1.20' as JuPedSim agent: Model constraint violation: Agent (1790.93, 1898.96) too close to agent (1790.953128685575, 1899.2087384041024): distance 0.2498113883949544
Warning: Error while adding person 'pf_2.20' as JuPedSim agent: Model constraint violation: Agent (1799.82, 2076.16) too close to agent (1799.5318500426215, 2076.015856977693): distance 0.32219188198479926
Warning: Error while adding person 'pf_1.23' as JuPedSim agent: Model constraint violation: Agent (1790.93, 1898.96) too close to agent (1790.9469243946894, 1899.2692263319902): distance 0.309689133699773
Warning: Error while adding person 'pf_2.23' as JuPedSim agent: Model constraint violation: Agent (1799.82, 2076.16) too close to agent (1799.4769999841446, 2075.9890559685928): distance 0.3832373582395653
Warning: Error while adding person 'pf_1.24' as JuPedSim agent: Model constraint violation: Agent (1790.93, 1898.96) too close to agent (1790.7370637555794, 1899.0934766573273): distance 0.2346069318294472
Warning: Error while adding person 'pf_1.25' as JuPedSim agent: Model constraint violation: Agent (1790.93, 1898.96) too close to agent (1791.3176251431648, 1898.8565778541752): distance 0.4011849845900643
Warning: Error while adding person 'pf_2.28' as JuPedSim agent: Model constraint violation: Agent (1799.82, 2076.16) too close to agent (1799.4929522517018, 2075.9955022465892): distance 0.36608706688985193
Warning: Error while adding person 'pf_1.29' as JuPedSim agent: Model constraint violation: Agent (1790.93, 1898.96) too close to agent (1790.9735702901148, 1899.4285900815028): distance 0.4706113414096763
Warning: Error while adding person 'pf_0.30' as JuPedSim agent: Model constraint violation: Agent (1596.52, 1889.3) too close to agent (1596.635413829293, 1889.5504644406503): distance 0.2757766995639175
Warning: Error while adding person 'pf_1.30' as JuPedSim agent: Model constraint violation: Agent (1790.93, 1898.96) too close to agent (1791.1945021011122, 1898.6191065507383): distance 0.4314738755038857
Warning: Error while adding person 'pf_2.39' as JuPedSim agent: Model constraint violation: Agent (1799.82, 2076.16) too close to agent (1799.5020023105224, 2076.000018909255): distance 0.3559725830862027
Warning: Error while adding person 'pf_0.40' as JuPedSim agent: Model constraint violation: Agent (1596.52, 1889.3) too close to agent (1596.6243517041207, 1889.5264580541514): distance 0.24934419673003322
Warning: Error while adding person 'pf_1.40' as JuPedSim agent: Model constraint violation: Agent (1790.93, 1898.96) too close to agent (1790.9639691530376, 1899.3253226591057): distance 0.3668985535732442
Warning: Error while adding person 'pf_1.43' as JuPedSim agent: Model constraint violation: Agent (1790.93, 1898.96) too close to agent (1790.962034814621, 1899.3486758516221): distance 0.3899937781323747
Warning: Error while adding person 'pf_2.43' as JuPedSim agent: Model constraint violation: Agent (1799.82, 2076.16) too close to agent (1799.593145546246, 2076.046271050323): distance 0.2537660678314124
Warning: Error while adding person 'pf_1.44' as JuPedSim agent: Model constraint violation: Agent (1790.93, 1898.96) too close to agent (1790.5979519151804, 1899.0316086637695): distance 0.33968180899080863
Warning: Error while adding person 'pf_2.44' as JuPedSim agent: Model constraint violation: Agent (1799.82, 2076.16) too close to agent (1799.561388884373, 2076.471700251186): distance 0.4050145129688793
Warning: Error while adding person 'pf_1.45' as JuPedSim agent: Model constraint violation: Agent (1790.93, 1898.96) too close to agent (1790.519022409171, 1899.1281257761084): distance 0.44403699930946694
Warning: Error while adding person 'pf_2.45' as JuPedSim agent: Model constraint violation: Agent (1799.82, 2076.16) too close to agent (1800.0355596767552, 2076.2562266044224): distance 0.23606256298174338
Warning: Error while adding person 'pf_2.46' as JuPedSim agent: Model constraint violation: Agent (1799.82, 2076.16) too close to agent (1799.8549418077073, 2075.791098320907): distance 0.37055280158603804
Warning: Error while adding person 'pf_2.47' as JuPedSim agent: Model constraint violation: Agent (1799.82, 2076.16) too close to agent (1799.8125718393642, 2076.2400682872067): distance 0.08041211467598261
Warning: The pedestrian model uses infrastructure which is not in the network, timeLoss and routeLength may be invalid.
Warning: Error while adding person 'pf_0.49' as JuPedSim agent: Model constraint violation: Agent (1596.52, 1889.3) too close to agent (1596.717084978785, 1889.7277024622986): distance 0.470926623922396
Loading
Loading