Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSPModel_JuPedSim.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2014-2026 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
21// The pedestrian following model that can instantiate different pedestrian models
22// that come with the JuPedSim third-party simulation framework.
23/****************************************************************************/
24#pragma once
25#include <config.h>
26#include <vector>
27#include <map>
28#include <geos_c.h>
29#include <jupedsim/jupedsim.h>
31#include <microsim/MSNet.h>
33
34
35// ===========================================================================
36// class declarations
37// ===========================================================================
38class OutputDevice;
39
40
41// ===========================================================================
42// class definitions
43// ===========================================================================
50public:
51 MSPModel_JuPedSim(const OptionsCont& oc, MSNet* net);
53
55 void remove(MSTransportableStateAdapter* state) override;
57
58 bool usingShortcuts() override {
60 }
61 void registerArrived(const JPS_AgentId agentID);
62 void clearState() override;
63
64 class Event : public Command {
65 public:
66 explicit Event(MSPModel_JuPedSim* model)
67 : myModel(model) { }
68 SUMOTime execute(SUMOTime currentTime) override {
69 return myModel->execute(currentTime);
70 }
71
72 private:
74 };
75
82
83 typedef std::tuple<JPS_StageId, Position, double> WaypointDesc;
84
85 void polygonChanged(const SUMOPolygon* const poly, const bool added, const bool removed) override;
86
87private:
93 public:
94 PState(MSPerson* person, MSStageMoving* stage, JPS_JourneyId journeyId, JPS_StageId stageId, const std::vector<WaypointDesc>& waypoints);
95 ~PState() override;
96
97 void reinit(MSStageMoving* stage, JPS_JourneyId journeyId, JPS_StageId stageId, const std::vector<WaypointDesc>& waypoints);
98
99 inline Position getPosition(const MSStageMoving&, SUMOTime) const override {
100 return myRemoteXYPos;
101 }
102 void setPosition(const double x, const double y, const double z = 0.);
103
104 inline void setAngle(double angle) {
105 myAngle = angle;
106 }
107
108 inline void setStage(MSStageMoving* const stage) {
109 myStage = stage;
110 }
111
112 inline void setLane(MSLane* lane) {
113 myLane = lane;
114 }
115
116 inline void setLanePosition(double lanePosition) {
117 myEdgePos = lanePosition;
118 }
119 const MSEdge* getNextEdge(const MSStageMoving& stage) const override;
120
121 const MSPModel_JuPedSim::WaypointDesc* getNextWaypoint(const int offset = 0) const;
122
123 inline JPS_AgentId getAgentId() const {
124 return myAgentId;
125 }
126
127 void setAgentId(JPS_AgentId id) {
128 myAgentId = id;
129 myWaitingToEnter = false;
130 }
131
133 bool isFinished() const override {
134 return myWaypoints.empty();
135 }
136
137 JPS_JourneyId getJourneyId() const {
138 return myJourneyId;
139 }
140
142 JPS_StageId getStageId() const {
143 return myStageId;
144 }
145
147 myWaypoints.erase(myWaypoints.begin());
148 return myWaypoints.empty();
149 }
150
151 private:
153 JPS_JourneyId myJourneyId;
154 JPS_StageId myStageId;
155 std::vector<MSPModel_JuPedSim::WaypointDesc> myWaypoints;
156 JPS_AgentId myAgentId;
157 };
158
161
164
167
169 const double myExitTolerance;
170
171 std::vector<PState*> myPedestrianStates;
172
174 GEOSGeometry* myGEOSPedestrianNetwork; // Kept because the largest component refers to it.
175
178
180
182 JPS_Geometry myJPSGeometry; // Kept because of dynamic geometry switching and JPS_Simulation object.
183
187 JPS_OperationalModel myJPSOperationalModel;
188 JPS_Simulation myJPSSimulation;
190
192 struct AreaData {
193 const std::string id;
194 const std::string areaType;
195 const std::vector<JPS_Point> areaBoundary;
197
200 };
201
203 std::vector<std::unique_ptr<AreaData> > myAreas;
204
206 std::vector<SUMOTrafficObject::NumericalID> myAllStoppedTrainIDs;
207
208 std::map<const MSLane*, std::pair<JPS_StageId, JPS_StageId>, ComparatorNumericalIdLess> myCrossingWaits;
209 std::map<JPS_StageId, const MSLane*> myCrossings;
210
211 static const int GEOS_QUADRANT_SEGMENTS;
212 static const double GEOS_MITRE_LIMIT;
213 static const double GEOS_MIN_AREA;
214 static const double GEOS_BUFFERED_SEGMENT_WIDTH;
217 static const std::string PEDESTRIAN_NETWORK_ID;
219 static const std::vector<MSPModel_JuPedSim::PState*> noPedestrians;
220
221 void initialize(const OptionsCont& oc);
222 void tryPedestrianInsertion(PState* state, const Position& p);
223 bool addStage(JPS_JourneyDescription journey, JPS_StageId& predecessor, const std::string& agentID, const JPS_StageId stage);
224 bool addWaypoint(JPS_JourneyDescription journey, JPS_StageId& predecessor, const std::string& agentID, const WaypointDesc& waypoint);
225 static GEOSGeometry* createGeometryFromCenterLine(PositionVector centerLine, double width, int capStyle);
226 static GEOSGeometry* createGeometryFromShape(PositionVector shape, std::string junctionID = std::string(""), std::string shapeID = std::string(""), bool isInternalShape = false);
227 GEOSGeometry* buildPedestrianNetwork(MSNet* network);
228 static GEOSCoordSequence* convertToGEOSPoints(PositionVector shape);
229 static std::vector<JPS_Point> convertToJPSPoints(const GEOSGeometry* geometry);
230 static PositionVector convertToSUMOPoints(const GEOSGeometry* geometry);
231 static double getLinearRingArea(const GEOSGeometry* linearRing);
232 void removePolygonFromDrawing(const std::string& polygonId);
233 void preparePolygonForDrawing(const GEOSGeometry* polygon, const std::string& polygonId, const RGBColor& color);
234 static const GEOSGeometry* getLargestComponent(const GEOSGeometry* polygon, int& nbrComponents, double& maxArea, double& totalArea);
235 static JPS_Geometry buildJPSGeometryFromGEOSGeometry(const GEOSGeometry* polygon);
236 static void dumpGeometry(const GEOSGeometry* polygon, const std::string& filename, bool useGeoCoordinates = false);
237 static double getRadius(const MSVehicleType& vehType);
238 JPS_StageId addWaitingSet(const MSLane* const crossing, const bool entry);
239};
long long int SUMOTime
Definition GUI.h:36
Base (microsim) event class.
Definition Command.h:50
A road/street connecting two junctions.
Definition MSEdge.h:77
Representation of a lane in the micro simulation.
Definition MSLane.h:84
The simulated network and simulation perfomer.
Definition MSNet.h:89
The abstract superclass for pedestrian models which actually interact with vehicles.
Container for pedestrian state and individual position update function.
double myEdgePos
the advancement along the current lane
const MSLane * myLane
the current lane of this pedestrian
MSStageMoving * myStage
the current stage of this pedestrian
Position myRemoteXYPos
remote-controlled position
bool myWaitingToEnter
whether the pedestrian is waiting to start its walk
Event(MSPModel_JuPedSim *model)
MSPModel_JuPedSim * myModel
SUMOTime execute(SUMOTime currentTime) override
Executes the command.
Holds pedestrian state and performs updates.
JPS_StageId getStageId() const
first stage of the journey
JPS_AgentId getAgentId() const
void setStage(MSStageMoving *const stage)
bool isFinished() const override
whether the transportable has finished walking
void setAgentId(JPS_AgentId id)
const MSPModel_JuPedSim::WaypointDesc * getNextWaypoint(const int offset=0) const
void setLanePosition(double lanePosition)
JPS_JourneyId myJourneyId
id of the journey, needed for modifying it
std::vector< MSPModel_JuPedSim::WaypointDesc > myWaypoints
const MSEdge * getNextEdge(const MSStageMoving &stage) const override
return the list of internal edges if the transportable is on an intersection
JPS_JourneyId getJourneyId() const
void reinit(MSStageMoving *stage, JPS_JourneyId journeyId, JPS_StageId stageId, const std::vector< WaypointDesc > &waypoints)
Position getPosition(const MSStageMoving &, SUMOTime) const override
return the network coordinate of the transportable
void setPosition(const double x, const double y, const double z=0.)
A pedestrian following model that acts as a proxy for pedestrian models provided by the JuPedSim thir...
bool usingShortcuts() override
whether travel times and distances can reliably be calculated from the network alone
JPS_StageId addWaitingSet(const MSLane *const crossing, const bool entry)
OutputDevice * myPythonScript
MSTransportableStateAdapter * add(MSTransportable *person, MSStageMoving *stage, SUMOTime now) override
register the given person as a pedestrian
void removePolygonFromDrawing(const std::string &polygonId)
const GEOSGeometry * myGEOSPedestrianNetworkLargestComponent
The GEOS polygon representing the largest (by area) connected component of the pedestrian network.
void preparePolygonForDrawing(const GEOSGeometry *polygon, const std::string &polygonId, const RGBColor &color)
static const RGBColor PEDESTRIAN_NETWORK_CARRIAGES_AND_RAMPS_COLOR
static const double GEOS_MITRE_LIMIT
const double myExitTolerance
Threshold to decide if a pedestrian has ended its journey or not.
std::vector< SUMOTrafficObject::NumericalID > myAllStoppedTrainIDs
Array of stopped trains, used to detect whether to add carriages and ramps to the geometry.
bool addStage(JPS_JourneyDescription journey, JPS_StageId &predecessor, const std::string &agentID, const JPS_StageId stage)
void registerArrived(const JPS_AgentId agentID)
static GEOSGeometry * createGeometryFromCenterLine(PositionVector centerLine, double width, int capStyle)
static PositionVector convertToSUMOPoints(const GEOSGeometry *geometry)
static const std::string PEDESTRIAN_NETWORK_CARRIAGES_AND_RAMPS_ID
static const RGBColor PEDESTRIAN_NETWORK_COLOR
JPS_Geometry myJPSGeometry
The JPS polygon representing the largest connected component of the pedestrian network.
static const std::string PEDESTRIAN_NETWORK_ID
bool addWaypoint(JPS_JourneyDescription journey, JPS_StageId &predecessor, const std::string &agentID, const WaypointDesc &waypoint)
static GEOSGeometry * createGeometryFromShape(PositionVector shape, std::string junctionID=std::string(""), std::string shapeID=std::string(""), bool isInternalShape=false)
static GEOSCoordSequence * convertToGEOSPoints(PositionVector shape)
JPS_Simulation myJPSSimulation
GEOSGeometry * myGEOSPedestrianNetwork
The GEOS polygon containing all computed connected components of the pedestrian network.
static void dumpGeometry(const GEOSGeometry *polygon, const std::string &filename, bool useGeoCoordinates=false)
static std::vector< JPS_Point > convertToJPSPoints(const GEOSGeometry *geometry)
static JPS_Geometry buildJPSGeometryFromGEOSGeometry(const GEOSGeometry *polygon)
std::map< const MSLane *, std::pair< JPS_StageId, JPS_StageId >, ComparatorNumericalIdLess > myCrossingWaits
const SUMOTime myJPSDeltaT
Timestep used in the JuPedSim simulator.
MSNet *const myNetwork
The network on which the simulation runs.
std::map< JPS_StageId, const MSLane * > myCrossings
JPS_Geometry myJPSGeometryWithTrainsAndRamps
The JPS polygon representing the largest connected component plus carriages and ramps.
void polygonChanged(const SUMOPolygon *const poly, const bool added, const bool removed) override
static const double GEOS_MIN_AREA
std::tuple< JPS_StageId, Position, double > WaypointDesc
void initialize(const OptionsCont &oc)
GEOSGeometry * buildPedestrianNetwork(MSNet *network)
void remove(MSTransportableStateAdapter *state) override
remove the specified person from the pedestrian simulation
std::vector< std::unique_ptr< AreaData > > myAreas
Array of special areas.
static double getLinearRingArea(const GEOSGeometry *linearRing)
void clearState() override
Resets pedestrians when quick-loading state.
ShapeContainer & myShapeContainer
The shape container used to add polygons to the rendering pipeline.
std::vector< PState * > myPedestrianStates
JPS_OperationalModel myJPSOperationalModel
static const int GEOS_QUADRANT_SEGMENTS
static const std::vector< MSPModel_JuPedSim::PState * > noPedestrians
static const GEOSGeometry * getLargestComponent(const GEOSGeometry *polygon, int &nbrComponents, double &maxArea, double &totalArea)
static double getRadius(const MSVehicleType &vehType)
void tryPedestrianInsertion(PState *state, const Position &p)
SUMOTime execute(SUMOTime time)
static const double GEOS_BUFFERED_SEGMENT_WIDTH
abstract base class for managing callbacks to retrieve various state information from the model
Definition MSPModel.h:154
The car-following model and parameter.
A storage for options typed value containers)
Definition OptionsCont.h:89
Static storage of an output device and its base (abstract) implementation.
std::map< std::string, std::string > Map
parameters map
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.
Storage for geometrical objects.
Interface for objects which want to be notified about shape updates.
Function-object for stable sorting of objects with numerical ids.
Definition Named.h:38
Structure that keeps data related to vanishing areas (and other types of areas).
const Parameterised::Map & params
SUMOTime lastRemovalTime
The last time a pedestrian was removed in a vanishing area.
const std::vector< JPS_Point > areaBoundary