Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-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 : /****************************************************************************/
14 : /// @file MSPerson.h
15 : /// @author Daniel Krajzewicz
16 : /// @author Jakob Erdmann
17 : /// @author Sascha Krieg
18 : /// @author Michael Behrisch
19 : /// @date Mon, 9 Jul 2001
20 : ///
21 : // The class for modelling person-movements
22 : /****************************************************************************/
23 : #pragma once
24 : #include <config.h>
25 :
26 : #include <string>
27 : #include <vector>
28 : #include <set>
29 : #include <utils/common/SUMOTime.h>
30 : #include <utils/common/Command.h>
31 : #include <utils/geom/Position.h>
32 : #include <utils/geom/PositionVector.h>
33 : #include <microsim/transportables/MSTransportable.h>
34 : #include <microsim/transportables/MSStageMoving.h>
35 :
36 :
37 : // ===========================================================================
38 : // class declarations
39 : // ===========================================================================
40 : class MSNet;
41 : class MSEdge;
42 : class MSLane;
43 : class OutputDevice;
44 : class SUMOVehicleParameter;
45 : class MSStoppingPlace;
46 : class SUMOVehicle;
47 : class MSVehicleType;
48 : class MSPModel;
49 : class MSMoveReminder;
50 :
51 : typedef std::vector<const MSEdge*> ConstMSEdgeVector;
52 :
53 : // ===========================================================================
54 : // class definitions
55 : // ===========================================================================
56 : /**
57 : * @class MSPerson
58 : *
59 : * The class holds a simulated person together with her movement stages
60 : */
61 : class MSPerson : public MSTransportable {
62 : public:
63 : /**
64 : * An intermediate stage performing the access from or to public transport as given
65 : * by the access elements of the public transport stop. The travel time is computed by the simulation
66 : */
67 : class MSPersonStage_Access : public MSStage {
68 : public:
69 : /// constructor
70 : MSPersonStage_Access(const MSEdge* destination, MSStoppingPlace* toStop,
71 : const double arrivalPos, const double arrivalPosLat, const double dist, const bool isExit,
72 : const Position& startPos, const Position& endPos);
73 :
74 : /// destructor
75 : ~MSPersonStage_Access();
76 :
77 : MSStage* clone() const;
78 :
79 : /// proceeds to the next step
80 : virtual void proceed(MSNet* net, MSTransportable* person, SUMOTime now, MSStage* previous);
81 :
82 : /// @brief returns the stage description as a string
83 : std::string getStageDescription(const bool isPerson) const;
84 : std::string getStageSummary(const bool isPerson) const;
85 :
86 : Position getPosition(SUMOTime now) const;
87 :
88 : double getAngle(SUMOTime now) const;
89 :
90 : /// @brief get travel distance in this stage
91 0 : double getDistance() const {
92 0 : return myDist;
93 : }
94 :
95 : /// @brief the speed of the person in this stage
96 : double getSpeed() const;
97 :
98 : /** @brief Called on writing tripinfo output
99 : *
100 : * @param[in] os The stream to write the information into
101 : * @param[in] transportable The person to write information about
102 : * @exception IOError not yet implemented
103 : */
104 : void tripInfoOutput(OutputDevice& os, const MSTransportable* const transportable) const;
105 :
106 : /// @brief Called on writing vehroute output. Currently does nothing.
107 328 : void routeOutput(const bool /*isPerson*/, OutputDevice& /*os*/, const bool /*withRouteLength*/, const MSStage* const /*previous*/, const bool /*withTiming*/, const bool /*saveState*/ = false) const {};
108 :
109 : /** @brief Saves the current state into the given stream
110 : */
111 : void saveState(std::ostringstream& out, MSTransportable* transportable);
112 :
113 : /** @brief Reconstructs the current state
114 : */
115 : void loadState(MSTransportable* person, std::istringstream& state);
116 :
117 : private:
118 : class ProceedCmd : public Command {
119 : public:
120 4269 : ProceedCmd(MSTransportable* person, MSEdge* edge) : myPerson(person), myStopEdge(edge) {}
121 4269 : ~ProceedCmd() {}
122 : SUMOTime execute(SUMOTime currentTime);
123 : private:
124 : MSTransportable* const myPerson;
125 : MSEdge* myStopEdge;
126 : private:
127 : /// @brief Invalidated assignment operator.
128 : ProceedCmd& operator=(const ProceedCmd&);
129 : };
130 :
131 : private:
132 : /// the origin edge
133 : const MSEdge* myOrigin;
134 : const double myDist;
135 : const bool myAmExit;
136 : SUMOTime myEstimatedArrival;
137 : PositionVector myPath;
138 : };
139 :
140 : public:
141 : /// constructor
142 : MSPerson(const SUMOVehicleParameter* pars, MSVehicleType* vtype, MSTransportable::MSTransportablePlan* plan, const double speedFactor);
143 :
144 : /// destructor
145 : virtual ~MSPerson();
146 :
147 : /* @brief check whether an access stage must be added and return whether a
148 : * stage was added */
149 : bool checkAccess(const MSStage* const prior, const bool waitAtStop = true);
150 :
151 : /// @brief return the list of internal edges if this person is walking and the pedestrian model allows it
152 : const std::string& getNextEdge() const;
153 :
154 : /// @brief returns the next edge ptr if this person is walking and the pedestrian model allows it
155 : const MSEdge* getNextEdgePtr() const;
156 :
157 : /// @brief whether this person is selected in the GUI
158 6436993198 : virtual bool isSelected() const {
159 6436993198 : return false;
160 : }
161 :
162 196537820 : inline double getChosenSpeedFactor() const {
163 196537820 : return myChosenSpeedFactor;
164 : }
165 :
166 : inline void setChosenSpeedFactor(const double factor) {
167 30 : myChosenSpeedFactor = factor;
168 : }
169 :
170 : double getImpatience() const;
171 :
172 : /// @brief whether the person is jammed as defined by the current pedestrian model
173 : bool isJammed() const;
174 :
175 : /// @brief set new walk and replace the stages with relative indices in the interval [firstIndex, nextIndex[
176 : void replaceWalk(const ConstMSEdgeVector& newEdges, double departPos, int firstIndex, int nextIndex);
177 :
178 : inline double getTimegapCrossing() const {
179 51419925 : return myTimegapCrossing;
180 : }
181 :
182 : /** @class Influencer
183 : * @brief Changes the wished person speed and position
184 : *
185 : * The class is used for passing velocities or positions obtained via TraCI to the person.
186 : */
187 : class Influencer {
188 : public:
189 : /// @brief Constructor
190 : Influencer();
191 :
192 :
193 : /// @brief Destructor
194 : ~Influencer();
195 :
196 :
197 : void setRemoteControlled(Position xyPos, MSLane* l, double pos, double posLat, double angle, int edgeOffset, const ConstMSEdgeVector& route, SUMOTime t);
198 :
199 : SUMOTime getLastAccessTimeStep() const {
200 : return myLastRemoteAccess;
201 : }
202 :
203 : void postProcessRemoteControl(MSPerson* p);
204 :
205 : bool isRemoteControlled() const;
206 :
207 : bool isRemoteAffected(SUMOTime t) const;
208 :
209 : private:
210 : Position myRemoteXYPos;
211 : MSLane* myRemoteLane;
212 : double myRemotePos;
213 : double myRemotePosLat;
214 : double myRemoteAngle;
215 : int myRemoteEdgeOffset;
216 : ConstMSEdgeVector myRemoteRoute;
217 : SUMOTime myLastRemoteAccess;
218 : };
219 :
220 :
221 : /** @brief Returns the velocity/lane influencer
222 : *
223 : * If no influencer was existing before, one is built, first
224 : * @return Reference to this vehicle's speed influencer
225 : */
226 : Influencer& getInfluencer();
227 :
228 : const Influencer* getInfluencer() const;
229 :
230 100248848 : bool hasInfluencer() const {
231 100248848 : return myInfluencer != 0;
232 : }
233 :
234 : /// @brief sets position outside the road network
235 : void setRemoteState(Position xyPos);
236 :
237 : private:
238 : /// @brief An instance of a speed/position influencing instance; built in "getInfluencer"
239 : Influencer* myInfluencer;
240 :
241 : double myChosenSpeedFactor;
242 :
243 : /// @brief value may be sampled from distribution and therefore must be cached
244 : double myTimegapCrossing;
245 :
246 : private:
247 : /// @brief Invalidated copy constructor.
248 : MSPerson(const MSPerson&);
249 :
250 : /// @brief Invalidated assignment operator.
251 : MSPerson& operator=(const MSPerson&);
252 :
253 : };
|