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_Interacting.h"
32 
33 
34 // ===========================================================================
35 // class declarations
36 // ===========================================================================
37 class OutputDevice;
38 
39 
40 // ===========================================================================
41 // class definitions
42 // ===========================================================================
49 public:
50  MSPModel_JuPedSim(const OptionsCont& oc, MSNet* net);
52 
54  void remove(MSTransportableStateAdapter* state) override;
56 
57  bool usingShortcuts() override {
59  }
60  void registerArrived(const JPS_AgentId agentID);
61  void clearState() override;
62 
63  class Event : public Command {
64  public:
65  explicit Event(MSPModel_JuPedSim* model)
66  : myModel(model) { }
67  SUMOTime execute(SUMOTime currentTime) override {
68  return myModel->execute(currentTime);
69  }
70 
71  private:
73  };
74 
75  enum class JPS_Model {
80  };
81 
82  typedef std::tuple<JPS_StageId, Position, double> WaypointDesc;
83 private:
89  public:
90  PState(MSPerson* person, MSStageMoving* stage, JPS_JourneyId journeyId, JPS_StageId stageId, const std::vector<WaypointDesc>& waypoints);
91  ~PState() override;
92 
93  void reinit(MSStageMoving* stage, JPS_JourneyId journeyId, JPS_StageId stageId, const std::vector<WaypointDesc>& waypoints);
94 
95  inline Position getPosition(const MSStageMoving&, SUMOTime) const override {
96  return myRemoteXYPos;
97  }
98  void setPosition(double x, double y);
99 
100  inline void setAngle(double angle) {
101  myAngle = angle;
102  }
103 
104  inline void setStage(MSStageMoving* const stage) {
105  myStage = stage;
106  }
107 
108  inline void setLane(MSLane* lane) {
109  myLane = lane;
110  }
111 
112  inline void setLanePosition(double lanePosition) {
113  myEdgePos = lanePosition;
114  }
115  const MSEdge* getNextEdge(const MSStageMoving& stage) const override;
116 
117  const MSPModel_JuPedSim::WaypointDesc* getNextWaypoint(const int offset = 0) const;
118 
119  inline JPS_AgentId getAgentId() const {
120  return myAgentId;
121  }
122 
123  void setAgentId(JPS_AgentId id) {
124  myAgentId = id;
125  myWaitingToEnter = false;
126  }
127 
129  bool isFinished() const override {
130  return myWaypoints.empty();
131  }
132 
133  JPS_JourneyId getJourneyId() const {
134  return myJourneyId;
135  }
136 
138  JPS_StageId getStageId() const {
139  return myStageId;
140  }
141 
143  myWaypoints.erase(myWaypoints.begin());
144  return myWaypoints.empty();
145  }
146 
147  private:
149  JPS_JourneyId myJourneyId;
150  JPS_StageId myStageId;
151  std::vector<MSPModel_JuPedSim::WaypointDesc> myWaypoints;
152  JPS_AgentId myAgentId;
153  };
154 
156  MSNet* const myNetwork;
157 
160 
163 
165  const double myExitTolerance;
166 
167  std::vector<PState*> myPedestrianStates;
168 
170  GEOSGeometry* myGEOSPedestrianNetwork; // Kept because the largest component refers to it.
171 
174 
176 
178  JPS_Geometry myJPSGeometry; // Kept because of dynamic geometry switching and JPS_Simulation object.
179 
183  JPS_OperationalModel myJPSOperationalModel;
184  JPS_Simulation myJPSSimulation;
186 
188  struct AreaData {
189  const std::string id;
190  const std::string areaType;
191  const std::vector<JPS_Point> areaBoundary;
193 
196  };
197 
199  std::vector<AreaData> myAreas;
200 
202  std::vector<SUMOTrafficObject::NumericalID> myAllStoppedTrainIDs;
203 
204  std::map<const MSLane*, std::pair<JPS_StageId, JPS_StageId> > myCrossingWaits;
205  std::map<JPS_StageId, const MSLane*> myCrossings;
206 
207  static const int GEOS_QUADRANT_SEGMENTS;
208  static const double GEOS_MITRE_LIMIT;
209  static const double GEOS_MIN_AREA;
210  static const double GEOS_BUFFERED_SEGMENT_WIDTH;
211  static const double CARRIAGE_RAMP_LENGTH;
214  static const std::string PEDESTRIAN_NETWORK_ID;
216  static const std::vector<MSPModel_JuPedSim::PState*> noPedestrians;
217 
218  void initialize(const OptionsCont& oc);
219  void tryPedestrianInsertion(PState* state, const Position& p);
220  bool addStage(JPS_JourneyDescription journey, JPS_StageId& predecessor, const std::string& agentID, const JPS_StageId stage);
221  bool addWaypoint(JPS_JourneyDescription journey, JPS_StageId& predecessor, const std::string& agentID, const WaypointDesc& waypoint);
222  static GEOSGeometry* createGeometryFromCenterLine(PositionVector centerLine, double width, int capStyle);
223  static GEOSGeometry* createGeometryFromShape(PositionVector shape, std::string junctionID = std::string(""), std::string shapeID = std::string(""), bool isInternalShape = false);
224  GEOSGeometry* buildPedestrianNetwork(MSNet* network);
225  static GEOSCoordSequence* convertToGEOSPoints(PositionVector shape);
226  static std::vector<JPS_Point> convertToJPSPoints(const GEOSGeometry* geometry);
227  static PositionVector convertToSUMOPoints(const GEOSGeometry* geometry);
228  static double getLinearRingArea(const GEOSGeometry* linearRing);
229  void removePolygonFromDrawing(const std::string& polygonId);
230  void preparePolygonForDrawing(const GEOSGeometry* polygon, const std::string& polygonId, const RGBColor& color);
231  static const GEOSGeometry* getLargestComponent(const GEOSGeometry* polygon, int& nbrComponents, double& maxArea, double& totalArea);
232  static JPS_Geometry buildJPSGeometryFromGEOSGeometry(const GEOSGeometry* polygon);
233  static void dumpGeometry(const GEOSGeometry* polygon, const std::string& filename, bool useGeoCoordinates = false);
234  static double getRadius(const MSVehicleType& vehType);
235  JPS_StageId addWaitingSet(const MSLane* const crossing, const bool entry);
236 };
long long int SUMOTime
Definition: GUI.h:35
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
void setPosition(double x, double y)
void setAngle(double angle)
void setLane(MSLane *lane)
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
PState(MSPerson *person, MSStageMoving *stage, JPS_JourneyId journeyId, JPS_StageId stageId, const std::vector< WaypointDesc > &waypoints)
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
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
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.
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)
std::vector< AreaData > myAreas
Array of special areas.
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.
std::map< JPS_StageId, const MSLane * > myCrossings
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
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
static double getLinearRingArea(const GEOSGeometry *linearRing)
std::map< const MSLane *, std::pair< JPS_StageId, JPS_StageId > > myCrossingWaits
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.
Definition: MSVehicleType.h:63
A storage for options typed value containers)
Definition: OptionsCont.h:89
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
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