LCOV - code coverage report
Current view: top level - src/microsim/devices - MSDevice_Tripinfo.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 4 4
Test Date: 2025-11-13 15:38:19 Functions: 100.0 % 1 1

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2009-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    MSDevice_Tripinfo.h
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Michael Behrisch
      17              : /// @author  Jakob Erdmann
      18              : /// @date    Fri, 30.01.2009
      19              : ///
      20              : // A device which collects info on the vehicle trip
      21              : /****************************************************************************/
      22              : #pragma once
      23              : #include <config.h>
      24              : 
      25              : #include "MSVehicleDevice.h"
      26              : #include <utils/common/SUMOTime.h>
      27              : 
      28              : // ===========================================================================
      29              : // class declarations
      30              : // ===========================================================================
      31              : class SUMOVehicle;
      32              : class SUMOTrafficObject;
      33              : 
      34              : // ===========================================================================
      35              : // class definitions
      36              : // ===========================================================================
      37              : /**
      38              :  * @class MSDevice_Tripinfo
      39              :  * @brief A device which collects info on the vehicle trip (mainly on departure and arrival)
      40              :  *
      41              :  * Each device collects departure time, lane and speed and the same for arrival.
      42              :  *
      43              :  * @see MSDevice
      44              :  */
      45              : class MSDevice_Tripinfo : public MSVehicleDevice {
      46              : public:
      47              :     /** @brief Inserts MSDevice_Tripinfo-options
      48              :      * @param[filled] oc The options container to add the options to
      49              :      */
      50              :     static void insertOptions(OptionsCont& oc);
      51              : 
      52              :     /** @brief Build devices for the given vehicle, if needed
      53              :      *
      54              :      * The options are read and evaluated whether a tripinfo-device shall be built
      55              :      *  for the given vehicle.
      56              :      *
      57              :      * The built device is stored in the given vector.
      58              :      *
      59              :      * @param[in] v The vehicle for which a device may be built
      60              :      * @param[filled] into The vector to store the built device in
      61              :      */
      62              :     static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into);
      63              : 
      64              :     /// @brief generate output for vehicles which are still in the network
      65              :     static void generateOutputForUnfinished();
      66              : 
      67              :     /// @brief record tripinfo data for pedestrians
      68              :     static void addPedestrianData(double walkLength, SUMOTime walkDuration, SUMOTime walkTimeLoss);
      69              : 
      70              :     /// @brief record tripinfo data for rides and transports
      71              :     static void addRideTransportData(const bool isPerson, const double distance, const SUMOTime duration,
      72              :                                      const SUMOVehicleClass vClass, const std::string& line, const SUMOTime waitingTime);
      73              : 
      74              :     /// @brief get statistics for printing to stdout
      75              :     static std::string printStatistics();
      76              : 
      77              :     /// @brief write statistic output to (xml) file
      78              :     static void writeStatistics(OutputDevice& od);
      79              : 
      80              :     /// @brief accessors for GUINet-Parameters
      81              :     static double getAvgRouteLength();
      82              :     static double getAvgTripSpeed();
      83              :     static double getAvgDuration();
      84              :     static double getAvgWaitingTime();
      85              :     static double getAvgTimeLoss();
      86              :     static double getAvgDepartDelay();
      87              :     static double getAvgDepartDelayWaiting();
      88              :     static double getTotalDepartDelay();
      89              : 
      90              :     static double getAvgBikeRouteLength();
      91              :     static double getAvgBikeTripSpeed();
      92              :     static double getAvgBikeDuration();
      93              :     static double getAvgBikeWaitingTime();
      94              :     static double getAvgBikeTimeLoss();
      95              :     static double getAvgBikeDepartDelay();
      96              :     static double getTotalBikeDepartDelay();
      97              : 
      98              :     static double getAvgWalkRouteLength();
      99              :     static double getAvgWalkDuration();
     100              :     static double getAvgWalkTimeLoss();
     101              : 
     102              :     static double getAvgRideRouteLength();
     103              :     static double getAvgRideWaitingTime();
     104              :     static double getAvgRideDuration();
     105              : 
     106              : public:
     107              :     /// @brief Destructor.
     108              :     ~MSDevice_Tripinfo();
     109              : 
     110              : 
     111              :     /// @brief resets counters
     112              :     static void cleanup();
     113              : 
     114              : 
     115              :     /// @name Methods called on vehicle movement / state change, overwriting MSDevice
     116              :     /// @{
     117              : 
     118              :     /** @brief Checks for waiting steps when the vehicle moves
     119              :      *
     120              :      * @param[in] veh Vehicle that asks this reminder.
     121              :      * @param[in] oldPos Position before move.
     122              :      * @param[in] newPos Position after move with newSpeed.
     123              :      * @param[in] newSpeed Moving speed.
     124              :      * @return True (always).
     125              :      */
     126              :     bool notifyMove(SUMOTrafficObject& veh, double oldPos, double newPos, double newSpeed);
     127              : 
     128              :     /** @brief record idling as waiting time - cf issue 2233
     129              :      *
     130              :      * @param[in] veh The idling vehicle.
     131              :      * @return Always true
     132              :      *
     133              :      * @see MSMoveReminder::notifyIdle
     134              :      */
     135              :     bool notifyIdle(SUMOTrafficObject& veh);
     136              : 
     137              :     /** @brief Saves departure info on insertion
     138              :      *
     139              :      * @param[in] veh The entering vehicle.
     140              :      * @param[in] reason how the vehicle enters the lane
     141              :      * @return Always true
     142              :      * @see MSMoveReminder::notifyEnter
     143              :      * @see MSMoveReminder::Notification
     144              :      */
     145              :     bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
     146              : 
     147              : 
     148              :     /** @brief Saves arrival info
     149              :      *
     150              :      * @param[in] veh The leaving vehicle.
     151              :      * @param[in] lastPos Position on the lane when leaving.
     152              :      * @param[in] isArrival whether the vehicle arrived at its destination
     153              :      * @param[in] isLaneChange whether the vehicle changed from the lane
     154              :      * @return True if it did not leave the net.
     155              :      */
     156              :     bool notifyLeave(SUMOTrafficObject& veh, double lastPos, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
     157              :     /// @}
     158              : 
     159              : 
     160              :     /// @brief return the name for this type of device
     161         2850 :     const std::string deviceName() const {
     162         2850 :         return "tripinfo";
     163              :     }
     164              : 
     165              :     /** @brief Called on writing tripinfo output
     166              :      *
     167              :      * @param[in] os The stream to write the information into
     168              :      * @exception IOError not yet implemented
     169              :      * @see MSDevice::generateOutput
     170              :      */
     171              :     void generateOutput(OutputDevice* tripinfoOut) const;
     172              : 
     173              :     /** @brief Saves the state of the device
     174              :      *
     175              :      * @param[in] out The OutputDevice to write the information into
     176              :      */
     177              :     void saveState(OutputDevice& out) const;
     178              : 
     179              :     /** @brief Loads the state of the device from the given description
     180              :      *
     181              :      * @param[in] attrs XML attributes describing the current state
     182              :      */
     183              :     void loadState(const SUMOSAXAttributes& attrs);
     184              : 
     185              :     /// @brief update stopping time for meso
     186              :     void updateStopTime(const SUMOTime time) {
     187     13253888 :         myStoppingTime += time;
     188     13253888 :     }
     189              : 
     190              : 
     191              :     /// @brief try to retrieve the given parameter from this device. Throw exception for unsupported key
     192              :     std::string getParameter(const std::string& key) const;
     193              : 
     194              :     /// @brief try to retrieve the given parameter from the global statistics. Throw exception for unsupported key
     195              :     static std::string getGlobalParameter(const std::string& prefixedKey);
     196              : 
     197              : private:
     198              :     /** @brief Constructor
     199              :      *
     200              :      * @param[in] holder The vehicle that holds this device
     201              :      * @param[in] id The ID of the device
     202              :      */
     203              :     MSDevice_Tripinfo(SUMOVehicle& holder, const std::string& id);
     204              : 
     205              : 
     206              : protected:
     207              :     /** @brief Internal notification about the vehicle moves, see MSMoveReminder::notifyMoveInternal()
     208              :      *
     209              :      */
     210              :     void notifyMoveInternal(const SUMOTrafficObject& veh,
     211              :                             const double frontOnLane,
     212              :                             const double timeOnLane,
     213              :                             const double meanSpeedFrontOnLane,
     214              :                             const double meanSpeedVehicleOnLane,
     215              :                             const double travelledDistanceFrontOnLane,
     216              :                             const double travelledDistanceVehicleOnLane,
     217              :                             const double meanLengthOnLane);
     218              : 
     219              :     /// @brief update stopping time after parking
     220              :     void updateParkingStopTime();
     221              : 
     222              :     static void printRideStatistics(std::ostringstream& msg, const std::string& category, const std::string& modeName, const int index);
     223              : 
     224              :     static void writeRideStatistics(OutputDevice& od, const std::string& category, const int index);
     225              : 
     226              :     static bool lowAcceleration(const SUMOTrafficObject& veh);
     227              : 
     228              : private:
     229              :     /// @brief The lane the vehicle departed at
     230              :     std::string myDepartLane;
     231              : 
     232              :     /// @brief The speed on departure
     233              :     double myDepartSpeed;
     234              : 
     235              :     /// @brief The lateral depart position
     236              :     double myDepartPosLat;
     237              : 
     238              :     /// @brief The overall waiting time
     239              :     SUMOTime myWaitingTime;
     240              : 
     241              :     /// @brief Whether the vehicle is currently waiting
     242              :     bool myAmWaiting;
     243              : 
     244              :     /// @brief The overall number of unintended stops
     245              :     int myWaitingCount;
     246              : 
     247              :     /// @brief The overall intentional stopping time
     248              :     SUMOTime myStoppingTime;
     249              : 
     250              :     /// @brief The time when parking started
     251              :     SUMOTime myParkingStarted;
     252              : 
     253              :     /// @brief The vehicle's arrival time
     254              :     SUMOTime myArrivalTime;
     255              : 
     256              :     /// @brief The lane the vehicle arrived at
     257              :     std::string myArrivalLane;
     258              : 
     259              :     /// @brief The position on the lane the vehicle arrived at
     260              :     double myArrivalPos;
     261              : 
     262              :     /// @brief The lateral position on the lane the vehicle arrived at
     263              :     double myArrivalPosLat;
     264              : 
     265              :     /// @brief The speed when arriving
     266              :     double myArrivalSpeed;
     267              : 
     268              :     /// @brief The reason for vehicle arrival
     269              :     MSMoveReminder::Notification myArrivalReason;
     270              : 
     271              :     /// @brief The time loss when compared to the desired and allowed speed
     272              :     SUMOTime myMesoTimeLoss;
     273              : 
     274              :     /// @brief The route length
     275              :     double myRouteLength;
     276              : 
     277              :     /// @brief devices which may still need to produce output
     278              :     static std::set<const MSDevice_Tripinfo*, ComparatorNumericalIdLess> myPendingOutput;
     279              : 
     280              :     /// @brief global tripinfo statistics
     281              :     static int myVehicleCount;
     282              :     static int myUndepartedVehicleCount;
     283              :     static double myTotalRouteLength;
     284              :     static double myTotalSpeed;
     285              :     static SUMOTime myTotalDuration;
     286              :     static SUMOTime myTotalWaitingTime;
     287              :     static SUMOTime myTotalTimeLoss;
     288              :     static SUMOTime myTotalDepartDelay;
     289              :     static SUMOTime myWaitingDepartDelay;
     290              : 
     291              :     /// @brief separate values for bicycles
     292              :     static int myBikeCount;
     293              :     static double myTotalBikeRouteLength;
     294              :     static double myTotalBikeSpeed;
     295              :     static SUMOTime myTotalBikeDuration;
     296              :     static SUMOTime myTotalBikeWaitingTime;
     297              :     static SUMOTime myTotalBikeTimeLoss;
     298              :     static SUMOTime myTotalBikeDepartDelay;
     299              : 
     300              :     static int myWalkCount;
     301              :     static double myTotalWalkRouteLength;
     302              :     static SUMOTime myTotalWalkDuration;
     303              :     static SUMOTime myTotalWalkTimeLoss;
     304              : 
     305              :     static std::vector<int> myRideCount;
     306              :     static std::vector<int> myRideBusCount;
     307              :     static std::vector<int> myRideRailCount;
     308              :     static std::vector<int> myRideTaxiCount;
     309              :     static std::vector<int> myRideBikeCount;
     310              :     static std::vector<int> myRideAbortCount;
     311              :     static std::vector<SUMOTime> myTotalRideWaitingTime;
     312              :     static std::vector<double> myTotalRideRouteLength;
     313              :     static std::vector<SUMOTime> myTotalRideDuration;
     314              : 
     315              : private:
     316              :     /// @brief Invalidated copy constructor.
     317              :     MSDevice_Tripinfo(const MSDevice_Tripinfo&);
     318              : 
     319              :     /// @brief Invalidated assignment operator.
     320              :     MSDevice_Tripinfo& operator=(const MSDevice_Tripinfo&);
     321              : 
     322              : 
     323              : };
        

Generated by: LCOV version 2.0-1