LCOV - code coverage report
Current view: top level - src/microsim/transportables - MSStage.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 80.0 % 45 36
Test Date: 2026-05-24 16:29:35 Functions: 68.8 % 16 11

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

Generated by: LCOV version 2.0-1