LCOV - code coverage report
Current view: top level - src/microsim/transportables - MSTransportableControl.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 23 26 88.5 %
Date: 2024-05-07 15:28:01 Functions: 0 3 0.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    MSTransportableControl.h
      15             : /// @author  Daniel Krajzewicz
      16             : /// @author  Jakob Erdmann
      17             : /// @author  Sascha Krieg
      18             : /// @author  Michael Behrisch
      19             : /// @date    Mon, 9 Jul 2001
      20             : ///
      21             : // Stores all persons or containers in the net and handles their waiting for cars.
      22             : /****************************************************************************/
      23             : #pragma once
      24             : #include <config.h>
      25             : 
      26             : #include <vector>
      27             : #include <map>
      28             : #include <microsim/MSVehicle.h>
      29             : #include <microsim/transportables/MSTransportable.h>
      30             : #include <microsim/devices/MSDevice_Vehroutes.h>
      31             : 
      32             : 
      33             : // ===========================================================================
      34             : // class declarations
      35             : // ===========================================================================
      36             : class MSNet;
      37             : class MSPModel;
      38             : 
      39             : 
      40             : // ===========================================================================
      41             : // class definitions
      42             : // ===========================================================================
      43             : /**
      44             :  *
      45             :  * @class MSTransportableControl
      46             :  * The class is used to handle transportables (persons and containers)
      47             :  *  who are not using a transportation
      48             :  *  system but are walking or waiting. This includes waiting
      49             :  *  for the arrival or departure time / the time the waiting is over.
      50             :  */
      51             : class MSTransportableControl {
      52             : public:
      53             :     /// @brief Definition of a list of transportables
      54             :     typedef std::vector<MSTransportable*> TransportableVector;
      55             : 
      56             :     /// @brief Definition of the internal transportables map iterator
      57             :     typedef std::map<std::string, MSTransportable*>::const_iterator constVehIt;
      58             : 
      59             : 
      60             : public:
      61             :     /// @brief Constructor
      62             :     MSTransportableControl(const bool isPerson);
      63             : 
      64             : 
      65             :     /// @brief Destructor
      66             :     virtual ~MSTransportableControl();
      67             : 
      68             : 
      69             :     /** @brief Adds a single transportable, returns false if an id clash occurred
      70             :      * @param[in] transportable The transportable to add
      71             :      * @return Whether the transportable could be added (none with the same id existed before)
      72             :      */
      73             :     bool add(MSTransportable* transportable);
      74             : 
      75             : 
      76             :     /** @brief Returns the named transportable, if existing
      77             :      * @param[in] id The id of the transportable
      78             :      * @return The named transportable, if existing, otherwise nullptr
      79             :      */
      80             :     MSTransportable* get(const std::string& id) const;
      81             : 
      82             : 
      83             :     /// removes a single transportable
      84             :     virtual void erase(MSTransportable* transportable);
      85             : 
      86             :     /// sets the arrival time for a waiting transportable
      87             :     void setWaitEnd(SUMOTime time, MSTransportable* transportable);
      88             : 
      89             :     /// checks whether any transportables waiting time is over
      90             :     void checkWaiting(MSNet* net, const SUMOTime time);
      91             : 
      92             :     /// adds a transportable to the list of transportables waiting for a vehicle on the specified edge
      93             :     void addWaiting(const MSEdge* edge, MSTransportable* person);
      94             : 
      95             :     /// register forced (traci) departure
      96             :     void forceDeparture();
      97             : 
      98             :     /// @brief check whether any transportables are waiting for the given vehicle
      99             :     bool hasAnyWaiting(const MSEdge* edge, SUMOVehicle* vehicle) const;
     100             : 
     101             :     /** @brief load any applicable transportables
     102             :     * Loads any person / container that is waiting on that edge for the given vehicle and removes them from myWaiting
     103             :     * @param[in] edge the edge on which the loading should take place
     104             :     * @param[in] vehicle the vehicle which is taking on containers
     105             :     * @param[in,out] timeToLoadNext earliest time for the next loading process (gets updated)
     106             :     * @param[in,out] stopDuration the duration of the stop where the loading takes place (might be extended)
     107             :     * @return Whether any transportables have been loaded
     108             :     */
     109             :     bool loadAnyWaiting(const MSEdge* edge, SUMOVehicle* vehicle, SUMOTime& timeToLoadNext, SUMOTime& stopDuration);
     110             : 
     111             :     /// checks whether any transportable waits to finish her plan
     112             :     bool hasTransportables() const;
     113             : 
     114             :     /// checks whether any transportable is still engaged in walking / stopping
     115             :     bool hasNonWaiting() const;
     116             : 
     117             :     /// @brief return the number of active transportable objects
     118             :     int getActiveCount();
     119             : 
     120             :     /// aborts the plan for any transportable that is still waiting for a ride
     121             :     void abortAnyWaitingForVehicle();
     122             : 
     123             :     /// let the given transportable abort waiting for a vehicle (when removing stage via TraCI)
     124             :     void abortWaitingForVehicle(MSTransportable* t);
     125             : 
     126             :     /// aborts waiting stage of transportable
     127             :     void abortWaiting(MSTransportable* t);
     128             : 
     129             :     /** @brief Builds a new person
     130             :      * @param[in] pars The parameter
     131             :      * @param[in] vtype The type (reusing vehicle type container here)
     132             :      * @param[in] plan This person's plan
     133             :      * @param[in] rng The RNG to compute the optional speed deviation
     134             :      */
     135             :     virtual MSTransportable* buildPerson(const SUMOVehicleParameter* pars, MSVehicleType* vtype, MSTransportable::MSTransportablePlan* plan,
     136             :                                          SumoRNG* rng) const;
     137             : 
     138             :     /** @brief Builds a new container
     139             :     * @param[in] pars The parameter
     140             :     * @param[in] vtype The type (reusing vehicle type container here)
     141             :     * @param[in] plan This container's plan
     142             :     */
     143             :     virtual MSTransportable* buildContainer(const SUMOVehicleParameter* pars, MSVehicleType* vtype, MSTransportable::MSTransportablePlan* plan) const;
     144             : 
     145             :     /** @brief Returns the begin of the internal transportables map
     146             :      * @return The begin of the internal transportables map
     147             :      */
     148             :     constVehIt loadedBegin() const {
     149             :         return myTransportables.begin();
     150             :     }
     151             : 
     152             : 
     153             :     /** @brief Returns the end of the internal transportables map
     154             :      * @return The end of the internal transportables map
     155             :      */
     156             :     constVehIt loadedEnd() const {
     157             :         return myTransportables.end();
     158             :     }
     159             : 
     160             : 
     161             :     /** @brief Returns the number of known transportables
     162             :      * @return The number of stored transportables
     163             :      */
     164             :     int size() const {
     165          26 :         return (int)myTransportables.size();
     166             :     }
     167             : 
     168             :     /// @brief register a jammed transportable
     169             :     void registerJammed() {
     170       63115 :         myJammedNumber++;
     171             :     }
     172             : 
     173             :     /// @brief register a teleport after aborting a long wait
     174             :     void registerTeleportAbortWait() {
     175          16 :         myTeleportsAbortWait++;
     176             :     }
     177             : 
     178             :     /// @brief register a teleport to the final destination
     179             :     void registerTeleportWrongDest() {
     180          30 :         myTeleportsWrongDest++;
     181          30 :     }
     182             : 
     183             :     /// @brief decrement counter to avoid double counting transportables loaded from state
     184             :     void fixLoadCount(const MSTransportable* transportable);
     185             : 
     186             :     /// @name Retrieval of transportable statistics (always accessible)
     187             :     /// @{
     188             : 
     189             :     /** @brief Returns the number of build transportables
     190             :      * @return The number of loaded (build) transportables
     191             :      */
     192           0 :     int getLoadedNumber() const {
     193      465707 :         return myLoadedNumber;
     194             :     }
     195             : 
     196             :     int getDepartedNumber() const;
     197             : 
     198             :     /** @brief Returns the number of build and inserted, but not yet deleted transportables
     199             :      * @return The number of simulated transportables
     200             :      */
     201           0 :     int getRunningNumber() const {
     202     2961242 :         return myRunningNumber;
     203             :     }
     204             : 
     205             :     /** @brief Returns the number of times a transportables was jammed
     206             :      * @return The number of times transportables were jammed
     207             :      */
     208           0 :     int getJammedNumber() const {
     209        7000 :         return myJammedNumber;
     210             :     }
     211             : 
     212             :     /** @brief Returns the number of transportables waiting for a ride
     213             :      */
     214             :     int getWaitingForVehicleNumber() const {
     215        4752 :         return myWaitingForVehicleNumber;
     216             :     }
     217             : 
     218             :     /** @brief Returns the number of transportables waiting for a specified
     219             :      * amount of time
     220             :      */
     221             :     int getWaitingUntilNumber() const {
     222        4752 :         return myWaitingUntilNumber;
     223             :     }
     224             : 
     225             :     /** @brief Returns the number of transportables moving by themselvs (i.e. walking)
     226             :      */
     227             :     int getMovingNumber() const;
     228             : 
     229             :     /** @brief Returns the number of transportables riding a vehicle
     230             :      */
     231             :     int getRidingNumber() const;
     232             : 
     233             :     /** @brief Returns the number of transportables that exited the simulation
     234             :      */
     235             :     int getEndedNumber() const {
     236        4752 :         return myEndedNumber;
     237             :     }
     238             : 
     239             :     /** @brief Returns the number of transportables that arrived at their
     240             :      * destination
     241             :      */
     242             :     int getArrivedNumber() const {
     243        4752 :         return myArrivedNumber;
     244             :     }
     245             : 
     246             :     /// @brief return the number of teleports due to excessive waiting for a ride
     247             :     int getTeleportsAbortWait() const {
     248          17 :         return myTeleportsAbortWait;
     249             :     }
     250             : 
     251             :     /// @brief return the number of teleports of transportables riding to the wrong destination
     252             :     int getTeleportsWrongDest() const {
     253          24 :         return myTeleportsWrongDest;
     254             :     }
     255             : 
     256             :     /// @brief Returns the number of teleports transportables did
     257             :     int getTeleportCount() const {
     258        6945 :         return myTeleportsAbortWait + myTeleportsWrongDest;
     259             :     }
     260             : 
     261             :     /// @}
     262             : 
     263             :     /** @brief Returns the default movement model for this kind of transportables
     264             :      * @return The movement model
     265             :      */
     266             :     inline MSPModel* getMovementModel() {
     267     8083134 :         return myMovementModel;
     268             :     }
     269             : 
     270             :     /** @brief Returns the non interacting movement model (for tranship and "beaming")
     271             :      * @return The non interacting movement model
     272             :      */
     273             :     inline MSPModel* getNonInteractingModel() {
     274      109548 :         return myNonInteractingModel;
     275             :     }
     276             : 
     277             :     void addArrived() {
     278      408197 :         myArrivedNumber++;
     279             :     }
     280             : 
     281             :     void addDiscarded() {
     282          56 :         myLoadedNumber++;
     283          56 :         myDiscardedNumber++;
     284          56 :     }
     285             : 
     286             :     void startedAccess() {
     287        5024 :         myAccessNumber++;
     288             :     }
     289             : 
     290             :     void endedAccess() {
     291        4992 :         myAccessNumber--;
     292             :     }
     293             : 
     294             :     /** @brief Saves the current state into the given stream
     295             :      */
     296             :     void saveState(OutputDevice& out);
     297             : 
     298             :     /** @brief Reconstruct the current state
     299             :      */
     300             :     void loadState(const std::string& state);
     301             : 
     302             :     /// @brief Resets transportables when quick-loading state
     303             :     void clearState();
     304             : 
     305             :     const MSDevice_Vehroutes::SortedRouteInfo& getRouteInfo() {
     306             :         return myRouteInfos;
     307             :     }
     308             : 
     309             : protected:
     310             :     /// all currently created transportables by id
     311             :     std::map<std::string, MSTransportable*> myTransportables;
     312             : 
     313             :     /// @brief Transportables waiting for departure
     314             :     std::map<SUMOTime, TransportableVector> myWaiting4Departure;
     315             : 
     316             :     /// the lists of walking / stopping transportables
     317             :     std::map<SUMOTime, TransportableVector> myWaitingUntil;
     318             : 
     319             :     /// the lists of waiting transportables
     320             :     std::map<const MSEdge*, TransportableVector, ComparatorNumericalIdLess> myWaiting4Vehicle;
     321             : 
     322             :     /// @brief The number of build transportables
     323             :     int myLoadedNumber;
     324             : 
     325             :     /// @brief The number of discarded transportables
     326             :     int myDiscardedNumber;
     327             : 
     328             :     /// @brief The number of transportables within the network (build and inserted but not removed)
     329             :     int myRunningNumber;
     330             : 
     331             :     /// @brief The number of jammed transportables
     332             :     int myJammedNumber;
     333             : 
     334             :     /// @brief The number of transportables waiting for departure
     335             :     int myWaitingForDepartureNumber;
     336             : 
     337             :     /// @brief The number of transportables waiting for vehicles
     338             :     int myWaitingForVehicleNumber;
     339             : 
     340             :     /// @brief The number of transportables waiting for a specified time
     341             :     int myWaitingUntilNumber;
     342             : 
     343             :     /// @brief The number of transportables currently in an access stage
     344             :     int myAccessNumber;
     345             : 
     346             :     /// @brief The number of transportables that exited the simulation
     347             :     int myEndedNumber;
     348             : 
     349             :     /// @brief The number of transportables that arrived at their destination
     350             :     int myArrivedNumber;
     351             : 
     352             :     /// @brief The number of teleports due to long waits for a ride
     353             :     int myTeleportsAbortWait;
     354             : 
     355             :     /// @brief The number of teleports due to wrong destination
     356             :     int myTeleportsWrongDest;
     357             : 
     358             :     /// @brief whether a new transportable waiting for a vehicle has been added in the last step
     359             :     bool myHaveNewWaiting;
     360             : 
     361             : private:
     362             :     MSPModel* myMovementModel;
     363             : 
     364             :     MSPModel* myNonInteractingModel;
     365             : 
     366             :     /// @brief Information needed to sort transportable output by departure time
     367             :     MSDevice_Vehroutes::SortedRouteInfo myRouteInfos;
     368             : 
     369             :     /// @brief The time until waiting for a ride is aborted
     370             :     SUMOTime myAbortWaitingTimeout;
     371             : 
     372             : private:
     373             :     /// @brief invalidated assignment operator
     374             :     MSTransportableControl& operator=(const MSTransportableControl& src) = delete;
     375             : };

Generated by: LCOV version 1.14