Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2025 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 402728 : MSStageMoving(const MSStageType type, const std::vector<const MSEdge*>& route, const std::string& routeID, MSStoppingPlace* toStop, const double speed,
38 402728 : const double departPos, const double arrivalPos, const double departPosLat, const int departLane) :
39 : MSStage(type, route.back(), toStop, arrivalPos),
40 402728 : myPState(nullptr), myRoute(route), myRouteID(routeID), myRouteStep(myRoute.begin()),
41 402728 : mySpeed(speed), myDepartPos(departPos),
42 1208184 : myDepartPosLat(departPosLat), myDepartLane(departLane) {}
43 :
44 : /// destructor
45 : virtual ~MSStageMoving();
46 :
47 : virtual const MSEdge* getNextRouteEdge() const = 0;
48 :
49 : inline MSTransportableStateAdapter* getPState() const {
50 1479864 : return myPState;
51 : }
52 :
53 : inline void setPState(MSTransportableStateAdapter* pstate) {
54 : myPState = pstate;
55 : }
56 :
57 : /// Returns the current edge
58 : const MSEdge* getEdge() const;
59 :
60 : /// Returns the current lane
61 : const MSLane* getLane() const;
62 :
63 : /// Returns first edge of the containers route
64 : const MSEdge* getFromEdge() const;
65 :
66 : /// @brief the edges of the current stage
67 : ConstMSEdgeVector getEdges() const;
68 :
69 : /// Returns the offset from the start of the current edge measured in its natural direction
70 : double getEdgePos(SUMOTime now) const;
71 :
72 : /// @brief Return the movement directon on the edge
73 : int getDirection() const;
74 :
75 : /// Returns the position of the container
76 : Position getPosition(SUMOTime now) const;
77 :
78 : /// Returns the angle of the transportable
79 : double getAngle(SUMOTime now) const;
80 :
81 : /// Returns the time the transportable spent waiting
82 : SUMOTime getWaitingTime() const;
83 :
84 : /// Returns the cumulative time the transportable spent waiting
85 : SUMOTime getTotalWaitingTime() const;
86 :
87 : /// Returns the speed of the transportable
88 : double getSpeed() const;
89 :
90 : /// Returns the configured speed in this stage
91 : double getConfiguredSpeed() const {
92 131393076 : return mySpeed;
93 : }
94 :
95 : /// @brief the maximum speed of the transportable
96 : virtual double getMaxSpeed(const MSTransportable* const transportable = nullptr) const = 0;
97 :
98 : /// @brief move forward and return whether the transportable arrived
99 : virtual bool moveToNextEdge(MSTransportable* transportable, SUMOTime currentTime, int prevDir, MSEdge* nextInternal = nullptr, const bool isReplay = false) = 0;
100 :
101 : /// @brief add the move reminders for the current lane on entry
102 0 : virtual void activateEntryReminders(MSTransportable* person, const bool isDepart = false) {
103 : UNUSED_PARAMETER(person);
104 : UNUSED_PARAMETER(isDepart);
105 0 : }
106 :
107 : /// @brief place transportable on a previously passed edge
108 : virtual void setRouteIndex(MSTransportable* const transportable, int routeOffset);
109 :
110 : virtual void replaceRoute(MSTransportable* const transportable, const ConstMSEdgeVector& edges, int routeOffset);
111 :
112 : inline const std::vector<const MSEdge*>& getRoute() const {
113 243228 : return myRoute;
114 : }
115 :
116 : inline const std::vector<const MSEdge*>::iterator getRouteStep() const {
117 971666 : return myRouteStep;
118 : }
119 :
120 : inline double getDepartPos() const {
121 398069 : return myDepartPos;
122 : }
123 :
124 : inline void setDepartPos(const double pos) {
125 0 : myDepartPos = pos;
126 0 : }
127 :
128 : inline double getDepartPosLat() const {
129 243030 : return myDepartPosLat;
130 : }
131 :
132 : inline int getDepartLane() const {
133 243024 : return myDepartLane;
134 : }
135 :
136 : /// @brief interpret custom depart lane
137 : static const MSLane* checkDepartLane(const MSEdge* edge, SUMOVehicleClass svc, int laneIndex, const std::string& id);
138 :
139 80 : bool equals(const MSStage& s) const {
140 80 : if (!MSStage::equals(s)) {
141 : return false;
142 : }
143 : // this is safe because MSStage already checked that the type fits
144 : const MSStageMoving& sm = static_cast<const MSStageMoving&>(s);
145 160 : return myRoute == sm.myRoute &&
146 80 : myRouteID == sm.myRouteID &&
147 80 : mySpeed == sm.mySpeed &&
148 80 : myDepartPos == sm.myDepartPos &&
149 118 : myDepartPosLat == sm.myDepartPosLat &&
150 38 : myDepartLane == sm.myDepartLane;
151 : }
152 :
153 : protected:
154 : /// @brief state that is to be manipulated by MSPModel
155 : MSTransportableStateAdapter* myPState;
156 :
157 : /// @brief The route of the container
158 : std::vector<const MSEdge*> myRoute;
159 :
160 : /// @brief The original route id
161 : std::string myRouteID;
162 :
163 : /// @brief current step
164 : std::vector<const MSEdge*>::iterator myRouteStep;
165 :
166 : /// @brief The current internal edge this transportable is on or nullptr
167 : MSEdge* myCurrentInternalEdge = nullptr;
168 :
169 : /// @brief the speed of the transportable
170 : double mySpeed;
171 :
172 : /// @brief the depart position
173 : double myDepartPos;
174 :
175 : /// @brief the lateral depart position
176 : double myDepartPosLat;
177 :
178 : /// @brief the depart lane or -1
179 : int myDepartLane;
180 : };
|