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 MSTransportable.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/common/WrappingCommand.h> 28 : #include <utils/geom/Position.h> 29 : #include <utils/geom/PositionVector.h> 30 : #include <utils/geom/Boundary.h> 31 : #include <utils/router/SUMOAbstractRouter.h> 32 : #include <utils/vehicle/SUMOTrafficObject.h> 33 : #include <microsim/MSRouterDefs.h> 34 : #include "MSStage.h" 35 : 36 : 37 : // =========================================================================== 38 : // class declarations 39 : // =========================================================================== 40 : class MSEdge; 41 : class MSLane; 42 : class MSNet; 43 : class MSStoppingPlace; 44 : class MSVehicleType; 45 : class OutputDevice; 46 : class SUMOVehicleParameter; 47 : class SUMOVehicle; 48 : class MSTransportableDevice; 49 : 50 : 51 : // =========================================================================== 52 : // class definitions 53 : // =========================================================================== 54 : /** 55 : * @class MSTransportable 56 : * 57 : * The class holds a simulated moveable object 58 : */ 59 : class MSTransportable : public SUMOTrafficObject { 60 : public: 61 : /// @name inherited from SUMOTrafficObject 62 : /// @{ 63 5780649 : inline bool isPerson() const { 64 5780649 : return myAmPerson; 65 : } 66 : 67 79 : inline bool isContainer() const { 68 79 : return !myAmPerson; 69 : } 70 : 71 : inline std::string getObjectType() { 72 54607 : return myAmPerson ? "Person" : "Container"; 73 : } 74 : 75 44450524 : inline NumericalID getNumericalID() const { 76 44450524 : return myNumericalID; 77 : } 78 : 79 4270 : inline bool isStopped() const { 80 4270 : return getCurrentStageType() == MSStageType::WAITING; 81 : } 82 : 83 : double getSlope() const; 84 : 85 : SUMOVehicleClass getVClass() const; 86 : 87 : /// @brief whether the transportable (persons) is jammed as defined by the current pedestrian model 88 0 : virtual bool isJammed() const { 89 0 : return false; 90 : } 91 : 92 : /** @brief Returns the maximum speed (the minimum of desired and physical maximum speed) 93 : * @return The objects's maximum speed 94 : */ 95 : double getMaxSpeed() const; 96 : 97 : SUMOTime getWaitingTime(const bool accumulated = false) const; 98 : 99 26034 : double getPreviousSpeed() const { 100 26034 : return getSpeed(); 101 : } 102 : 103 9220 : double getAcceleration() const { 104 9220 : return 0.0; 105 : } 106 : 107 1571451 : double getPositionOnLane() const { 108 1571451 : return getEdgePos(); 109 : } 110 : 111 : double getBackPositionOnLane(const MSLane* lane) const; 112 : 113 258603 : Position getPosition(const double /*offset*/) const { 114 258603 : return getPosition(); 115 : } 116 : /// @} 117 : 118 : /// the structure holding the plan of a transportable 119 : typedef std::vector<MSStage*> MSTransportablePlan; 120 : 121 : /// constructor 122 : MSTransportable(const SUMOVehicleParameter* pars, MSVehicleType* vtype, MSTransportablePlan* plan, const bool isPerson); 123 : 124 : /// destructor 125 : virtual ~MSTransportable(); 126 : 127 : /* @brief proceeds to the next step of the route, 128 : * @return Whether the transportables plan continues */ 129 : virtual bool proceed(MSNet* net, SUMOTime time, const bool vehicleArrived = false); 130 : 131 556 : virtual bool checkAccess(const MSStage* const prior, const bool waitAtStop = true) { 132 : UNUSED_PARAMETER(prior); 133 : UNUSED_PARAMETER(waitAtStop); 134 556 : return false; 135 : } 136 : 137 : /// @brief set the id (inherited from Named but forbidden for transportables) 138 : void setID(const std::string& newID); 139 : 140 4166247 : inline const SUMOVehicleParameter& getParameter() const { 141 4166247 : return *myParameter; 142 : } 143 : 144 4034954389 : inline const MSVehicleType& getVehicleType() const { 145 4034954389 : return *myVType; 146 : } 147 : 148 : /// @brief returns the associated RNG 149 : SumoRNG* getRNG() const; 150 : 151 : /// @brief returns the index of the associated RNG 152 : int getRNGIndex() const; 153 : 154 : /// Returns the desired departure time. 155 : SUMOTime getDesiredDepart() const; 156 : 157 : /// logs depart time of the current stage 158 : void setDeparted(SUMOTime now); 159 : 160 : /// logs depart time of the current stage 161 : SUMOTime getDeparture() const; 162 : 163 : /// Returns the current destination. 164 : const MSEdge* getDestination() const { 165 87610 : return (*myStep)->getDestination(); 166 : } 167 : 168 : /// Returns the destination after the current destination. 169 : const MSEdge* getNextDestination() const { 170 : return (*(myStep + 1))->getDestination(); 171 : } 172 : 173 : /// @brief Returns the current edge 174 705642 : const MSEdge* getEdge() const { 175 705642 : return (*myStep)->getEdge(); 176 : } 177 : 178 : /// @brief Returns the current lane (may be nullptr) 179 937930 : const MSLane* getLane() const { 180 937930 : return (*myStep)->getLane(); 181 : } 182 : 183 : /// @brief Returns the departure edge 184 : const MSEdge* getFromEdge() const { 185 0 : return (*myStep)->getFromEdge(); 186 : } 187 : 188 : /// @brief Return the position on the edge 189 : virtual double getEdgePos() const; 190 : 191 : /// @brief Return the movement directon on the edge 192 : virtual int getDirection() const; 193 : 194 : /// @brief Return the Network coordinate of the transportable 195 : virtual Position getPosition() const; 196 : 197 : /// @brief return the current angle of the transportable 198 : virtual double getAngle() const; 199 : 200 : /// @brief the time this transportable spent waiting in seconds 201 : virtual double getWaitingSeconds() const; 202 : 203 : /// @brief the current speed of the transportable 204 : virtual double getSpeed() const; 205 : 206 : /// @brief the current speed factor of the transportable (where applicable) 207 0 : virtual double getChosenSpeedFactor() const { 208 0 : return 1; 209 : } 210 : 211 : /// @brief the current stage type of the transportable 212 : MSStageType getCurrentStageType() const { 213 2595028 : return (*myStep)->getStageType(); 214 : } 215 : 216 : /// @brief the stage type for the nth next stage 217 : MSStageType getStageType(int next) const { 218 : assert(myStep + next < myPlan->end()); 219 : assert(myStep + next >= myPlan->begin()); 220 49095 : return (*(myStep + next))->getStageType(); 221 : } 222 : 223 : /// @brief return textual summary for the given stage 224 : std::string getStageSummary(int stageIndex) const; 225 : 226 : /// Returns the current stage description as a string 227 0 : std::string getCurrentStageDescription() const { 228 21010 : return (*myStep)->getStageDescription(myAmPerson); 229 : } 230 : 231 : /// @brief Return the current stage 232 : MSStage* getCurrentStage() const { 233 6600666 : return *myStep; 234 : } 235 : 236 : /// @brief Return the next (or previous) stage denoted by the offset 237 : inline MSStage* getNextStage(int offset) const { 238 : assert(myStep + offset >= myPlan->begin()); 239 : assert(myStep + offset < myPlan->end()); 240 242349 : return *(myStep + offset); 241 : } 242 : 243 : /// @brief returns the numerical IDs of edges to be used (possibly of future stages) 244 : const std::set<NumericalID> getUpcomingEdgeIDs() const; 245 : 246 : /// @brief Return the total number stages in this person's plan 247 : inline int getNumStages() const { 248 474057 : return (int)myPlan->size(); 249 : } 250 : 251 : /// @brief Return the number of remaining stages (including the current) 252 : inline int getNumRemainingStages() const { 253 62897 : return (int)(myPlan->end() - myStep); 254 : } 255 : 256 : /// @brief Return the index of the current stage 257 : inline int getCurrentStageIndex() const { 258 238185 : return (int)(myStep - myPlan->begin()); 259 : } 260 : 261 : /// @brief return the index of the edge within the route 262 455878 : inline int getRoutePosition() const { 263 455878 : return (*myStep)->getRoutePosition(); 264 : } 265 : 266 : /// @brief returns the next edge ptr (used by walking persons) 267 0 : virtual const MSEdge* getNextEdgePtr() const { 268 0 : return nullptr; 269 : } 270 : 271 : /** @brief Called on writing tripinfo output 272 : * 273 : * @param[in] os The stream to write the information into 274 : * @exception IOError not yet implemented 275 : */ 276 : void tripInfoOutput(OutputDevice& os) const; 277 : 278 : /** @brief Called on writing vehroute output 279 : * 280 : * @param[in] os The stream to write the information into 281 : * @exception IOError not yet implemented 282 : */ 283 : void routeOutput(OutputDevice& os, const bool withRouteLength) const; 284 : 285 : /// Whether the transportable waits for the given vehicle in the current step 286 : bool isWaitingFor(const SUMOVehicle* vehicle) const { 287 314257 : return (*myStep)->isWaitingFor(vehicle); 288 : } 289 : 290 : /// @brief Whether the transportable waits for a vehicle 291 : bool isWaiting4Vehicle() const { 292 1834577 : return (*myStep)->isWaiting4Vehicle(); 293 : } 294 : 295 : void setAbortWaiting(const SUMOTime timeout); 296 : 297 : /// @brief Abort current stage (used for aborting waiting for a vehicle) 298 : SUMOTime abortStage(SUMOTime step); 299 : 300 : /// @brief The vehicle associated with this transportable 301 : SUMOVehicle* getVehicle() const { 302 355600 : return (*myStep)->getVehicle(); 303 : } 304 : 305 : /// @brief Appends the given stage to the current plan 306 : void appendStage(MSStage* stage, int next = -1); 307 : 308 : /// @brief removes the nth next stage 309 : void removeStage(int next, bool stayInSim = true); 310 : 311 : /// @brief set the speed for all present and future (walking) stages and modify the vType so that stages added later are also affected 312 : void setSpeed(double speed); 313 : 314 : /// @brief returns the final arrival pos 315 : double getArrivalPos() const { 316 316 : return myPlan->back()->getArrivalPos(); 317 : } 318 : 319 : /// @brief returns the final arrival edge 320 1556 : const MSEdge* getArrivalEdge() const { 321 1556 : return myPlan->back()->getEdges().back(); 322 : } 323 : 324 : /** @brief Returns the end point for reroutes (usually the last edge of the route) 325 : * 326 : * @return The rerouting end point 327 : */ 328 1525 : const MSEdge* getRerouteDestination() const { 329 1525 : return getArrivalEdge(); 330 : } 331 : 332 : /// Replaces the current route by the given one 333 : bool replaceRoute(ConstMSRoutePtr route, const std::string& info, bool onInit = false, int offset = 0, bool addStops = true, bool removeStops = true, std::string* msgReturn = nullptr); 334 : 335 : /** @brief Replaces the current vehicle type by the one given 336 : * 337 : * If the currently used vehicle type is marked as being used by this vehicle 338 : * only, it is deleted, first. The new, given type is then assigned to 339 : * "myVType". 340 : * @param[in] type The new vehicle type 341 : * @see MSTransportable::myVType 342 : */ 343 : void replaceVehicleType(MSVehicleType* type); 344 : 345 : /** @brief Replaces the current vehicle type with a new one used by this vehicle only 346 : * 347 : * If the currently used vehicle type is already marked as being used by this vehicle 348 : * only, no new type is created. 349 : * @return The new modifiable vehicle type 350 : * @see MSTransportable::myVType 351 : */ 352 : MSVehicleType& getSingularType(); 353 : 354 : /// @brief return the bounding box of the person 355 : PositionVector getBoundingBox() const; 356 : 357 : /// @brief return whether the person has reached the end of its plan 358 : bool hasArrived() const; 359 : 360 : /// @brief return whether the transportable has started its plan 361 : bool hasDeparted() const; 362 : 363 : /// @brief adapt plan when the vehicle reroutes and now stops at replacement instead of orig 364 : void rerouteParkingArea(MSStoppingPlace* orig, MSStoppingPlace* replacement); 365 : 366 : /// @brief Returns a device of the given type if it exists or nullptr if not 367 : MSDevice* getDevice(const std::type_info& type) const; 368 : 369 : /// @brief set individual junction model paramete (not type related) 370 : void setJunctionModelParameter(const std::string& key, const std::string& value); 371 : 372 : /** @brief Returns this vehicle's devices 373 : * @return This vehicle's devices 374 : */ 375 : inline const std::vector<MSTransportableDevice*>& getDevices() const { 376 : return myDevices; 377 : } 378 : 379 0 : virtual bool hasInfluencer() const { 380 0 : return false; 381 : } 382 : 383 : /// @brief whether this transportable is selected in the GUI 384 0 : virtual bool isSelected() const { 385 0 : return false; 386 : } 387 : 388 : /// @brief return routing mode (configures router choice but also handling of transient permission changes) 389 : virtual int getRoutingMode() const; 390 : 391 : /** @brief Saves the current state into the given stream 392 : */ 393 : void saveState(OutputDevice& out); 394 : 395 : /** @brief Reconstructs the current state 396 : */ 397 : void loadState(const std::string& state); 398 : 399 : protected: 400 : /// the plan of the transportable 401 : const SUMOVehicleParameter* myParameter; 402 : 403 : /// @brief This transportable's type. (mainly used for drawing related information 404 : /// Note sure if it is really necessary 405 : MSVehicleType* myVType; 406 : 407 : /// @brief Whether events shall be written 408 : bool myWriteEvents; 409 : 410 : /// the plan of the transportable 411 : MSTransportablePlan* myPlan; 412 : 413 : /// the iterator over the route 414 : MSTransportablePlan::iterator myStep; 415 : 416 : /// @brief The devices this transportable has 417 : std::vector<MSTransportableDevice*> myDevices; 418 : 419 : private: 420 : const bool myAmPerson; 421 : 422 : const NumericalID myNumericalID; 423 : 424 : WrappingCommand<MSTransportable>* myAbortCommand; 425 : 426 : static NumericalID myCurrentNumericalIndex; 427 : 428 : private: 429 : /// @brief Invalidated copy constructor. 430 : MSTransportable(const MSTransportable&); 431 : 432 : /// @brief Invalidated assignment operator. 433 : MSTransportable& operator=(const MSTransportable&); 434 : 435 : };