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 MSStageWalking.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 : // A stage performing walking on a sequence of edges. 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 : * A stage performing walking on a sequence of edges. The real movements are part of the pedestrian model. 58 : */ 59 : class MSStageWalking : public MSStageMoving { 60 : public: 61 : /// constructor 62 : MSStageWalking(const std::string& personID, const ConstMSEdgeVector& route, MSStoppingPlace* toStop, SUMOTime walkingTime, 63 : double speed, double departPos, double arrivalPos, double departPosLat, int departLane = -1, const std::string& routeID = ""); 64 : 65 : /// destructor 66 : ~MSStageWalking(); 67 : 68 : MSStage* clone() const; 69 : 70 : /// proceeds to the next step 71 : virtual void proceed(MSNet* net, MSTransportable* person, SUMOTime now, MSStage* previous); 72 : 73 : /// abort this stage (TraCI) 74 : void abort(MSTransportable*); 75 : 76 : /// sets the walking speed (ignored in other stages) 77 : void setSpeed(double speed); 78 : 79 : /// @brief get travel distance in this stage 80 91 : double getDistance() const { 81 91 : return walkDistance(); 82 : } 83 : 84 : /// @brief return index of current edge within route 85 : int getRoutePosition() const; 86 : 87 18328 : std::string getStageDescription(const bool isPerson) const { 88 : UNUSED_PARAMETER(isPerson); 89 18328 : return "walking"; 90 : } 91 : 92 : std::string getStageSummary(const bool isPerson) const; 93 : 94 : /** @brief Saves the current state into the given stream 95 : */ 96 : void saveState(std::ostringstream& out); 97 : 98 : /** @brief Reconstructs the current state 99 : */ 100 : void loadState(MSTransportable* transportable, std::istringstream& state); 101 : 102 : /** @brief Called on writing tripinfo output 103 : * @param[in] os The stream to write the information into 104 : * @exception IOError not yet implemented 105 : */ 106 : virtual void tripInfoOutput(OutputDevice& os, const MSTransportable* const transportable) const; 107 : 108 : /** @brief Called on writing vehroute output 109 : * @param[in] os The stream to write the information into 110 : * @param[in] withRouteLength whether route length shall be written 111 : * @exception IOError not yet implemented 112 : */ 113 : virtual void routeOutput(const bool isPerson, OutputDevice& os, const bool withRouteLength, const MSStage* const previous) const; 114 : 115 : /// @brief move forward and return whether the person arrived 116 : bool moveToNextEdge(MSTransportable* person, SUMOTime currentTime, int prevDir, MSEdge* nextInternal = nullptr); 117 : 118 : void activateEntryReminders(MSTransportable* person, const bool isDepart = false); 119 : 120 : void activateLeaveReminders(MSTransportable* person, const MSLane* lane, double lastPos, SUMOTime t, bool arrived); 121 : 122 : /// @brief accessors to be used by MSPModel 123 : //@{ 124 : double getMaxSpeed(const MSTransportable* const person) const; 125 : 126 19010772 : inline double getArrivalPos() const { 127 19010772 : return myArrivalPos; 128 : } 129 : 130 103183346 : inline const MSEdge* getNextRouteEdge() const { 131 103183346 : return myRouteStep == myRoute.end() - 1 ? nullptr : *(myRouteStep + 1); 132 : } 133 : //@} 134 : 135 : /// @brief Whether the transportable is walking 136 0 : bool isWalk() const { 137 0 : return true; 138 : } 139 : 140 : SUMOTime getTimeLoss(const MSTransportable* transportable) const; 141 : 142 : private: 143 : /// @brief compute total walking distance 144 : double walkDistance(bool partial = false) const; 145 : 146 : /* @brief compute average speed if the total walking duration is given 147 : * @note Must be called when the previous stage changes myDepartPos from the default*/ 148 : double computeAverageSpeed() const; 149 : 150 : private: 151 : /// the time the person is walking 152 : SUMOTime myWalkingTime; 153 : 154 : /// the time the person entered the edge 155 : SUMOTime myLastEdgeEntryTime; 156 : 157 : /// @brief the MoveReminders encountered while walking 158 : std::vector<MSMoveReminder*> myMoveReminders; 159 : 160 : /// @brief optional exit time tracking for vehroute output 161 : std::vector<SUMOTime>* myExitTimes; 162 : 163 : /// @brief distance walked on non-normal edges (i.e. walkingareas) 164 : double myInternalDistance; 165 : 166 : static bool myWarnedInvalidTripinfo; 167 : 168 : private: 169 : /// @brief Invalidated copy constructor. 170 : MSStageWalking(const MSStageWalking&); 171 : 172 : /// @brief Invalidated assignment operator. 173 : MSStageWalking& operator=(const MSStageWalking&); 174 : 175 : };