Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-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 : /****************************************************************************/
14 : /// @file MSStage.h
15 : /// @author Michael Behrisch
16 : /// @date Tue, 21 Apr 2015
17 : ///
18 : // The common superclass for modelling transportable objects like persons and containers
19 : /****************************************************************************/
20 : #pragma once
21 : #include <config.h>
22 :
23 : #include <set>
24 : #include <cassert>
25 : #include <utils/common/SUMOTime.h>
26 : #include <utils/common/SUMOVehicleClass.h>
27 : #include <utils/geom/Position.h>
28 : #include <utils/geom/PositionVector.h>
29 : #include <utils/geom/Boundary.h>
30 : #include <utils/router/SUMOAbstractRouter.h>
31 : #include <utils/vehicle/SUMOTrafficObject.h>
32 :
33 :
34 : // ===========================================================================
35 : // class declarations
36 : // ===========================================================================
37 : class MSEdge;
38 : class MSLane;
39 : class MSNet;
40 : class MSStoppingPlace;
41 : class MSVehicleType;
42 : class OutputDevice;
43 : class SUMOVehicleParameter;
44 : class SUMOVehicle;
45 : class MSStageTrip;
46 : class MSTransportableDevice;
47 : class MSTransportable;
48 : class MSTransportableStateAdapter;
49 :
50 : typedef std::vector<const MSEdge*> ConstMSEdgeVector;
51 :
52 : // ===========================================================================
53 : // class definitions
54 : // ===========================================================================
55 : enum class MSStageType {
56 : WAITING_FOR_DEPART = 0,
57 : WAITING = 1,
58 : WALKING = 2, // only for persons
59 : DRIVING = 3,
60 : ACCESS = 4,
61 : TRIP = 5,
62 : TRANSHIP = 6
63 : };
64 :
65 : /**
66 : * The "abstract" class for a single stage of a movement
67 : * Contains the destination of the current movement step
68 : */
69 : class MSStage : public Parameterised {
70 : public:
71 : /// constructor
72 : MSStage(const MSStageType type, const MSEdge* destination, MSStoppingPlace* toStop, const double arrivalPos,
73 : const double arrivalPosLat = 0.0, const std::string& group = "");
74 :
75 : /// destructor
76 : virtual ~MSStage();
77 :
78 : /// initialization, e.g. for param-related events
79 993551 : virtual void init(MSTransportable* /*transportable*/) {};
80 :
81 : /// returns the destination edge
82 : const MSEdge* getDestination() const;
83 :
84 : /// returns the destination stop (if any)
85 : MSStoppingPlace* getDestinationStop() const {
86 15860465 : return myDestinationStop;
87 : }
88 :
89 : /// returns the origin stop (if any). only needed for MSStageTrip
90 48 : virtual MSStoppingPlace* getOriginStop() const {
91 48 : return nullptr;
92 : }
93 :
94 644661 : virtual double getArrivalPos() const {
95 644661 : return myArrivalPos;
96 : }
97 :
98 0 : virtual double getArrivalPosLat() const {
99 0 : return myArrivalPosLat;
100 : }
101 :
102 : void setArrivalPos(double arrivalPos) {
103 249 : myArrivalPos = arrivalPos;
104 204 : }
105 :
106 : /// Returns the current edge
107 : virtual const MSEdge* getEdge() const;
108 : virtual const MSEdge* getFromEdge() const;
109 : virtual double getEdgePos(SUMOTime now) const;
110 : virtual double getEdgePosLat(SUMOTime now) const;
111 :
112 : /// @brief Return the movement directon on the edge
113 : virtual int getDirection() const;
114 :
115 : /// returns the position of the transportable
116 : virtual Position getPosition(SUMOTime now) const = 0;
117 :
118 : /// returns the angle of the transportable
119 : virtual double getAngle(SUMOTime now) const = 0;
120 :
121 : /// Returns the current lane (if applicable)
122 7251 : virtual const MSLane* getLane() const {
123 7251 : return nullptr;
124 : }
125 :
126 : ///
127 : MSStageType getStageType() const {
128 8388836 : return myType;
129 : }
130 :
131 : /// @brief return the id of the group of transportables traveling together
132 : const std::string& getGroup() const {
133 : return myGroup;
134 : }
135 :
136 : /// @brief return (brief) string representation of the current stage
137 : virtual std::string getStageDescription(const bool isPerson) const = 0;
138 :
139 : /// @brief return string summary of the current stage
140 : virtual std::string getStageSummary(const bool isPerson) const = 0;
141 :
142 : /// proceeds to this stage
143 : virtual void proceed(MSNet* net, MSTransportable* transportable, SUMOTime now, MSStage* previous) = 0;
144 :
145 : /// abort this stage (TraCI)
146 0 : virtual void abort(MSTransportable*) {};
147 :
148 : /// sets the walking speed (ignored in other stages)
149 5 : virtual void setSpeed(double) {};
150 :
151 : /// get departure time of stage
152 : SUMOTime getDeparted() const;
153 :
154 : /// get arrival time of stage
155 : SUMOTime getArrived() const;
156 :
157 : virtual SUMOTime getTimeLoss(const MSTransportable* transportable) const;
158 : virtual SUMOTime getDuration() const;
159 : virtual SUMOTime getTravelTime() const;
160 : virtual SUMOTime getWaitingTime() const;
161 :
162 : /// logs end of the step
163 : void setDeparted(SUMOTime now);
164 :
165 : /// logs end of the step
166 : virtual const std::string setArrived(MSNet* net, MSTransportable* transportable, SUMOTime now, const bool vehicleArrived);
167 :
168 : /// Whether the transportable waits for the given vehicle
169 : virtual bool isWaitingFor(const SUMOVehicle* vehicle) const;
170 :
171 : /// @brief Whether the transportable waits for a vehicle
172 3467 : virtual bool isWaiting4Vehicle() const {
173 3467 : return false;
174 : }
175 :
176 : /// @brief Whether the transportable is walking
177 0 : virtual bool isWalk() const {
178 0 : return false;
179 : }
180 :
181 : /// @brief Current vehicle in which the transportable is driving (or nullptr)
182 361147 : virtual SUMOVehicle* getVehicle() const {
183 361147 : return nullptr;
184 : }
185 :
186 : /// @brief the time this transportable spent waiting
187 : virtual SUMOTime getWaitingTime(SUMOTime now) const;
188 :
189 : /// @brief the speed of the transportable
190 : virtual double getSpeed() const;
191 :
192 : /// @brief the edges of the current stage
193 : virtual ConstMSEdgeVector getEdges() const;
194 :
195 : /// @brief return index of current edge within route
196 7224 : virtual int getRoutePosition() const {
197 7224 : return 0;
198 : }
199 :
200 : /// @brief get position on edge e at length at with orthogonal offset
201 : Position getEdgePosition(const MSEdge* e, double at, double offset) const;
202 :
203 : /// @brief get position on lane at length at with orthogonal offset
204 : Position getLanePosition(const MSLane* lane, double at, double offset) const;
205 :
206 : /// @brief get angle of the edge at a certain position
207 : double getEdgeAngle(const MSEdge* e, double at) const;
208 :
209 : void setDestination(const MSEdge* newDestination, MSStoppingPlace* newDestStop);
210 :
211 : /// @brief get travel distance in this stage
212 : virtual double getDistance() const = 0;
213 :
214 : /** @brief Called on writing tripinfo output
215 : * @param[in] os The stream to write the information into
216 : * @exception IOError not yet implemented
217 : */
218 : virtual void tripInfoOutput(OutputDevice& os, const MSTransportable* const transportable) const = 0;
219 :
220 : /** @brief Called on writing vehroute output
221 : * @param[in] isPerson Whether we are writing person or container info
222 : * @param[in] os The stream to write the information into
223 : * @param[in] withRouteLength whether route length shall be written
224 : * @param[in] previous The previous stage for additional info such as from edge
225 : * @exception IOError not yet implemented
226 : */
227 : virtual void routeOutput(const bool isPerson, OutputDevice& os, const bool withRouteLength, const MSStage* const previous) const = 0;
228 :
229 : virtual MSStage* clone() const = 0;
230 :
231 : /** @brief Saves the current state into the given stream, standard implementation does nothing
232 : */
233 0 : virtual void saveState(std::ostringstream& out) {
234 : UNUSED_PARAMETER(out);
235 0 : }
236 :
237 : /** @brief Reconstructs the current state, standard implementation does nothing
238 : */
239 0 : virtual void loadState(MSTransportable* transportable, std::istringstream& state) {
240 : UNUSED_PARAMETER(transportable);
241 : UNUSED_PARAMETER(state);
242 0 : }
243 :
244 : bool wasSet(int what) const {
245 208479 : return (myParametersSet & what) != 0;
246 : }
247 :
248 : void markSet(int what) {
249 32887 : myParametersSet |= what;
250 32887 : }
251 :
252 : /** @brief Returns the costs of the stage
253 : *
254 : * @return The stage's costs (normally the time needed to pass it)
255 : */
256 : double getCosts() const {
257 105 : return myCosts;
258 : }
259 :
260 : /** @brief Sets the costs of the stage
261 : *
262 : * @param[in] costs The new stage costs
263 : */
264 : void setCosts(double costs) {
265 206641 : myCosts = costs;
266 : }
267 :
268 : MSStageTrip* getTrip() const {
269 4315 : return myTrip;
270 : }
271 :
272 : void setTrip(MSStageTrip* trip) {
273 216594 : myTrip = trip;
274 : }
275 :
276 118 : virtual bool equals(const MSStage& s) const {
277 236 : return myDestination == s.myDestination &&
278 118 : myDestinationStop == s.myDestinationStop &&
279 118 : myArrivalPos == s.myArrivalPos &&
280 118 : myArrivalPosLat == s.myArrivalPosLat &&
281 236 : myType == s.myType &&
282 118 : myGroup == s.myGroup;
283 : }
284 :
285 : protected:
286 : /// the next edge to reach by getting transported
287 : const MSEdge* myDestination;
288 :
289 : /// the stop to reach by getting transported (if any)
290 : MSStoppingPlace* myDestinationStop;
291 :
292 : /// @brief the longitudinal position at which we want to arrive
293 : double myArrivalPos;
294 :
295 : /// @brief the lateral position at which we want to arrive
296 : double myArrivalPosLat;
297 :
298 : /// the time at which this stage started
299 : SUMOTime myDeparted;
300 :
301 : /// the time at which this stage ended
302 : SUMOTime myArrived;
303 :
304 : /// The type of this stage
305 : MSStageType myType;
306 :
307 : /// The id of the group of transportables traveling together
308 : const std::string myGroup;
309 :
310 : /// @brief The assigned or calculated costs
311 : double myCosts;
312 :
313 : /// @brief Information on which parameter were set (mainly for vehroute output)
314 : int myParametersSet;
315 :
316 : MSStageTrip* myTrip = nullptr;
317 :
318 : /// @brief the offset for computing positions when standing at an edge
319 : static const double ROADSIDE_OFFSET;
320 :
321 : private:
322 : /// @brief Invalidated copy constructor.
323 : MSStage(const MSStage&);
324 :
325 : /// @brief Invalidated assignment operator.
326 : MSStage& operator=(const MSStage&) = delete;
327 :
328 : };
|