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 MSStageMoving.h
15 : /// @author Michael Behrisch
16 : /// @author Jakob Erdmann
17 : /// @date Wed, 1 Jun 2022
18 : ///
19 : // The common superclass for modelling walking and tranship
20 : /****************************************************************************/
21 : #pragma once
22 : #include <config.h>
23 :
24 : #include <microsim/transportables/MSStage.h>
25 :
26 :
27 : // ===========================================================================
28 : // class declarations
29 : // ===========================================================================
30 :
31 : /**
32 : * An abstract stage providing additional interface for the movement models
33 : */
34 : class MSStageMoving : public MSStage {
35 : public:
36 : /// constructor
37 365148 : MSStageMoving(const MSStageType type, const std::vector<const MSEdge*>& route, const std::string& routeID, MSStoppingPlace* toStop, const double speed,
38 365148 : const double departPos, const double arrivalPos, const double departPosLat, const int departLane) :
39 : MSStage(type, route.back(), toStop, arrivalPos),
40 365148 : myPState(nullptr), myRoute(route), myRouteID(routeID), myRouteStep(myRoute.begin()),
41 365148 : mySpeed(speed), myDepartPos(departPos),
42 365148 : myDepartPosLat(departPosLat), myDepartLane(departLane),
43 730296 : myLoadedWaitingTime(0)
44 365148 : {}
45 :
46 : /// destructor
47 : virtual ~MSStageMoving();
48 :
49 : virtual const MSEdge* getNextRouteEdge() const = 0;
50 :
51 : inline MSTransportableStateAdapter* getPState() const {
52 6671694 : return myPState;
53 : }
54 :
55 : inline void setPState(MSTransportableStateAdapter* pstate) {
56 : myPState = pstate;
57 : }
58 :
59 : /// Returns the current edge
60 : const MSEdge* getEdge() const;
61 :
62 : /// Returns the current lane
63 : const MSLane* getLane() const;
64 :
65 : /// Returns first edge of the containers route
66 : const MSEdge* getFromEdge() const;
67 :
68 : /// @brief the edges of the current stage
69 : ConstMSEdgeVector getEdges() const;
70 :
71 : /// Returns the offset from the start of the current edge measured in its natural direction
72 : double getEdgePos(SUMOTime now) const;
73 :
74 : /// @brief Return the movement directon on the edge
75 : int getDirection() const;
76 :
77 : /// Returns the position of the container
78 : Position getPosition(SUMOTime now) const;
79 :
80 : /// Returns the angle of the transportable
81 : double getAngle(SUMOTime now) const;
82 :
83 : /// Returns the time the transportable spent waiting
84 : SUMOTime getWaitingTime() const;
85 :
86 : /// Returns the cumulative time the transportable spent waiting
87 : SUMOTime getTotalWaitingTime() const;
88 :
89 : /// Restore waiting time when loading state
90 : void setTotalWaitingTime(SUMOTime t) {
91 33297 : myLoadedWaitingTime = t;
92 : }
93 :
94 : /// Returns the speed of the transportable
95 : double getSpeed() const;
96 :
97 : /// Returns the configured speed in this stage
98 : double getConfiguredSpeed() const {
99 102839850 : return mySpeed;
100 : }
101 :
102 : /// @brief the maximum speed of the transportable
103 : virtual double getMaxSpeed(const MSTransportable* const transportable = nullptr) const = 0;
104 :
105 : /// @brief move forward and return whether the transportable arrived
106 : virtual bool moveToNextEdge(MSTransportable* transportable, SUMOTime currentTime, int prevDir, MSEdge* nextInternal = nullptr, const bool isReplay = false) = 0;
107 :
108 : /// @brief add the move reminders for the current lane on entry
109 0 : virtual void activateEntryReminders(MSTransportable* person, const bool isDepart = false) {
110 : UNUSED_PARAMETER(person);
111 : UNUSED_PARAMETER(isDepart);
112 0 : }
113 :
114 : /// @brief place transportable on a previously passed edge
115 : virtual void setRouteIndex(MSTransportable* const transportable, int routeOffset);
116 :
117 : virtual void replaceRoute(MSTransportable* const transportable, const ConstMSEdgeVector& edges, int routeOffset);
118 :
119 : inline const std::vector<const MSEdge*>& getRoute() const {
120 204255 : return myRoute;
121 : }
122 :
123 : inline const std::vector<const MSEdge*>::iterator getRouteStep() const {
124 2610223 : return myRouteStep;
125 : }
126 :
127 : inline double getDepartPos() const {
128 363928 : return myDepartPos;
129 : }
130 :
131 : inline void setDepartPos(const double pos) {
132 0 : myDepartPos = pos;
133 0 : }
134 :
135 : inline double getDepartPosLat() const {
136 204062 : return myDepartPosLat;
137 : }
138 :
139 : inline int getDepartLane() const {
140 204051 : return myDepartLane;
141 : }
142 :
143 : /// @brief interpret custom depart lane
144 : static const MSLane* checkDepartLane(const MSEdge* edge, SUMOVehicleClass svc, int laneIndex, const std::string& id);
145 :
146 80 : bool equals(const MSStage& s) const {
147 80 : if (!MSStage::equals(s)) {
148 : return false;
149 : }
150 : // this is safe because MSStage already checked that the type fits
151 : const MSStageMoving& sm = static_cast<const MSStageMoving&>(s);
152 160 : return myRoute == sm.myRoute &&
153 80 : myRouteID == sm.myRouteID &&
154 80 : mySpeed == sm.mySpeed &&
155 80 : myDepartPos == sm.myDepartPos &&
156 118 : myDepartPosLat == sm.myDepartPosLat &&
157 38 : myDepartLane == sm.myDepartLane;
158 : }
159 :
160 : protected:
161 : /// @brief state that is to be manipulated by MSPModel
162 : MSTransportableStateAdapter* myPState;
163 :
164 : /// @brief The route of the container
165 : std::vector<const MSEdge*> myRoute;
166 :
167 : /// @brief The original route id
168 : std::string myRouteID;
169 :
170 : /// @brief current step
171 : std::vector<const MSEdge*>::iterator myRouteStep;
172 :
173 : /// @brief The current internal edge this transportable is on or nullptr
174 : MSEdge* myCurrentInternalEdge = nullptr;
175 :
176 : /// @brief the speed of the transportable
177 : double mySpeed;
178 :
179 : /// @brief the depart position
180 : double myDepartPos;
181 :
182 : /// @brief the lateral depart position
183 : double myDepartPosLat;
184 :
185 : /// @brief the depart lane or -1
186 : int myDepartLane;
187 :
188 : SUMOTime myLoadedWaitingTime;
189 : };
|