Eclipse SUMO - Simulation of Urban MObility
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-2024 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>
30 #include "microsim/MSNet.h"
31 #include "MSPModel.h"
32 
33 
34 // ===========================================================================
35 // class definitions
36 // ===========================================================================
42 class MSPModel_JuPedSim : public MSPModel {
43 public:
44  MSPModel_JuPedSim(const OptionsCont& oc, MSNet* net);
46 
48  void remove(MSTransportableStateAdapter* state) override;
50 
51  bool usingInternalLanes() override;
52  bool usingShortcuts() override {
54  }
55  void registerArrived();
56  int getActiveNumber() override;
57  void clearState() override;
58 
59  class Event : public Command {
60  public:
61  explicit Event(MSPModel_JuPedSim* model)
62  : myJPSModel(model) { }
63  SUMOTime execute(SUMOTime currentTime) override {
64  return myJPSModel->execute(currentTime);
65  }
66 
67  private:
69  };
70 
71 private:
77  public:
78  PState(MSPerson* person, MSStageMoving* stage, JPS_JourneyId journeyId, JPS_StageId stageId, const std::vector<std::pair<Position, double> >& waypoints);
79  ~PState() override;
80 
81  void reinit(MSStageMoving* stage, JPS_JourneyId journeyId, JPS_StageId stageId, const std::vector<std::pair<Position, double> >& waypoints);
82 
83  Position getPosition(const MSStageMoving& stage, SUMOTime now) const override;
84  void setPosition(double x, double y);
85 
87  void setPreviousPosition(Position previousPosition);
88 
89  double getAngle(const MSStageMoving& stage, SUMOTime now) const override;
90  void setAngle(double angle);
91 
92  MSStageMoving* getStage() const;
93  void setStage(MSStageMoving* const stage);
94 
95  MSPerson* getPerson() const;
96 
97  void setLanePosition(double lanePosition);
98  double getEdgePos(const MSStageMoving& stage, SUMOTime now) const override;
99  int getDirection(const MSStageMoving& stage, SUMOTime now) const override;
100  SUMOTime getWaitingTime(const MSStageMoving& stage, SUMOTime now) const override;
101  double getSpeed(const MSStageMoving& stage) const override;
102  const MSEdge* getNextEdge(const MSStageMoving& stage) const override;
103  const std::pair<Position, double>& getNextWaypoint() const;
104  JPS_AgentId getAgentId() const;
105 
107  bool isFinished() const override {
108  return myWaypoints.empty();
109  }
110 
111  void setAgentId(JPS_AgentId id) {
112  myAgentId = id;
113  myWaitingToEnter = false;
114  }
115 
116  JPS_JourneyId getJourneyId() const {
117  return myJourneyId;
118  }
119 
121  JPS_StageId getStageId() const {
122  return myStageId;
123  }
124 
125  bool isWaitingToEnter() const {
126  return myWaitingToEnter;
127  }
128 
130  myWaypoints.erase(myWaypoints.begin());
131  return myWaypoints.empty();
132  }
133 
134  private:
138  JPS_JourneyId myJourneyId;
139  JPS_StageId myStageId;
140  std::vector<std::pair<Position, double> > myWaypoints;
141  JPS_AgentId myAgentId;
143  Position myPreviousPosition; // Will be initialized to zero automatically.
144  double myAngle;
148  };
149 
151  MSNet* const myNetwork;
152 
155 
158 
160  const double myExitTolerance;
161 
163  std::vector<PState*> myPedestrianStates;
164 
166  GEOSGeometry* myGEOSPedestrianNetwork; // Kept because the largest component refers to it.
167 
170 
172 
174  JPS_Geometry myJPSGeometry; // Kept because of dynamic geometry switching and JPS_Simulation object.
175 
178  JPS_OperationalModel myJPSModel;
179  JPS_Simulation myJPSSimulation;
180 
182  struct AreaData {
183  const std::string id;
184  const std::string areaType;
185  const std::vector<JPS_Point> areaBoundary;
187 
190  };
191 
193  std::vector<AreaData> myAreas;
194 
196  std::vector<SUMOTrafficObject::NumericalID> myAllStoppedTrainIDs;
197 
198  static const int GEOS_QUADRANT_SEGMENTS;
199  static const double GEOS_MITRE_LIMIT;
200  static const double GEOS_MIN_AREA;
201  static const double GEOS_BUFFERED_SEGMENT_WIDTH;
202  static const double CARRIAGE_RAMP_LENGTH;
205  static const std::string PEDESTRIAN_NETWORK_ID;
207 
208  void initialize(const OptionsCont& oc);
209  void tryPedestrianInsertion(PState* state, const Position& p);
210  bool addWaypoint(JPS_JourneyDescription journey, JPS_StageId& predecessor, const Position& point, const std::string& agentID, const double radius);
211  static MSLane* getNextPedestrianLane(const MSLane* const currentLane);
212  static const Position& getAnchor(const MSLane* const lane, const MSEdge* const edge, MSEdgeVector incoming);
213  static const MSEdgeVector getAdjacentEdgesOfEdge(const MSEdge* const edge);
214  static const MSEdge* getWalkingAreaInbetween(const MSEdge* const edge, const MSEdge* const otherEdge);
215  static GEOSGeometry* createGeometryFromCenterLine(PositionVector centerLine, double width, int capStyle);
216  static GEOSGeometry* createGeometryFromShape(PositionVector shape, std::string junctionID = std::string(""), std::string shapeID = std::string(""), bool isInternalShape = false);
217  static GEOSGeometry* createGeometryFromAnchors(const Position& anchor, const MSLane* const lane, const Position& otherAnchor, const MSLane* const otherLane);
218  GEOSGeometry* buildPedestrianNetwork(MSNet* network);
219  static GEOSCoordSequence* convertToGEOSPoints(PositionVector shape);
220  static std::vector<JPS_Point> convertToJPSPoints(const GEOSGeometry* geometry);
221  static PositionVector convertToSUMOPoints(const GEOSGeometry* geometry);
222  static double getLinearRingArea(const GEOSGeometry* linearRing);
223  void removePolygonFromDrawing(const std::string& polygonId);
224  void preparePolygonForDrawing(const GEOSGeometry* polygon, const std::string& polygonId, const RGBColor& color);
225  static const GEOSGeometry* getLargestComponent(const GEOSGeometry* polygon, int& nbrComponents, double& maxArea, double& totalArea);
226  static JPS_Geometry buildJPSGeometryFromGEOSGeometry(const GEOSGeometry* polygon);
227  static void dumpGeometry(const GEOSGeometry* polygon, const std::string& filename, bool useGeoCoordinates = false);
228  static double getRadius(const MSVehicleType& vehType);
229 };
long long int SUMOTime
Definition: GUI.h:35
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:73
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
Event(MSPModel_JuPedSim *model)
SUMOTime execute(SUMOTime currentTime) override
Executes the command.
MSPModel_JuPedSim * myJPSModel
Holds pedestrian state and performs updates.
JPS_StageId getStageId() const
first stage of the journey
std::vector< std::pair< Position, double > > myWaypoints
void setPosition(double x, double y)
JPS_AgentId getAgentId() const
void setStage(MSStageMoving *const stage)
SUMOTime getWaitingTime(const MSStageMoving &stage, SUMOTime now) const override
return the time the transportable spent standing
void reinit(MSStageMoving *stage, JPS_JourneyId journeyId, JPS_StageId stageId, const std::vector< std::pair< Position, double > > &waypoints)
PState(MSPerson *person, MSStageMoving *stage, JPS_JourneyId journeyId, JPS_StageId stageId, const std::vector< std::pair< Position, double > > &waypoints)
bool isFinished() const override
whether the transportable has finished walking
double getEdgePos(const MSStageMoving &stage, SUMOTime now) const override
return the offset from the start of the current edge measured in its natural direction
const std::pair< Position, double > & getNextWaypoint() const
double getSpeed(const MSStageMoving &stage) const override
return the current speed of the transportable
void setAgentId(JPS_AgentId id)
void setPreviousPosition(Position previousPosition)
void setLanePosition(double lanePosition)
JPS_JourneyId myJourneyId
id of the journey, needed for modifying it
const MSEdge * getNextEdge(const MSStageMoving &stage) const override
return the list of internal edges if the transportable is on an intersection
int getDirection(const MSStageMoving &stage, SUMOTime now) const override
return the walking direction (FORWARD, BACKWARD)
JPS_JourneyId getJourneyId() const
Position getPreviousPosition() const
Position getPosition(const MSStageMoving &stage, SUMOTime now) const override
return the network coordinate of the transportable
double getAngle(const MSStageMoving &stage, SUMOTime now) const override
return the direction in which the transportable faces in degrees
bool myWaitingToEnter
whether the pedestrian is waiting to start its walk
MSStageMoving * getStage() const
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
MSTransportableStateAdapter * add(MSTransportable *person, MSStageMoving *stage, SUMOTime now) override
register the given person as a pedestrian
void removePolygonFromDrawing(const std::string &polygonId)
JPS_OperationalModel myJPSModel
bool addWaypoint(JPS_JourneyDescription journey, JPS_StageId &predecessor, const Position &point, const std::string &agentID, const double radius)
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
MSPModel_JuPedSim(const OptionsCont &oc, MSNet *net)
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.
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
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)
std::vector< AreaData > myAreas
Array of special areas.
static MSLane * getNextPedestrianLane(const MSLane *const currentLane)
static std::vector< JPS_Point > convertToJPSPoints(const GEOSGeometry *geometry)
static JPS_Geometry buildJPSGeometryFromGEOSGeometry(const GEOSGeometry *polygon)
const SUMOTime myJPSDeltaT
Timestep used in the JuPedSim simulator.
MSNet *const myNetwork
The network on which the simulation runs.
JPS_Geometry myJPSGeometryWithTrainsAndRamps
The JPS polygon representing the largest connected component plus carriages and ramps.
static const double CARRIAGE_RAMP_LENGTH
static const double GEOS_MIN_AREA
void initialize(const OptionsCont &oc)
GEOSGeometry * buildPedestrianNetwork(MSNet *network)
void remove(MSTransportableStateAdapter *state) override
remove the specified person from the pedestrian simulation
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.
static const Position & getAnchor(const MSLane *const lane, const MSEdge *const edge, MSEdgeVector incoming)
static const MSEdge * getWalkingAreaInbetween(const MSEdge *const edge, const MSEdge *const otherEdge)
std::vector< PState * > myPedestrianStates
static const int GEOS_QUADRANT_SEGMENTS
static const GEOSGeometry * getLargestComponent(const GEOSGeometry *polygon, int &nbrComponents, double &maxArea, double &totalArea)
static const MSEdgeVector getAdjacentEdgesOfEdge(const MSEdge *const edge)
static double getRadius(const MSVehicleType &vehType)
static GEOSGeometry * createGeometryFromAnchors(const Position &anchor, const MSLane *const lane, const Position &otherAnchor, const MSLane *const otherLane)
void tryPedestrianInsertion(PState *state, const Position &p)
SUMOTime execute(SUMOTime time)
static const double GEOS_BUFFERED_SEGMENT_WIDTH
int getActiveNumber() override
return the number of active objects
bool usingInternalLanes() override
whether movements on intersections are modelled
The pedestrian (and also sometimes container) movement model.
Definition: MSPModel.h:51
abstract base class for managing callbacks to retrieve various state information from the model
Definition: MSPModel.h:156
The car-following model and parameter.
Definition: MSVehicleType.h:63
A storage for options typed value containers)
Definition: OptionsCont.h:89
std::map< std::string, std::string > Map
parameters map
Definition: Parameterised.h:45
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
A list of positions.
Storage for geometrical objects.
Structure that keeps data related to vanishing areas (and other types of areas).
SUMOTime lastRemovalTime
The last time a pedestrian was removed in a vanishing area.
const Parameterised::Map params
const std::vector< JPS_Point > areaBoundary