LCOV - code coverage report
Current view: top level - src/microsim/transportables - MSStageDriving.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 11 11 100.0 %
Date: 2024-05-06 15:32:35 Functions: 2 2 100.0 %

          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       46339 :     MSStoppingPlace* getOriginStop() const {
      95       46339 :         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       29884 :     SUMOVehicle* getVehicle() const {
     140       29884 :         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       40178 :         return myLines;
     157             :     }
     158             : 
     159             :     std::string getIntendedVehicleID() const {
     160         543 :         return myIntendedVehicleID;
     161             :     }
     162             : 
     163             :     SUMOTime getIntendedDepart() const {
     164         104 :         return myIntendedDepart;
     165             :     }
     166             : 
     167             :     std::string getVehicleType() const {
     168         543 :         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 getWaitingTime() const;
     181             : 
     182             :     /** @brief Saves the current state into the given stream
     183             :      */
     184             :     void saveState(std::ostringstream& out);
     185             : 
     186             :     /** @brief Reconstructs the current state
     187             :      */
     188             :     void loadState(MSTransportable* transportable, std::istringstream& state);
     189             : 
     190             : protected:
     191             :     /// the origin edge
     192             :     const MSEdge* myOrigin;
     193             : 
     194             :     /// the lines  to choose from
     195             :     const std::set<std::string> myLines;
     196             : 
     197             :     /// @brief The taken vehicle
     198             :     SUMOVehicle* myVehicle;
     199             :     /// @brief cached vehicle data for output after the vehicle has been removed
     200             :     std::string myVehicleID;
     201             :     std::string myVehicleLine;
     202             :     std::string myVehicleType;
     203             : 
     204             :     SUMOVehicleClass myVehicleVClass;
     205             :     double myVehicleDistance;
     206             :     /// @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
     207             :     SUMOTime myTimeLoss;
     208             : 
     209             :     double myWaitingPos;
     210             :     /// @brief The time since which this person is waiting for a ride
     211             :     SUMOTime myWaitingSince;
     212             :     const MSEdge* myWaitingEdge;
     213             :     Position myStopWaitPos;
     214             :     /// @brief the stop at which this ride starts (or nullptr)
     215             :     MSStoppingPlace* myOriginStop;
     216             : 
     217             :     std::string myIntendedVehicleID;
     218             :     SUMOTime myIntendedDepart;
     219             : 
     220             : 
     221             : private:
     222             :     /// brief register waiting person (on proceed or loadState)
     223             :     void registerWaiting(MSTransportable* transportable, SUMOTime now);
     224             : 
     225             : private:
     226             :     /// @brief Invalidated copy constructor.
     227             :     MSStageDriving(const MSStageDriving&);
     228             : 
     229             :     /// @brief Invalidated assignment operator.
     230             :     MSStageDriving& operator=(const MSStageDriving&) = delete;
     231             : 
     232             : private:
     233             :     class BookReservation : public Command {
     234             :     public:
     235          78 :         BookReservation(MSTransportable* transportable, SUMOTime earliestPickupTime, MSStageDriving* stage) :
     236          78 :             myTransportable(transportable), myEarliestPickupTime(earliestPickupTime), myStage(stage), myWaitingPos(stage->myWaitingPos) {}
     237             :         SUMOTime execute(SUMOTime currentTime);
     238             : 
     239             :     public:
     240             :         MSTransportable* myTransportable;
     241             :         SUMOTime myEarliestPickupTime;
     242             :         MSStageDriving* myStage;
     243             :         double myWaitingPos;
     244             :     };
     245             : 
     246             : protected:
     247             :     BookReservation* myReservationCommand;
     248             : 
     249             : };

Generated by: LCOV version 1.14