LCOV - code coverage report
Current view: top level - src/microsim/transportables - MSStageDriving.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 25 25
Test Date: 2026-05-24 16:29:35 Functions: 100.0 % 4 4

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-2026 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    MSStageDriving.h
      15              : /// @author  Michael Behrisch
      16              : /// @date    Tue, 21 Apr 2015
      17              : ///
      18              : // A stage performing the travelling by a transport system (cars, public transport)
      19              : /****************************************************************************/
      20              : #pragma once
      21              : #include <config.h>
      22              : 
      23              : #include <set>
      24              : #include <cassert>
      25              : #include <utils/common/Command.h>
      26              : #include <utils/common/SUMOTime.h>
      27              : #include <utils/common/SUMOVehicleClass.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 "MSStage.h"
      34              : 
      35              : 
      36              : // ===========================================================================
      37              : // class declarations
      38              : // ===========================================================================
      39              : class MSEdge;
      40              : class MSLane;
      41              : class MSNet;
      42              : class MSStop;
      43              : class MSStoppingPlace;
      44              : class MSVehicleType;
      45              : class OutputDevice;
      46              : class SUMOVehicleParameter;
      47              : class SUMOVehicle;
      48              : class MSTransportableDevice;
      49              : class MSTransportable;
      50              : 
      51              : typedef std::vector<const MSEdge*> ConstMSEdgeVector;
      52              : 
      53              : // ===========================================================================
      54              : // class definitions
      55              : // ===========================================================================
      56              : /**
      57              : * A "real" stage performing the travelling by a transport system
      58              : * The given route will be chosen. The travel time is computed by the simulation
      59              : */
      60              : class MSStageDriving : public MSStage {
      61              : public:
      62              :     /// constructor
      63              :     MSStageDriving(const MSEdge* origin, const MSEdge* destination, MSStoppingPlace* toStop,
      64              :                    const double arrivalPos, const double arrivalPosLat, const std::vector<std::string>& lines,
      65              :                    const std::string& group = "",
      66              :                    const std::string& intendedVeh = "", SUMOTime intendedDepart = -1);
      67              : 
      68              :     /// destructor
      69              :     virtual ~MSStageDriving();
      70              : 
      71              :     MSStage* clone() const;
      72              : 
      73              :     /// @brief return default value for undefined arrivalPos
      74              :     double getArrivalPos() const;
      75              : 
      76              :     /// abort this stage (TraCI)
      77              :     void abort(MSTransportable* t);
      78              : 
      79              :     /// initialization, e.g. for param-related events
      80              :     void init(MSTransportable* transportable);
      81              : 
      82              :     /// Returns the current edge
      83              :     const MSEdge* getEdge() const;
      84              :     const MSEdge* getFromEdge() const;
      85              :     double getEdgePos(SUMOTime now) const;
      86              : 
      87              :     /// @brief Return the movement directon on the edge
      88              :     int getDirection() const;
      89              : 
      90              :     const MSLane* getLane() const;
      91              : 
      92        99401 :     MSStoppingPlace* getOriginStop() const {
      93        99401 :         return myOriginStop;
      94              :     }
      95              : 
      96              :     ///
      97              :     Position getPosition(SUMOTime now) const;
      98              : 
      99              :     double getAngle(SUMOTime now) const;
     100              : 
     101              :     /// @brief get travel distance in this stage
     102              :     double getDistance() const;
     103              : 
     104              :     /// @brief return (brief) string representation of the current stage
     105              :     std::string getStageDescription(const bool isPerson) const;
     106              : 
     107              :     /// @brief return string summary of the current stage
     108              :     std::string getStageSummary(const bool isPerson) const;
     109              : 
     110              :     /// proceeds to this stage
     111              :     void proceed(MSNet* net, MSTransportable* transportable, SUMOTime now, MSStage* previous);
     112              : 
     113              :     /** @brief Called on writing tripinfo output
     114              :      * @param[in] os The stream to write the information into
     115              :      * @exception IOError not yet implemented
     116              :      */
     117              :     void tripInfoOutput(OutputDevice& os, const MSTransportable* const transportable) const;
     118              : 
     119              :     /** @brief Called on writing vehroute output
     120              :      * @param[in] isPerson Whether we are writing person or container info
     121              :      * @param[in] os The stream to write the information into
     122              :      * @param[in] withRouteLength whether route length shall be written
     123              :      * @param[in] previous The previous stage for additional info such as from edge
     124              :      * @exception IOError not yet implemented
     125              :      */
     126              :     void routeOutput(const bool isPerson, OutputDevice& os, const bool withRouteLength, const MSStage* const previous, const bool withTiming, const bool saveState = false) const;
     127              : 
     128              :     /// Whether the person waits for the given vehicle
     129              :     bool isWaitingFor(const SUMOVehicle* vehicle) const;
     130              : 
     131              :     /// @brief Whether the person waits for a vehicle
     132              :     bool isWaiting4Vehicle() const;
     133              : 
     134              :     /// @brief Return where the person waits and for what
     135              :     std::string getWaitingDescription() const;
     136              : 
     137        72646 :     SUMOVehicle* getVehicle() const {
     138        72646 :         return myVehicle;
     139              :     }
     140              : 
     141              :     /// @brief time spent waiting for a ride
     142              :     SUMOTime getWaitingTime(SUMOTime now) const;
     143              : 
     144              :     double getSpeed() const;
     145              : 
     146              :     ConstMSEdgeVector getEdges() const;
     147              : 
     148              :     void setVehicle(SUMOVehicle* v);
     149              :     void setVehicleID(const std::string vehID) {
     150         7180 :         myVehicleID = vehID;
     151         7180 :     }
     152              : 
     153              :     /// @brief marks arrival time and records driven distance
     154              :     const std::string setArrived(MSNet* net, MSTransportable* transportable, SUMOTime now, const bool vehicleArrived);
     155              : 
     156              :     const std::set<std::string>& getLines() const {
     157        75747 :         return myLines;
     158              :     }
     159              : 
     160              :     std::string getIntendedVehicleID() const {
     161          526 :         return myIntendedVehicleID;
     162              :     }
     163              : 
     164              :     SUMOTime getIntendedDepart() const {
     165          102 :         return myIntendedDepart;
     166              :     }
     167              : 
     168              :     std::string getVehicleType() const {
     169          526 :         return myVehicleType;
     170              :     }
     171              : 
     172              :     /// change origin for parking area rerouting
     173           10 :     void setOrigin(const MSEdge* origin, MSStoppingPlace* originStop, double departPos) {
     174           10 :         myOrigin = origin;
     175           10 :         myOriginStop = originStop;
     176           10 :         myWaitingPos = departPos;
     177           10 :     }
     178              : 
     179              :     /// @brief restore further state during loading
     180              :     void setWaitingSince(SUMOTime t) {
     181            4 :         myWaitingSince = t;
     182            4 :     }
     183              : 
     184              :     /// @brief restore further state during loading
     185              :     void setVehicleDistance(double dist) {
     186         7180 :         myVehicleDistance = dist;
     187              :     }
     188              : 
     189              :     /// @brief checks whether the person may exit at the current vehicle position
     190              :     bool canLeaveVehicle(const MSTransportable* t, const SUMOVehicle& veh, const MSStop& stop);
     191              : 
     192              :     SUMOTime getTimeLoss(const MSTransportable* transportable) const;
     193              :     SUMOTime getDuration() const;
     194              :     SUMOTime getTravelTime() const;
     195              :     SUMOTime getWaitingTime() const;
     196              : 
     197              :     /** @brief Saves the current state into the given stream
     198              :      */
     199              :     void saveState(std::ostringstream& out, MSTransportable* transportable);
     200              : 
     201              :     /** @brief Reconstructs the current state
     202              :      */
     203              :     void loadState(MSTransportable* transportable, std::istringstream& state);
     204              : 
     205           38 :     bool equals(const MSStage& s) const {
     206           38 :         if (!MSStage::equals(s)) {
     207              :             return false;
     208              :         }
     209              :         // this is safe because MSStage already checked that the type fits
     210              :         const MSStageDriving& sd = static_cast<const MSStageDriving&>(s);
     211           38 :         return myOrigin == sd.myOrigin &&
     212           38 :                myLines == sd.myLines &&
     213           38 :                myIntendedVehicleID == sd.myIntendedVehicleID;
     214              :     }
     215              : 
     216              : protected:
     217              :     /// the origin edge
     218              :     const MSEdge* myOrigin;
     219              : 
     220              :     /// the lines  to choose from
     221              :     const std::set<std::string> myLines;
     222              : 
     223              :     /// @brief The taken vehicle
     224              :     SUMOVehicle* myVehicle;
     225              :     /// @brief cached vehicle data for output after the vehicle has been removed
     226              :     std::string myVehicleID;
     227              :     std::string myVehicleLine;
     228              :     std::string myVehicleType;
     229              : 
     230              :     SUMOVehicleClass myVehicleVClass;
     231              :     double myVehicleDistance;
     232              :     /// @brief While driving, this is the timeLoss of the vehicle when the ride started, after arrival this is the timeLoss which the vehicle accumulated during the ride
     233              :     SUMOTime myTimeLoss;
     234              : 
     235              :     double myWaitingPos;
     236              :     /// @brief The time since which this person is waiting for a ride
     237              :     SUMOTime myWaitingSince;
     238              :     const MSEdge* myWaitingEdge;
     239              :     Position myStopWaitPos;
     240              :     /// @brief the stop at which this ride starts (or nullptr)
     241              :     MSStoppingPlace* myOriginStop;
     242              : 
     243              :     std::string myIntendedVehicleID;
     244              :     SUMOTime myIntendedDepart;
     245              :     double myReservationWaitingPos = INVALID_DOUBLE;
     246              : 
     247              : private:
     248              :     /// brief register waiting person (on proceed or loadState)
     249              :     void registerWaiting(MSTransportable* transportable, SUMOTime now);
     250              : 
     251              : private:
     252              :     /// @brief Invalidated copy constructor.
     253              :     MSStageDriving(const MSStageDriving&);
     254              : 
     255              :     /// @brief Invalidated assignment operator.
     256              :     MSStageDriving& operator=(const MSStageDriving&) = delete;
     257              : 
     258              : private:
     259              :     class BookReservation : public Command {
     260              :     public:
     261          162 :         BookReservation(MSTransportable* transportable, SUMOTime earliestPickupTime, MSStageDriving* stage) :
     262          162 :             myTransportable(transportable), myEarliestPickupTime(earliestPickupTime), myStage(stage), myWaitingPos(stage->myWaitingPos) {}
     263              :         SUMOTime execute(SUMOTime currentTime);
     264              : 
     265              :     public:
     266              :         MSTransportable* myTransportable;
     267              :         SUMOTime myEarliestPickupTime;
     268              :         MSStageDriving* myStage;
     269              :         double myWaitingPos;
     270              :     };
     271              : };
        

Generated by: LCOV version 2.0-1