LCOV - code coverage report
Current view: top level - src/microsim/transportables - MSTransportableControl.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 88.9 % 27 24
Test Date: 2026-09-20 15:45:03 Functions: 0.0 % 3 0

            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    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              :     /// @removes all transportables
      87              :     void eraseAll();
      88              : 
      89              :     /// sets the arrival time for a waiting transportable
      90              :     void setWaitEnd(SUMOTime time, MSTransportable* transportable);
      91              : 
      92              :     /// checks whether any transportables waiting time is over
      93              :     void checkWaiting(MSNet* net, const SUMOTime time);
      94              : 
      95              : #ifndef THREAD_POOL
      96              : #ifdef HAVE_FOX
      97              :     /// adds a transportable to the list with a pending routing task
      98              :     void addPendingRouting(MSTransportable* transportable);
      99              : 
     100              :     /// resumes proceed for all transportables whose routing task has completed
     101              :     void processPendingRouting(MSNet* net, const SUMOTime time);
     102              : #endif
     103              : #endif
     104              : 
     105              :     /// adds a transportable to the list of transportables waiting for a vehicle on the specified edge
     106              :     void addWaiting(const MSEdge* edge, MSTransportable* person);
     107              : 
     108              :     /// register forced (traci) departure
     109              :     void forceDeparture();
     110              : 
     111              :     /// @brief check whether any transportables are waiting for the given vehicle
     112              :     bool hasAnyWaiting(const MSEdge* edge, SUMOVehicle* vehicle) const;
     113              : 
     114              :     /** @brief load any applicable transportables
     115              :     * Loads any person / container that is waiting on that edge for the given vehicle and removes them from myWaiting
     116              :     * @param[in] edge the edge on which the loading should take place
     117              :     * @param[in] vehicle the vehicle which is taking on containers
     118              :     * @param[in,out] timeToLoadNext earliest time for the next loading process (gets updated)
     119              :     * @param[in,out] stopDuration the duration of the stop where the loading takes place (might be extended)
     120              :     * @param[in] force load the specified transportable even if the vehicle is not on a stop (needed for replay)
     121              :     * @return Whether any transportables have been loaded
     122              :     */
     123              :     bool loadAnyWaiting(const MSEdge* edge, SUMOVehicle* vehicle, SUMOTime& timeToLoadNext, SUMOTime& stopDuration, MSTransportable* const force = nullptr);
     124              : 
     125              :     /// checks whether any transportable waits to finish her plan
     126              :     bool hasTransportables() const;
     127              : 
     128              :     /// checks whether any transportable is still engaged in walking / stopping
     129              :     bool hasNonWaiting() const;
     130              : 
     131              :     /// @brief return the number of active transportable objects
     132              :     int getActiveCount();
     133              : 
     134              :     /// aborts the plan for any transportable that is still waiting for a ride
     135              :     void abortAnyWaitingForVehicle();
     136              : 
     137              :     /// let the given transportable abort waiting for a vehicle (when removing stage via TraCI)
     138              :     void abortWaitingForVehicle(MSTransportable* t);
     139              : 
     140              :     /// aborts waiting stage of transportable
     141              :     void abortWaiting(MSTransportable* t);
     142              : 
     143              :     /** @brief Builds a new person
     144              :      * @param[in] pars The parameter
     145              :      * @param[in] vtype The type (reusing vehicle type container here)
     146              :      * @param[in] plan This person's plan
     147              :      * @param[in] rng The RNG to compute the optional speed deviation
     148              :      */
     149              :     virtual MSTransportable* buildPerson(const SUMOVehicleParameter* pars, MSVehicleType* vtype, MSTransportable::MSTransportablePlan* plan,
     150              :                                          SumoRNG* rng) const;
     151              : 
     152              :     /** @brief Builds a new container
     153              :     * @param[in] pars The parameter
     154              :     * @param[in] vtype The type (reusing vehicle type container here)
     155              :     * @param[in] plan This container's plan
     156              :     */
     157              :     virtual MSTransportable* buildContainer(const SUMOVehicleParameter* pars, MSVehicleType* vtype, MSTransportable::MSTransportablePlan* plan) const;
     158              : 
     159              :     /** @brief Returns the begin of the internal transportables map
     160              :      * @return The begin of the internal transportables map
     161              :      */
     162              :     constVehIt loadedBegin() const {
     163              :         return myTransportables.begin();
     164              :     }
     165              : 
     166              : 
     167              :     /** @brief Returns the end of the internal transportables map
     168              :      * @return The end of the internal transportables map
     169              :      */
     170              :     constVehIt loadedEnd() const {
     171              :         return myTransportables.end();
     172              :     }
     173              : 
     174              : 
     175              :     /** @brief Returns the number of known transportables
     176              :      * @return The number of stored transportables
     177              :      */
     178              :     int size() const {
     179           30 :         return (int)myTransportables.size();
     180              :     }
     181              : 
     182              :     /// @brief register a jammed transportable
     183              :     void registerJammed() {
     184        62945 :         myJammedNumber++;
     185              :     }
     186              : 
     187              :     /// @brief register a teleport after aborting a long wait
     188              :     void registerTeleportAbortWait() {
     189           16 :         myTeleportsAbortWait++;
     190              :     }
     191              : 
     192              :     /// @brief register a teleport to the final destination
     193              :     void registerTeleportWrongDest() {
     194           38 :         myTeleportsWrongDest++;
     195           38 :     }
     196              : 
     197              :     /// @brief decrement counter to avoid double counting transportables loaded from state
     198              :     void fixLoadCount(const MSTransportable* transportable);
     199              : 
     200              :     /// @name Retrieval of transportable statistics (always accessible)
     201              :     /// @{
     202              : 
     203              :     /** @brief Returns the number of build transportables
     204              :      * @return The number of loaded (build) transportables
     205              :      */
     206            0 :     int getLoadedNumber() const {
     207       540054 :         return myLoadedNumber;
     208              :     }
     209              : 
     210              :     int getDepartedNumber() const;
     211              : 
     212              :     /** @brief Returns the number of build and inserted, but not yet deleted transportables
     213              :      * @return The number of simulated transportables
     214              :      */
     215            0 :     int getRunningNumber() const {
     216     77032710 :         return myRunningNumber;
     217              :     }
     218              : 
     219              :     /** @brief Returns the number of times a transportables was jammed
     220              :      * @return The number of times transportables were jammed
     221              :      */
     222            0 :     int getJammedNumber() const {
     223        10321 :         return myJammedNumber;
     224              :     }
     225              : 
     226              :     /** @brief Returns the number of transportables waiting for a ride
     227              :      */
     228              :     int getWaitingForVehicleNumber() const {
     229         7752 :         return myWaitingForVehicleNumber;
     230              :     }
     231              : 
     232              :     /** @brief Returns the number of transportables waiting for a specified
     233              :      * amount of time
     234              :      */
     235              :     int getWaitingUntilNumber() const {
     236         7752 :         return myWaitingUntilNumber;
     237              :     }
     238              : 
     239              :     /** @brief Returns the number of transportables moving by themselvs (i.e. walking)
     240              :      */
     241              :     int getMovingNumber() const;
     242              : 
     243              :     /** @brief Returns the number of transportables riding a vehicle
     244              :      */
     245              :     int getRidingNumber() const;
     246              : 
     247              :     /** @brief Returns the number of transportables that exited the simulation
     248              :      */
     249              :     int getEndedNumber() const {
     250         7752 :         return myEndedNumber;
     251              :     }
     252              : 
     253              :     /** @brief Returns the number of transportables that arrived at their
     254              :      * destination
     255              :      */
     256              :     int getArrivedNumber() const {
     257         7752 :         return myArrivedNumber;
     258              :     }
     259              : 
     260              :     /** @brief Returns the number of discarded transportables
     261              :      */
     262              :     int getDiscardedNumber() const {
     263         7752 :         return myDiscardedNumber;
     264              :     }
     265              : 
     266              :     /// @brief return the number of teleports due to excessive waiting for a ride
     267              :     int getTeleportsAbortWait() const {
     268           11 :         return myTeleportsAbortWait;
     269              :     }
     270              : 
     271              :     /// @brief return the number of teleports of transportables riding to the wrong destination
     272              :     int getTeleportsWrongDest() const {
     273           18 :         return myTeleportsWrongDest;
     274              :     }
     275              : 
     276              :     /// @brief Returns the number of teleports transportables did
     277              :     int getTeleportCount() const {
     278        10272 :         return myTeleportsAbortWait + myTeleportsWrongDest;
     279              :     }
     280              : 
     281              :     /// @}
     282              : 
     283              :     /** @brief Returns the default movement model for this kind of transportables
     284              :      * @return The movement model
     285              :      */
     286              :     inline MSPModel* getMovementModel() {
     287     14798256 :         return myMovementModel;
     288              :     }
     289              : 
     290              :     /** @brief Returns the non interacting movement model (for tranship and "beaming")
     291              :      * @return The non interacting movement model
     292              :      */
     293              :     inline MSPModel* getNonInteractingModel() {
     294       135324 :         return myNonInteractingModel;
     295              :     }
     296              : 
     297              :     void addArrived() {
     298       435266 :         myArrivedNumber++;
     299              :     }
     300              : 
     301              :     void addDiscarded() {
     302           56 :         myLoadedNumber++;
     303           56 :         myDiscardedNumber++;
     304           56 :     }
     305              : 
     306              :     void startedAccess() {
     307         4236 :         myAccessNumber++;
     308              :     }
     309              : 
     310              :     void endedAccess() {
     311         4204 :         myAccessNumber--;
     312              :     }
     313              : 
     314              :     /** @brief Saves the current state into the given stream
     315              :      */
     316              :     void saveState(OutputDevice& out);
     317              : 
     318              :     /** @brief Reconstruct the current state
     319              :      */
     320              :     void loadState(const std::string& state);
     321              : 
     322              :     /// @brief Resets transportables when quick-loading state
     323              :     void clearState();
     324              : 
     325              :     const MSDevice_Vehroutes::SortedRouteInfo& getRouteInfo() {
     326              :         return myRouteInfos;
     327              :     }
     328              : 
     329              : protected:
     330              :     /// all currently created transportables by id
     331              :     std::map<std::string, MSTransportable*> myTransportables;
     332              : 
     333              :     /// @brief Transportables waiting for departure
     334              :     std::map<SUMOTime, TransportableVector> myWaiting4Departure;
     335              : 
     336              :     /// the lists of walking / stopping transportables
     337              :     std::map<SUMOTime, TransportableVector> myWaitingUntil;
     338              : 
     339              :     /// the lists of waiting transportables
     340              :     std::map<const MSEdge*, TransportableVector, ComparatorNumericalIdLess> myWaiting4Vehicle;
     341              : 
     342              :     /// @brief The number of build transportables
     343              :     int myLoadedNumber;
     344              : 
     345              :     /// @brief The number of discarded transportables
     346              :     int myDiscardedNumber;
     347              : 
     348              :     /// @brief The number of transportables within the network (build and inserted but not removed)
     349              :     int myRunningNumber;
     350              : 
     351              :     /// @brief The number of jammed transportables
     352              :     int myJammedNumber;
     353              : 
     354              :     /// @brief The number of transportables waiting for departure
     355              :     int myWaitingForDepartureNumber;
     356              : 
     357              :     /// @brief The number of transportables waiting for vehicles
     358              :     int myWaitingForVehicleNumber;
     359              : 
     360              :     /// @brief The number of transportables waiting for a specified time
     361              :     int myWaitingUntilNumber;
     362              : 
     363              :     /// @brief The number of transportables currently in an access stage
     364              :     int myAccessNumber;
     365              : 
     366              :     /// @brief The number of transportables that exited the simulation
     367              :     int myEndedNumber;
     368              : 
     369              :     /// @brief The number of transportables that arrived at their destination
     370              :     int myArrivedNumber;
     371              : 
     372              :     /// @brief The number of teleports due to long waits for a ride
     373              :     int myTeleportsAbortWait;
     374              : 
     375              :     /// @brief The number of teleports due to wrong destination
     376              :     int myTeleportsWrongDest;
     377              : 
     378              :     /// @brief whether a new transportable waiting for a vehicle has been added in the last step
     379              :     bool myHaveNewWaiting;
     380              : 
     381              : #ifndef THREAD_POOL
     382              : #ifdef HAVE_FOX
     383              :     /// @brief transportables waiting for an asynchronous routing task to complete
     384              :     TransportableVector myPendingRouting;
     385              : #endif
     386              : #endif
     387              : 
     388              :     /// @brief maximum transportable count
     389              :     int myMaxTransportableNumber;
     390              : 
     391              : private:
     392              :     MSPModel* myMovementModel;
     393              : 
     394              :     MSPModel* myNonInteractingModel;
     395              : 
     396              :     /// @brief Information needed to sort transportable output by departure time
     397              :     MSDevice_Vehroutes::SortedRouteInfo myRouteInfos;
     398              : 
     399              :     /// @brief The time until waiting for a ride is aborted
     400              :     SUMOTime myAbortWaitingTimeout;
     401              : 
     402              : private:
     403              :     /// @brief invalidated assignment operator
     404              :     MSTransportableControl& operator=(const MSTransportableControl& src) = delete;
     405              : };
        

Generated by: LCOV version 2.0-1