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 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 402647 : MSStageMoving(const MSStageType type, const std::vector<const MSEdge*>& route, const std::string& routeID, MSStoppingPlace* toStop, const double speed, 38 402647 : const double departPos, const double arrivalPos, const double departPosLat, const int departLane) : 39 : MSStage(type, route.back(), toStop, arrivalPos), 40 402647 : myPState(nullptr), myRoute(route), myRouteID(routeID), myRouteStep(myRoute.begin()), 41 402647 : mySpeed(speed), myDepartPos(departPos), 42 1207941 : 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 1445758 : 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 container 79 : double getAngle(SUMOTime now) const; 80 : 81 : /// Returns the time the container spent waiting 82 : SUMOTime getWaitingTime(SUMOTime now) const; 83 : 84 : /// Returns the speed of the container 85 : double getSpeed() const; 86 : 87 : /// Returns the configured speed in this stage 88 : double getConfiguredSpeed() const { 89 49724301 : return mySpeed; 90 : } 91 : 92 : /// @brief the maximum speed of the transportable 93 : virtual double getMaxSpeed(const MSTransportable* const transportable = nullptr) const = 0; 94 : 95 : /// @brief move forward and return whether the transportable arrived 96 : virtual bool moveToNextEdge(MSTransportable* transportable, SUMOTime currentTime, int prevDir, MSEdge* nextInternal = 0) = 0; 97 : 98 : /// @brief add the move reminders for the current lane on entry 99 0 : virtual void activateEntryReminders(MSTransportable* person, const bool isDepart = false) { 100 : UNUSED_PARAMETER(person); 101 : UNUSED_PARAMETER(isDepart); 102 0 : } 103 : 104 : /// @brief place transportable on a previously passed edge 105 : virtual void setRouteIndex(MSTransportable* const transportable, int routeOffset); 106 : 107 : virtual void replaceRoute(MSTransportable* const transportable, const ConstMSEdgeVector& edges, int routeOffset); 108 : 109 : inline const std::vector<const MSEdge*>& getRoute() const { 110 270344 : return myRoute; 111 : } 112 : 113 : inline const std::vector<const MSEdge*>::iterator getRouteStep() const { 114 964899 : return myRouteStep; 115 : } 116 : 117 : inline double getDepartPos() const { 118 402220 : return myDepartPos; 119 : } 120 : 121 : inline void setDepartPos(const double pos) { 122 0 : myDepartPos = pos; 123 0 : } 124 : 125 : inline double getDepartPosLat() const { 126 269568 : return myDepartPosLat; 127 : } 128 : 129 : inline int getDepartLane() const { 130 269576 : return myDepartLane; 131 : } 132 : 133 : /// @brief interpret custom depart lane 134 : static const MSLane* checkDepartLane(const MSEdge* edge, SUMOVehicleClass svc, int laneIndex, const std::string& id); 135 : 136 : protected: 137 : /// @brief state that is to be manipulated by MSPModel 138 : MSTransportableStateAdapter* myPState; 139 : 140 : /// @brief The route of the container 141 : std::vector<const MSEdge*> myRoute; 142 : 143 : /// @brief The original route id 144 : std::string myRouteID; 145 : 146 : /// @brief current step 147 : std::vector<const MSEdge*>::iterator myRouteStep; 148 : 149 : /// @brief The current internal edge this transportable is on or nullptr 150 : MSEdge* myCurrentInternalEdge = nullptr; 151 : 152 : /// @brief the speed of the transportable 153 : double mySpeed; 154 : 155 : /// @brief the depart position 156 : double myDepartPos; 157 : 158 : /// @brief the lateral depart position 159 : double myDepartPosLat; 160 : 161 : /// @brief the depart lane or -1 162 : int myDepartLane; 163 : };