Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSPModel_JuPedSim_legacy.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 old implementation of the JuPedSim coupling.
22// This is only being kept for reference and will probably be removed soon.
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:
53
55 void remove(MSTransportableStateAdapter* state) override;
57
58 bool usingShortcuts() override {
60 }
62 bool usingDoors() override {
63 return true;
64 }
65
66 void registerArrived(const JPS_AgentId agentID);
67 void clearState() override;
68
69 class Event : public Command {
70 public:
72 : myModel(model) { }
73 SUMOTime execute(SUMOTime currentTime) override {
74 return myModel->execute(currentTime);
75 }
76
77 private:
79 };
80
87
88 typedef std::tuple<JPS_StageId, Position, double> WaypointDesc;
89
90 void polygonChanged(const SUMOPolygon* const poly, const bool added, const bool removed) override;
91
92private:
98 public:
99 PState(MSPerson* person, MSStageMoving* stage, JPS_JourneyId journeyId, JPS_StageId stageId, const std::vector<WaypointDesc>& waypoints);
100 ~PState() override;
101
102 void reinit(MSStageMoving* stage, JPS_JourneyId journeyId, JPS_StageId stageId, const std::vector<WaypointDesc>& waypoints);
103
104 inline Position getPosition(const MSStageMoving&, SUMOTime) const override {
105 return myRemoteXYPos;
106 }
107 void setPosition(const double x, const double y, const double z = 0.);
108
109 inline void setAngle(double angle) {
110 myAngle = angle;
111 }
112
113 inline void setStage(MSStageMoving* const stage) {
114 myStage = stage;
115 }
116
117 inline void setLane(MSLane* lane) {
118 myLane = lane;
119 }
120
121 inline void setLanePosition(double lanePosition) {
122 myEdgePos = lanePosition;
123 }
124 const MSEdge* getNextEdge(const MSStageMoving& stage) const override;
125
126 const MSPModel_JuPedSim_legacy::WaypointDesc* getNextWaypoint(const int offset = 0) const;
127
128 inline JPS_AgentId getAgentId() const {
129 return myAgentId;
130 }
131
132 void setAgentId(JPS_AgentId id) {
133 myAgentId = id;
134 myWaitingToEnter = false;
135 }
136
138 bool isFinished() const override {
139 return myWaypoints.empty();
140 }
141
142 JPS_JourneyId getJourneyId() const {
143 return myJourneyId;
144 }
145
147 JPS_StageId getStageId() const {
148 return myStageId;
149 }
150
152 myWaypoints.erase(myWaypoints.begin());
153 return myWaypoints.empty();
154 }
155
156 private:
158 JPS_JourneyId myJourneyId;
159 JPS_StageId myStageId;
160 std::vector<MSPModel_JuPedSim_legacy::WaypointDesc> myWaypoints;
161 JPS_AgentId myAgentId;
162 };
163
166
169
172
175
177 const double myExitTolerance;
178
179 std::vector<PState*> myPedestrianStates;
180
182 GEOSGeometry* myGEOSPedestrianNetwork; // Kept because the largest component refers to it.
183
186
188
190 JPS_Geometry myJPSGeometry = nullptr; // Kept because of dynamic geometry switching and JPS_Simulation object.
191
193 JPS_Geometry myJPSGeometryWithTrainsAndRamps = nullptr;
195 JPS_OperationalModel myJPSOperationalModel = nullptr;
196 JPS_Simulation myJPSSimulation;
198
200 struct AreaData {
201 const std::string id;
202 const std::string areaType;
203 const std::vector<JPS_Point> areaBoundary;
205
208 };
209
211 std::vector<std::unique_ptr<AreaData> > myAreas;
212
214 std::vector<SUMOTrafficObject::NumericalID> myAllStoppedTrainIDs;
215
216 std::map<const MSLane*, std::pair<JPS_StageId, JPS_StageId>, ComparatorNumericalIdLess> myCrossingWaits;
217 std::map<JPS_StageId, const MSLane*> myCrossings;
218
219 static const int GEOS_QUADRANT_SEGMENTS;
220 static const double GEOS_MITRE_LIMIT;
221 static const double GEOS_MIN_AREA;
222 static const double GEOS_BUFFERED_SEGMENT_WIDTH;
225 static const std::string PEDESTRIAN_NETWORK_ID;
227 static const std::vector<MSPModel_JuPedSim_legacy::PState*> noPedestrians;
228
229 void initialize(const OptionsCont& oc);
230 void tryPedestrianInsertion(PState* state, const Position& p);
231 bool addStage(JPS_JourneyDescription journey, JPS_StageId& predecessor, const std::string& agentID, const JPS_StageId stage);
232 bool addWaypoint(JPS_JourneyDescription journey, JPS_StageId& predecessor, const std::string& agentID, const WaypointDesc& waypoint);
233 static GEOSGeometry* createGeometryFromCenterLine(PositionVector centerLine, double width, int capStyle);
234 static GEOSGeometry* createGeometryFromShape(PositionVector shape, std::string junctionID = std::string(""), std::string shapeID = std::string(""), bool isInternalShape = false);
235 GEOSGeometry* buildPedestrianNetwork(MSNet* network);
236 static GEOSCoordSequence* convertToGEOSPoints(PositionVector shape);
237 static std::vector<JPS_Point> convertToJPSPoints(const GEOSGeometry* geometry);
238 static PositionVector convertToSUMOPoints(const GEOSGeometry* geometry);
239 static double getLinearRingArea(const GEOSGeometry* linearRing);
240 void removePolygonFromDrawing(const std::string& polygonId);
241 void preparePolygonForDrawing(const GEOSGeometry* polygon, const std::string& polygonId, const RGBColor& color);
242 static const GEOSGeometry* getLargestComponent(const GEOSGeometry* polygon, int& nbrComponents, double& maxArea, double& totalArea);
243 static JPS_Geometry buildJPSGeometryFromGEOSGeometry(const GEOSGeometry* polygon);
244 static void dumpGeometry(const GEOSGeometry* polygon, const std::string& filename, bool useGeoCoordinates = false);
245 static double getRadius(const MSVehicleType& vehType);
246 JPS_StageId addWaitingSet(const MSLane* const crossing, const bool entry);
247};
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:78
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_legacy *model)
SUMOTime execute(SUMOTime currentTime) override
Executes the command.
Holds pedestrian state and performs updates.
bool isFinished() const override
whether the transportable has finished walking
void reinit(MSStageMoving *stage, JPS_JourneyId journeyId, JPS_StageId stageId, const std::vector< WaypointDesc > &waypoints)
const MSPModel_JuPedSim_legacy::WaypointDesc * getNextWaypoint(const int offset=0) const
const MSEdge * getNextEdge(const MSStageMoving &stage) const override
return the list of internal edges if the transportable is on an intersection
void setStage(MSStageMoving *const stage)
JPS_JourneyId myJourneyId
id of the journey, needed for modifying it
void setPosition(const double x, const double y, const double z=0.)
JPS_StageId getStageId() const
first stage of the journey
Position getPosition(const MSStageMoving &, SUMOTime) const override
return the network coordinate of the transportable
std::vector< MSPModel_JuPedSim_legacy::WaypointDesc > myWaypoints
A pedestrian following model that acts as a proxy for pedestrian models provided by the JuPedSim thir...
bool usingDoors() override
precise lateral positioning when leaving trains is supported by JuPedSim
void polygonChanged(const SUMOPolygon *const poly, const bool added, const bool removed) override
JPS_Geometry myJPSGeometryWithTrainsAndRamps
The JPS polygon representing the largest connected component plus carriages and ramps.
JPS_Geometry myJPSGeometry
The JPS polygon representing the largest connected component of the pedestrian network.
bool usingShortcuts() override
whether travel times and distances can reliably be calculated from the network alone
static const RGBColor PEDESTRIAN_NETWORK_CARRIAGES_AND_RAMPS_COLOR
void initialize(const OptionsCont &oc)
void clearState() override
Resets pedestrians when quick-loading state.
static JPS_Geometry buildJPSGeometryFromGEOSGeometry(const GEOSGeometry *polygon)
static GEOSCoordSequence * convertToGEOSPoints(PositionVector shape)
static PositionVector convertToSUMOPoints(const GEOSGeometry *geometry)
static double getRadius(const MSVehicleType &vehType)
static const double GEOS_BUFFERED_SEGMENT_WIDTH
GEOSGeometry * buildPedestrianNetwork(MSNet *network)
void registerArrived(const JPS_AgentId agentID)
static void dumpGeometry(const GEOSGeometry *polygon, const std::string &filename, bool useGeoCoordinates=false)
void preparePolygonForDrawing(const GEOSGeometry *polygon, const std::string &polygonId, const RGBColor &color)
std::map< const MSLane *, std::pair< JPS_StageId, JPS_StageId >, ComparatorNumericalIdLess > myCrossingWaits
const SUMOTime myJPSDeltaT
Timestep used in the JuPedSim simulator.
bool addWaypoint(JPS_JourneyDescription journey, JPS_StageId &predecessor, const std::string &agentID, const WaypointDesc &waypoint)
GEOSGeometry * myGEOSPedestrianNetwork
The GEOS polygon containing all computed connected components of the pedestrian network.
JPS_StageId addWaitingSet(const MSLane *const crossing, const bool entry)
MSNet *const myNetwork
The network on which the simulation runs.
void removePolygonFromDrawing(const std::string &polygonId)
JPS_OperationalModel myJPSOperationalModel
static const GEOSGeometry * getLargestComponent(const GEOSGeometry *polygon, int &nbrComponents, double &maxArea, double &totalArea)
static const std::vector< MSPModel_JuPedSim_legacy::PState * > noPedestrians
void tryPedestrianInsertion(PState *state, const Position &p)
static GEOSGeometry * createGeometryFromCenterLine(PositionVector centerLine, double width, int capStyle)
MSTransportableStateAdapter * add(MSTransportable *person, MSStageMoving *stage, SUMOTime now) override
register the given person as a pedestrian
static std::vector< JPS_Point > convertToJPSPoints(const GEOSGeometry *geometry)
ShapeContainer & myShapeContainer
The shape container used to add polygons to the rendering pipeline.
std::vector< std::unique_ptr< AreaData > > myAreas
Array of special areas.
void remove(MSTransportableStateAdapter *state) override
remove the specified person from the pedestrian simulation
bool addStage(JPS_JourneyDescription journey, JPS_StageId &predecessor, const std::string &agentID, const JPS_StageId stage)
static double getLinearRingArea(const GEOSGeometry *linearRing)
std::vector< SUMOTrafficObject::NumericalID > myAllStoppedTrainIDs
Array of stopped trains, used to detect whether to add carriages and ramps to the geometry.
static const std::string PEDESTRIAN_NETWORK_CARRIAGES_AND_RAMPS_ID
static GEOSGeometry * createGeometryFromShape(PositionVector shape, std::string junctionID=std::string(""), std::string shapeID=std::string(""), bool isInternalShape=false)
std::vector< PState * > myPedestrianStates
SumoRNG myRNG
The random number generator for fluctuations on insertion.
static const std::string PEDESTRIAN_NETWORK_ID
const double myExitTolerance
Threshold to decide if a pedestrian has ended its journey or not.
std::map< JPS_StageId, const MSLane * > myCrossings
const GEOSGeometry * myGEOSPedestrianNetworkLargestComponent
The GEOS polygon representing the largest (by area) connected component of the pedestrian network.
static const RGBColor PEDESTRIAN_NETWORK_COLOR
std::tuple< JPS_StageId, Position, double > WaypointDesc
abstract base class for managing callbacks to retrieve various state information from the model
Definition MSPModel.h:159
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).
SUMOTime lastRemovalTime
The last time a pedestrian was removed in a vanishing area.
const std::vector< JPS_Point > areaBoundary