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