LCOV - code coverage report
Current view: top level - src/microsim/transportables - MSStageDriving.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 16 16
Test Date: 2024-11-21 15:56:26 Functions: 100.0 % 3 3

            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    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              :     bool unspecifiedArrivalPos() const;
      77              : 
      78              :     /// abort this stage (TraCI)
      79              :     void abort(MSTransportable* t);
      80              : 
      81              :     /// initialization, e.g. for param-related events
      82              :     void init(MSTransportable* transportable);
      83              : 
      84              :     /// Returns the current edge
      85              :     const MSEdge* getEdge() const;
      86              :     const MSEdge* getFromEdge() const;
      87              :     double getEdgePos(SUMOTime now) const;
      88              : 
      89              :     /// @brief Return the movement directon on the edge
      90              :     int getDirection() const;
      91              : 
      92              :     const MSLane* getLane() const;
      93              : 
      94        97150 :     MSStoppingPlace* getOriginStop() const {
      95        97150 :         return myOriginStop;
      96              :     }
      97              : 
      98              :     ///
      99              :     Position getPosition(SUMOTime now) const;
     100              : 
     101              :     double getAngle(SUMOTime now) const;
     102              : 
     103              :     /// @brief get travel distance in this stage
     104              :     double getDistance() const;
     105              : 
     106              :     /// @brief return (brief) string representation of the current stage
     107              :     std::string getStageDescription(const bool isPerson) const;
     108              : 
     109              :     /// @brief return string summary of the current stage
     110              :     std::string getStageSummary(const bool isPerson) const;
     111              : 
     112              :     /// proceeds to this stage
     113              :     void proceed(MSNet* net, MSTransportable* transportable, SUMOTime now, MSStage* previous);
     114              : 
     115              :     /** @brief Called on writing tripinfo output
     116              :      * @param[in] os The stream to write the information into
     117              :      * @exception IOError not yet implemented
     118              :      */
     119              :     void tripInfoOutput(OutputDevice& os, const MSTransportable* const transportable) const;
     120              : 
     121              :     /** @brief Called on writing vehroute output
     122              :      * @param[in] isPerson Whether we are writing person or container info
     123              :      * @param[in] os The stream to write the information into
     124              :      * @param[in] withRouteLength whether route length shall be written
     125              :      * @param[in] previous The previous stage for additional info such as from edge
     126              :      * @exception IOError not yet implemented
     127              :      */
     128              :     void routeOutput(const bool isPerson, OutputDevice& os, const bool withRouteLength, const MSStage* const previous) const;
     129              : 
     130              :     /// Whether the person waits for the given vehicle
     131              :     bool isWaitingFor(const SUMOVehicle* vehicle) const;
     132              : 
     133              :     /// @brief Whether the person waits for a vehicle
     134              :     bool isWaiting4Vehicle() const;
     135              : 
     136              :     /// @brief Return where the person waits and for what
     137              :     std::string getWaitingDescription() const;
     138              : 
     139        71978 :     SUMOVehicle* getVehicle() const {
     140        71978 :         return myVehicle;
     141              :     }
     142              : 
     143              :     /// @brief time spent waiting for a ride
     144              :     SUMOTime getWaitingTime(SUMOTime now) const;
     145              : 
     146              :     double getSpeed() const;
     147              : 
     148              :     ConstMSEdgeVector getEdges() const;
     149              : 
     150              :     void setVehicle(SUMOVehicle* v);
     151              : 
     152              :     /// @brief marks arrival time and records driven distance
     153              :     const std::string setArrived(MSNet* net, MSTransportable* transportable, SUMOTime now, const bool vehicleArrived);
     154              : 
     155              :     const std::set<std::string>& getLines() const {
     156        74077 :         return myLines;
     157              :     }
     158              : 
     159              :     std::string getIntendedVehicleID() const {
     160          410 :         return myIntendedVehicleID;
     161              :     }
     162              : 
     163              :     SUMOTime getIntendedDepart() const {
     164           79 :         return myIntendedDepart;
     165              :     }
     166              : 
     167              :     std::string getVehicleType() const {
     168          410 :         return myVehicleType;
     169              :     }
     170              : 
     171              :     /// change origin for parking area rerouting
     172              :     void setOrigin(const MSEdge* origin) {
     173           10 :         myOrigin = origin;
     174              :     }
     175              : 
     176              :     /// @brief checks whether the person may exit at the current vehicle position
     177              :     bool canLeaveVehicle(const MSTransportable* t, const SUMOVehicle& veh, const MSStop& stop);
     178              : 
     179              :     SUMOTime getTimeLoss(const MSTransportable* transportable) const;
     180              :     SUMOTime getDuration() const;
     181              :     SUMOTime getTravelTime() const;
     182              :     SUMOTime getWaitingTime() const;
     183              : 
     184              :     /** @brief Saves the current state into the given stream
     185              :      */
     186              :     void saveState(std::ostringstream& out);
     187              : 
     188              :     /** @brief Reconstructs the current state
     189              :      */
     190              :     void loadState(MSTransportable* transportable, std::istringstream& state);
     191              : 
     192           38 :     bool equals(const MSStage& s) const {
     193           38 :         if (!MSStage::equals(s)) {
     194              :             return false;
     195              :         }
     196              :         // this is safe because MSStage already checked that the type fits
     197              :         const MSStageDriving& sd = static_cast<const MSStageDriving&>(s);
     198           38 :         return myOrigin == sd.myOrigin &&
     199           38 :                myLines == sd.myLines &&
     200           32 :                myIntendedVehicleID == sd.myIntendedVehicleID;
     201              :     }
     202              : 
     203              : protected:
     204              :     /// the origin edge
     205              :     const MSEdge* myOrigin;
     206              : 
     207              :     /// the lines  to choose from
     208              :     const std::set<std::string> myLines;
     209              : 
     210              :     /// @brief The taken vehicle
     211              :     SUMOVehicle* myVehicle;
     212              :     /// @brief cached vehicle data for output after the vehicle has been removed
     213              :     std::string myVehicleID;
     214              :     std::string myVehicleLine;
     215              :     std::string myVehicleType;
     216              : 
     217              :     SUMOVehicleClass myVehicleVClass;
     218              :     double myVehicleDistance;
     219              :     /// @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
     220              :     SUMOTime myTimeLoss;
     221              : 
     222              :     double myWaitingPos;
     223              :     /// @brief The time since which this person is waiting for a ride
     224              :     SUMOTime myWaitingSince;
     225              :     const MSEdge* myWaitingEdge;
     226              :     Position myStopWaitPos;
     227              :     /// @brief the stop at which this ride starts (or nullptr)
     228              :     MSStoppingPlace* myOriginStop;
     229              : 
     230              :     std::string myIntendedVehicleID;
     231              :     SUMOTime myIntendedDepart;
     232              : 
     233              : 
     234              : private:
     235              :     /// brief register waiting person (on proceed or loadState)
     236              :     void registerWaiting(MSTransportable* transportable, SUMOTime now);
     237              : 
     238              : private:
     239              :     /// @brief Invalidated copy constructor.
     240              :     MSStageDriving(const MSStageDriving&);
     241              : 
     242              :     /// @brief Invalidated assignment operator.
     243              :     MSStageDriving& operator=(const MSStageDriving&) = delete;
     244              : 
     245              : private:
     246              :     class BookReservation : public Command {
     247              :     public:
     248          162 :         BookReservation(MSTransportable* transportable, SUMOTime earliestPickupTime, MSStageDriving* stage) :
     249          162 :             myTransportable(transportable), myEarliestPickupTime(earliestPickupTime), myStage(stage), myWaitingPos(stage->myWaitingPos) {}
     250              :         SUMOTime execute(SUMOTime currentTime);
     251              : 
     252              :     public:
     253              :         MSTransportable* myTransportable;
     254              :         SUMOTime myEarliestPickupTime;
     255              :         MSStageDriving* myStage;
     256              :         double myWaitingPos;
     257              :     };
     258              : 
     259              : protected:
     260              :     BookReservation* myReservationCommand;
     261              : 
     262              : };
        

Generated by: LCOV version 2.0-1