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: 2025-12-06 15:35:27 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-2025 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      1003367 :     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     15575803 :         return myDestinationStop;
      90              :     }
      91              : 
      92              :     /// returns the origin stop (if any). only needed for MSStageTrip
      93         1575 :     virtual MSStoppingPlace* getOriginStop() const {
      94         1575 :         return nullptr;
      95              :     }
      96              : 
      97       642412 :     virtual double getArrivalPos() const {
      98       642412 :         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          249 :         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       463312 :     virtual SUMOTime getJumpDuration() const {
     134       463312 :         return -1;
     135              :     }
     136              : 
     137              :     ///
     138              :     MSStageType getStageType() const {
     139      8088550 :         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 end of the step
     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              :     /// Whether the transportable waits for the given vehicle
     181              :     virtual bool isWaitingFor(const SUMOVehicle* vehicle) const;
     182              : 
     183              :     /// @brief Whether the transportable waits for a vehicle
     184         3467 :     virtual bool isWaiting4Vehicle() const {
     185         3467 :         return false;
     186              :     }
     187              : 
     188              :     /// @brief Whether the transportable is walking
     189            0 :     virtual bool isWalk() const {
     190            0 :         return false;
     191              :     }
     192              : 
     193              :     /// @brief Current vehicle in which the transportable is driving (or nullptr)
     194       366623 :     virtual SUMOVehicle* getVehicle() const {
     195       366623 :         return nullptr;
     196              :     }
     197              : 
     198              :     /// @brief the speed of the transportable
     199              :     virtual double getSpeed() const;
     200              : 
     201              :     /// @brief the edges of the current stage
     202              :     virtual ConstMSEdgeVector getEdges() const;
     203              : 
     204              :     /// @brief return index of current edge within route
     205         7224 :     virtual int getRoutePosition() const {
     206         7224 :         return 0;
     207              :     }
     208              : 
     209              :     /// @brief get position on edge e at length at with orthogonal offset
     210              :     Position getEdgePosition(const MSEdge* e, double at, double offset) const;
     211              : 
     212              :     /// @brief get position on lane at length at with orthogonal offset
     213              :     Position getLanePosition(const MSLane* lane, double at, double offset) const;
     214              : 
     215              :     /// @brief get angle of the edge at a certain position
     216              :     double getEdgeAngle(const MSEdge* e, double at) const;
     217              : 
     218              :     void setDestination(const MSEdge* newDestination, MSStoppingPlace* newDestStop);
     219              : 
     220         1553 :     virtual void setOrigin(const MSEdge* origin, MSStoppingPlace* originStop, double departPos) {
     221              :         UNUSED_PARAMETER(origin);
     222              :         UNUSED_PARAMETER(originStop);
     223              :         UNUSED_PARAMETER(departPos);
     224         1553 :     }
     225              : 
     226              :     /// @brief get travel distance in this stage
     227              :     virtual double getDistance() const = 0;
     228              : 
     229              :     /** @brief Called on writing tripinfo output
     230              :      * @param[in] os The stream to write the information into
     231              :      * @exception IOError not yet implemented
     232              :      */
     233              :     virtual void tripInfoOutput(OutputDevice& os, const MSTransportable* const transportable) const = 0;
     234              : 
     235              :     /** @brief Called on writing vehroute output
     236              :      * @param[in] isPerson Whether we are writing person or container info
     237              :      * @param[in] os The stream to write the information into
     238              :      * @param[in] withRouteLength whether route length shall be written
     239              :      * @param[in] previous The previous stage for additional info such as from edge
     240              :      * @exception IOError not yet implemented
     241              :      */
     242              :     virtual void routeOutput(const bool isPerson, OutputDevice& os, const bool withRouteLength, const MSStage* const previous) const = 0;
     243              : 
     244              :     virtual MSStage* clone() const = 0;
     245              : 
     246              :     /** @brief Saves the current state into the given stream, standard implementation does nothing
     247              :      */
     248            0 :     virtual void saveState(std::ostringstream& out) {
     249              :         UNUSED_PARAMETER(out);
     250            0 :     }
     251              : 
     252              :     /** @brief Reconstructs the current state, standard implementation does nothing
     253              :      */
     254            0 :     virtual void loadState(MSTransportable* transportable, std::istringstream& state) {
     255              :         UNUSED_PARAMETER(transportable);
     256              :         UNUSED_PARAMETER(state);
     257            0 :     }
     258              : 
     259              :     bool wasSet(int what) const {
     260       207794 :         return (myParametersSet & what) != 0;
     261              :     }
     262              : 
     263              :     void markSet(int what) {
     264        32888 :         myParametersSet |= what;
     265        32888 :     }
     266              : 
     267              :     /** @brief Returns the costs of the stage
     268              :      *
     269              :      * @return The stage's costs (normally the time needed to pass it)
     270              :      */
     271              :     double getCosts() const {
     272          105 :         return myCosts;
     273              :     }
     274              : 
     275              :     /** @brief Sets the costs of the stage
     276              :      *
     277              :      * @param[in] costs The new stage costs
     278              :      */
     279              :     void setCosts(double costs) {
     280       205856 :         myCosts = costs;
     281              :     }
     282              : 
     283              :     MSStageTrip* getTrip() const {
     284         4391 :         return myTrip;
     285              :     }
     286              : 
     287              :     void setTrip(MSStageTrip* trip) {
     288       216041 :         myTrip = trip;
     289              :     }
     290              : 
     291          118 :     virtual bool equals(const MSStage& s) const {
     292          236 :         return myDestination == s.myDestination &&
     293          118 :                myDestinationStop == s.myDestinationStop &&
     294          118 :                myArrivalPos == s.myArrivalPos &&
     295          118 :                myArrivalPosLat == s.myArrivalPosLat &&
     296          236 :                myType == s.myType &&
     297          118 :                myGroup == s.myGroup;
     298              :     }
     299              : 
     300              : protected:
     301              :     /// the next edge to reach by getting transported
     302              :     const MSEdge* myDestination;
     303              : 
     304              :     /// the stop to reach by getting transported (if any)
     305              :     MSStoppingPlace* myDestinationStop;
     306              : 
     307              :     /// @brief the longitudinal position at which we want to arrive
     308              :     double myArrivalPos;
     309              : 
     310              :     /// @brief the lateral position at which we want to arrive
     311              :     double myArrivalPosLat;
     312              : 
     313              :     /// the time at which this stage started
     314              :     SUMOTime myDeparted;
     315              : 
     316              :     /// the time at which this stage ended
     317              :     SUMOTime myArrived;
     318              : 
     319              :     /// The type of this stage
     320              :     MSStageType myType;
     321              : 
     322              :     /// The id of the group of transportables traveling together
     323              :     const std::string myGroup;
     324              : 
     325              :     /// @brief The assigned or calculated costs
     326              :     double myCosts;
     327              : 
     328              :     /// @brief Information on which parameter were set (mainly for vehroute output)
     329              :     int myParametersSet;
     330              : 
     331              :     MSStageTrip* myTrip = nullptr;
     332              : 
     333              :     /// @brief the offset for computing positions when standing at an edge
     334              :     static const double ROADSIDE_OFFSET;
     335              : 
     336              : private:
     337              :     /// @brief Invalidated copy constructor.
     338              :     MSStage(const MSStage&);
     339              : 
     340              :     /// @brief Invalidated assignment operator.
     341              :     MSStage& operator=(const MSStage&) = delete;
     342              : 
     343              : };
        

Generated by: LCOV version 2.0-1