LCOV - code coverage report
Current view: top level - src/microsim/devices - MSDevice_Tripinfo.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 4 4 100.0 %
Date: 2024-04-30 15:40:33 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /****************************************************************************/
       2             : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3             : // Copyright (C) 2009-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    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             : 
      96             :     static double getAvgWalkRouteLength();
      97             :     static double getAvgWalkDuration();
      98             :     static double getAvgWalkTimeLoss();
      99             : 
     100             :     static double getAvgRideRouteLength();
     101             :     static double getAvgRideWaitingTime();
     102             :     static double getAvgRideDuration();
     103             : 
     104             : public:
     105             :     /// @brief Destructor.
     106             :     ~MSDevice_Tripinfo();
     107             : 
     108             : 
     109             :     /// @brief resets counters
     110             :     static void cleanup();
     111             : 
     112             : 
     113             :     /// @name Methods called on vehicle movement / state change, overwriting MSDevice
     114             :     /// @{
     115             : 
     116             :     /** @brief Checks for waiting steps when the vehicle moves
     117             :      *
     118             :      * @param[in] veh Vehicle that asks this reminder.
     119             :      * @param[in] oldPos Position before move.
     120             :      * @param[in] newPos Position after move with newSpeed.
     121             :      * @param[in] newSpeed Moving speed.
     122             :      * @return True (always).
     123             :      */
     124             :     bool notifyMove(SUMOTrafficObject& veh, double oldPos, double newPos, double newSpeed);
     125             : 
     126             :     /** @brief record idling as waiting time - cf issue 2233
     127             :      *
     128             :      * @param[in] veh The idling vehicle.
     129             :      * @return Always true
     130             :      *
     131             :      * @see MSMoveReminder::notifyIdle
     132             :      */
     133             :     bool notifyIdle(SUMOTrafficObject& veh);
     134             : 
     135             :     /** @brief Saves departure info on insertion
     136             :      *
     137             :      * @param[in] veh The entering vehicle.
     138             :      * @param[in] reason how the vehicle enters the lane
     139             :      * @return Always true
     140             :      * @see MSMoveReminder::notifyEnter
     141             :      * @see MSMoveReminder::Notification
     142             :      */
     143             :     bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
     144             : 
     145             : 
     146             :     /** @brief Saves arrival info
     147             :      *
     148             :      * @param[in] veh The leaving vehicle.
     149             :      * @param[in] lastPos Position on the lane when leaving.
     150             :      * @param[in] isArrival whether the vehicle arrived at its destination
     151             :      * @param[in] isLaneChange whether the vehicle changed from the lane
     152             :      * @return True if it did not leave the net.
     153             :      */
     154             :     bool notifyLeave(SUMOTrafficObject& veh, double lastPos, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
     155             :     /// @}
     156             : 
     157             : 
     158             :     /// @brief return the name for this type of device
     159        2530 :     const std::string deviceName() const {
     160        2530 :         return "tripinfo";
     161             :     }
     162             : 
     163             :     /** @brief Called on writing tripinfo output
     164             :      *
     165             :      * @param[in] os The stream to write the information into
     166             :      * @exception IOError not yet implemented
     167             :      * @see MSDevice::generateOutput
     168             :      */
     169             :     void generateOutput(OutputDevice* tripinfoOut) const;
     170             : 
     171             :     /** @brief Saves the state of the device
     172             :      *
     173             :      * @param[in] out The OutputDevice to write the information into
     174             :      */
     175             :     void saveState(OutputDevice& out) const;
     176             : 
     177             :     /** @brief Loads the state of the device from the given description
     178             :      *
     179             :      * @param[in] attrs XML attributes describing the current state
     180             :      */
     181             :     void loadState(const SUMOSAXAttributes& attrs);
     182             : 
     183             :     /// @brief update stopping time for meso
     184             :     void updateStopTime(const SUMOTime time) {
     185    23089422 :         myStoppingTime += time;
     186    23089422 :     }
     187             : 
     188             : 
     189             :     /// @brief try to retrieve the given parameter from this device. Throw exception for unsupported key
     190             :     std::string getParameter(const std::string& key) const;
     191             : 
     192             :     /// @brief try to retrieve the given parameter from the global statistics. Throw exception for unsupported key
     193             :     static std::string getGlobalParameter(const std::string& prefixedKey);
     194             : 
     195             : private:
     196             :     /** @brief Constructor
     197             :      *
     198             :      * @param[in] holder The vehicle that holds this device
     199             :      * @param[in] id The ID of the device
     200             :      */
     201             :     MSDevice_Tripinfo(SUMOVehicle& holder, const std::string& id);
     202             : 
     203             : 
     204             : protected:
     205             :     /** @brief Internal notification about the vehicle moves, see MSMoveReminder::notifyMoveInternal()
     206             :      *
     207             :      */
     208             :     void notifyMoveInternal(const SUMOTrafficObject& veh,
     209             :                             const double frontOnLane,
     210             :                             const double timeOnLane,
     211             :                             const double meanSpeedFrontOnLane,
     212             :                             const double meanSpeedVehicleOnLane,
     213             :                             const double travelledDistanceFrontOnLane,
     214             :                             const double travelledDistanceVehicleOnLane,
     215             :                             const double meanLengthOnLane);
     216             : 
     217             :     /// @brief update stopping time after parking
     218             :     void updateParkingStopTime();
     219             : 
     220             :     static void printRideStatistics(std::ostringstream& msg, const std::string& category, const std::string& modeName, const int index);
     221             : 
     222             :     static void writeRideStatistics(OutputDevice& od, const std::string& category, const int index);
     223             : 
     224             :     static bool lowAcceleration(const SUMOTrafficObject& veh);
     225             : 
     226             : private:
     227             :     /// @brief The lane the vehicle departed at
     228             :     std::string myDepartLane;
     229             : 
     230             :     /// @brief The speed on departure
     231             :     double myDepartSpeed;
     232             : 
     233             :     /// @brief The lateral depart position
     234             :     double myDepartPosLat;
     235             : 
     236             :     /// @brief The overall waiting time
     237             :     SUMOTime myWaitingTime;
     238             : 
     239             :     /// @brief Whether the vehicle is currently waiting
     240             :     bool myAmWaiting;
     241             : 
     242             :     /// @brief The overall number of unintended stops
     243             :     int myWaitingCount;
     244             : 
     245             :     /// @brief The overall intentional stopping time
     246             :     SUMOTime myStoppingTime;
     247             : 
     248             :     /// @brief The time when parking started
     249             :     SUMOTime myParkingStarted;
     250             : 
     251             :     /// @brief The vehicle's arrival time
     252             :     SUMOTime myArrivalTime;
     253             : 
     254             :     /// @brief The lane the vehicle arrived at
     255             :     std::string myArrivalLane;
     256             : 
     257             :     /// @brief The position on the lane the vehicle arrived at
     258             :     double myArrivalPos;
     259             : 
     260             :     /// @brief The lateral position on the lane the vehicle arrived at
     261             :     double myArrivalPosLat;
     262             : 
     263             :     /// @brief The speed when arriving
     264             :     double myArrivalSpeed;
     265             : 
     266             :     /// @brief The reason for vehicle arrival
     267             :     MSMoveReminder::Notification myArrivalReason;
     268             : 
     269             :     /// @brief The time loss when compared to the desired and allowed speed
     270             :     SUMOTime myMesoTimeLoss;
     271             : 
     272             :     /// @brief The route length
     273             :     double myRouteLength;
     274             : 
     275             :     /// @brief devices which may still need to produce output
     276             :     static std::set<const MSDevice_Tripinfo*, ComparatorNumericalIdLess> myPendingOutput;
     277             : 
     278             :     /// @brief global tripinfo statistics
     279             :     static int myVehicleCount;
     280             :     static int myUndepartedVehicleCount;
     281             :     static double myTotalRouteLength;
     282             :     static double myTotalSpeed;
     283             :     static SUMOTime myTotalDuration;
     284             :     static SUMOTime myTotalWaitingTime;
     285             :     static SUMOTime myTotalTimeLoss;
     286             :     static SUMOTime myTotalDepartDelay;
     287             :     static SUMOTime myWaitingDepartDelay;
     288             : 
     289             :     /// @brief separate values for bicycles
     290             :     static int myBikeCount;
     291             :     static double myTotalBikeRouteLength;
     292             :     static double myTotalBikeSpeed;
     293             :     static SUMOTime myTotalBikeDuration;
     294             :     static SUMOTime myTotalBikeWaitingTime;
     295             :     static SUMOTime myTotalBikeTimeLoss;
     296             : 
     297             :     static int myWalkCount;
     298             :     static double myTotalWalkRouteLength;
     299             :     static SUMOTime myTotalWalkDuration;
     300             :     static SUMOTime myTotalWalkTimeLoss;
     301             : 
     302             :     static std::vector<int> myRideCount;
     303             :     static std::vector<int> myRideBusCount;
     304             :     static std::vector<int> myRideRailCount;
     305             :     static std::vector<int> myRideTaxiCount;
     306             :     static std::vector<int> myRideBikeCount;
     307             :     static std::vector<int> myRideAbortCount;
     308             :     static std::vector<SUMOTime> myTotalRideWaitingTime;
     309             :     static std::vector<double> myTotalRideRouteLength;
     310             :     static std::vector<SUMOTime> myTotalRideDuration;
     311             : 
     312             : private:
     313             :     /// @brief Invalidated copy constructor.
     314             :     MSDevice_Tripinfo(const MSDevice_Tripinfo&);
     315             : 
     316             :     /// @brief Invalidated assignment operator.
     317             :     MSDevice_Tripinfo& operator=(const MSDevice_Tripinfo&);
     318             : 
     319             : 
     320             : };

Generated by: LCOV version 1.14