LCOV - code coverage report
Current view: top level - src/microsim - MSNet.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 94.6 % 37 35
Test Date: 2025-12-06 15:35:27 Functions: 80.0 % 5 4

            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    MSNet.h
      15              : /// @author  Christian Roessel
      16              : /// @author  Jakob Erdmann
      17              : /// @author  Daniel Krajzewicz
      18              : /// @author  Thimor Bohn
      19              : /// @author  Eric Nicolay
      20              : /// @author  Clemens Honomichl
      21              : /// @author  Michael Behrisch
      22              : /// @author  Leonhard Luecken
      23              : /// @date    Mon, 12 Mar 2001
      24              : ///
      25              : // The simulated network and simulation performer
      26              : /****************************************************************************/
      27              : #pragma once
      28              : #include <config.h>
      29              : 
      30              : #include <typeinfo>
      31              : #include <vector>
      32              : #include <map>
      33              : #include <string>
      34              : #include <fstream>
      35              : #include <iostream>
      36              : #include <cmath>
      37              : #include <iomanip>
      38              : #include <memory>
      39              : #include <utils/common/SUMOTime.h>
      40              : #include <utils/common/UtilExceptions.h>
      41              : #include <utils/common/NamedObjectCont.h>
      42              : #include <utils/common/NamedRTree.h>
      43              : #include <utils/router/SUMOAbstractRouter.h>
      44              : #include <mesosim/MESegment.h>
      45              : #include "MSRouterDefs.h"
      46              : #include "MSJunction.h"
      47              : 
      48              : 
      49              : // ===========================================================================
      50              : // class declarations
      51              : // ===========================================================================
      52              : class MSEdge;
      53              : class MSEdgeControl;
      54              : class MSEventControl;
      55              : class MSVehicleControl;
      56              : class MSJunctionControl;
      57              : class MSInsertionControl;
      58              : class SUMORouteLoaderControl;
      59              : class MSTransportableControl;
      60              : class MSTransportable;
      61              : class MSVehicle;
      62              : class MSRoute;
      63              : class MSLane;
      64              : class MSTLLogicControl;
      65              : class MSTrafficLightLogic;
      66              : class MSDetectorControl;
      67              : class ShapeContainer;
      68              : class MSDynamicShapeUpdater;
      69              : class PolygonDynamics;
      70              : class MSEdgeWeightsStorage;
      71              : class SUMOVehicle;
      72              : class SUMOTrafficObject;
      73              : class MSTractionSubstation;
      74              : class MSStoppingPlace;
      75              : template<class E, class L, class N, class V>
      76              : class IntermodalRouter;
      77              : template<class E, class L, class N, class V>
      78              : class PedestrianRouter;
      79              : class OptionsCont;
      80              : 
      81              : 
      82              : // ===========================================================================
      83              : // class definitions
      84              : // ===========================================================================
      85              : /**
      86              :  * @class MSNet
      87              :  * @brief The simulated network and simulation perfomer
      88              :  */
      89              : class MSNet : public Parameterised {
      90              : public:
      91              :     /** @enum SimulationState
      92              :      * @brief Possible states of a simulation - running or stopped with different reasons
      93              :      */
      94              :     enum SimulationState {
      95              :         /// @brief The simulation is loading
      96              :         SIMSTATE_LOADING,
      97              :         /// @brief The simulation is running
      98              :         SIMSTATE_RUNNING,
      99              :         /// @brief The final simulation step has been performed
     100              :         SIMSTATE_END_STEP_REACHED,
     101              :         /// @brief The simulation does not contain further vehicles
     102              :         SIMSTATE_NO_FURTHER_VEHICLES,
     103              :         /// @brief The connection to a client was closed by the client
     104              :         SIMSTATE_CONNECTION_CLOSED,
     105              :         /// @brief An error occurred during the simulation step
     106              :         SIMSTATE_ERROR_IN_SIM,
     107              :         /// @brief An external interrupt occurred
     108              :         SIMSTATE_INTERRUPTED,
     109              :         /// @brief The simulation had too many teleports
     110              :         SIMSTATE_TOO_MANY_TELEPORTS
     111              :     };
     112              : 
     113              :     /// @brief collision tracking
     114              :     struct Collision {
     115              :         std::string victim;
     116              :         std::string colliderType;
     117              :         std::string victimType;
     118              :         double colliderSpeed;
     119              :         double victimSpeed;
     120              :         Position colliderFront;
     121              :         Position victimFront;
     122              :         Position colliderBack;
     123              :         Position victimBack;
     124              :         std::string type;
     125              :         const MSLane* lane;
     126              :         double pos;
     127              :         SUMOTime time;
     128              :         SUMOTime continuationTime;
     129              :     };
     130              : 
     131              :     typedef std::map<std::string, std::vector<Collision> > CollisionMap;
     132              :     typedef std::map<const MSEdge*, double> Prohibitions;
     133              : 
     134              : public:
     135              :     /** @brief Returns the pointer to the unique instance of MSNet (singleton).
     136              :      * @return Pointer to the unique MSNet-instance
     137              :      * @exception ProcessError If a network was not yet constructed
     138              :      */
     139              :     static MSNet* getInstance();
     140              : 
     141              :     /**
     142              :      * @brief Returns whether this is a GUI Net
     143              :      */
     144           40 :     virtual bool isGUINet() const {
     145           40 :         return false;
     146              :     }
     147              : 
     148              :     /// @brief Place for static initializations of simulation components (called after successful net build)
     149              :     static void initStatic();
     150              : 
     151              :     /// @brief Place for static initializations of simulation components (called after successful net build)
     152              :     static void cleanupStatic();
     153              : 
     154              : 
     155              :     /** @brief Returns whether the network was already constructed
     156              :     * @return whether the network was already constructed
     157              :     */
     158              :     static bool hasInstance() {
     159         2362 :         return myInstance != nullptr;
     160              :     }
     161              : 
     162              : 
     163              :     /** @brief Constructor
     164              :      *
     165              :      * This constructor builds a net of which only some basic structures are initialised.
     166              :      * It prepares the network for being filled while loading.
     167              :      * As soon as all edge/junction/traffic lights and other containers are build, they
     168              :      *  must be initialised using "closeBuilding".
     169              :      * @param[in] vc The vehicle control to use
     170              :      * @param[in] beginOfTimestepEvents The event control to use for simulation step begin events
     171              :      * @param[in] endOfTimestepEvents The event control to use for simulation step end events
     172              :      * @param[in] insertionEvents The event control to use for insertion events
     173              :      * @param[in] shapeCont The shape container to use
     174              :      * @exception ProcessError If a network was already constructed
     175              :      * @see closeBuilding
     176              :      */
     177              :     MSNet(MSVehicleControl* vc, MSEventControl* beginOfTimestepEvents,
     178              :           MSEventControl* endOfTimestepEvents,
     179              :           MSEventControl* insertionEvents,
     180              :           ShapeContainer* shapeCont = 0);
     181              : 
     182              : 
     183              :     /// @brief Destructor
     184              :     virtual ~MSNet();
     185              : 
     186              : 
     187              :     /** @brief Closes the network's building process
     188              :      *
     189              :      * Assigns the structures built while loading to this network.
     190              :      * @param[in] oc The options to use
     191              :      * @param[in] edges The control of edges which belong to this network
     192              :      * @param[in] junctions The control of junctions which belong to this network
     193              :      * @param[in] routeLoaders The route loaders used
     194              :      * @param[in] tlc The control of traffic lights which belong to this network
     195              :      * @param[in] stateDumpTimes List of time steps at which state shall be written
     196              :      * @param[in] stateDumpFiles Filenames for states
     197              :      * @param[in] hasInternalLinks Whether the network actually contains internal links
     198              :      * @param[in] junctionHigherSpeeds Whether the network was built with higher junction speeds
     199              :      * @param[in] version The network version
     200              :      * @todo Try to move all this to the constructor?
     201              :      */
     202              :     void closeBuilding(const OptionsCont& oc, MSEdgeControl* edges, MSJunctionControl* junctions,
     203              :                        SUMORouteLoaderControl* routeLoaders, MSTLLogicControl* tlc,
     204              :                        std::vector<SUMOTime> stateDumpTimes, std::vector<std::string> stateDumpFiles,
     205              :                        bool hasInternalLinks,
     206              :                        bool junctionHigherSpeeds,
     207              :                        const MMVersion& version);
     208              : 
     209              : 
     210              :     /** @brief Returns whether the network has specific vehicle class permissions
     211              :      * @return whether permissions are present
     212              :      */
     213              :     bool hasPermissions() const {
     214     44620784 :         return myHavePermissions;
     215              :     }
     216              : 
     217              : 
     218              :     /// @brief Labels the network to contain vehicle class permissions
     219              :     void setPermissionsFound() {
     220       814569 :         myHavePermissions = true;
     221       814569 :     }
     222              : 
     223              : 
     224              :     /** @brief Adds a restriction for an edge type
     225              :      * @param[in] id The id of the type
     226              :      * @param[in] svc The vehicle class the restriction refers to
     227              :      * @param[in] speed The restricted speed
     228              :      */
     229              :     void addRestriction(const std::string& id, const SUMOVehicleClass svc, const double speed);
     230              : 
     231              : 
     232              :     /** @brief Returns the restrictions for an edge type
     233              :      * If no restrictions are present, 0 is returned.
     234              :      * @param[in] id The id of the type
     235              :      * @return The mapping of vehicle classes to maximum speeds
     236              :      */
     237              :     const std::map<SUMOVehicleClass, double>* getRestrictions(const std::string& id) const;
     238              : 
     239              :     /// @brief retriefe edge type specific routing preference
     240              :     double getPreference(const std::string& routingType, const SUMOVTypeParameter& pars) const;
     241              : 
     242              :     /// @brief add edge type specific routing preference
     243              :     void addPreference(const std::string& routingType, SUMOVehicleClass svc, double prio); 
     244              :     /// @brief add edge type specific routing preference
     245              :     void addPreference(const std::string& routingType, std::string vType, double prio); 
     246              : 
     247              :     /** @brief Adds edge type specific meso parameters
     248              :      * @param[in] id The id of the type
     249              :      * @param[in] edgeType The parameter object
     250              :      */
     251              :     void addMesoType(const std::string& typeID, const MESegment::MesoEdgeType& edgeType);
     252              : 
     253              :     /** @brief Returns edge type specific meso parameters
     254              :      * if no type specific parameters have been loaded, default values are returned
     255              :      */
     256              :     const MESegment::MesoEdgeType& getMesoType(const std::string& typeID);
     257              : 
     258              :     /** @brief Clears all dictionaries
     259              :      * @todo Try to move all this to the destructor
     260              :      */
     261              :     static void clearAll();
     262              : 
     263              :     /// @brief return whether the given flow is known
     264              :     bool hasFlow(const std::string& id) const;
     265              : 
     266              :     /** @brief Simulates from timestep start to stop
     267              :      * @param[in] start The begin time step of the simulation
     268              :      * @param[in] stop The end time step of the simulation
     269              :      * @return Returns always 0
     270              :      * @todo Recheck return value
     271              :      * @todo What exceptions may occure?
     272              :      */
     273              :     SimulationState simulate(SUMOTime start, SUMOTime stop);
     274              : 
     275              : 
     276              :     /** @brief Performs a single simulation step
     277              :      * @todo Which exceptions may occur?
     278              :      */
     279              :     void simulationStep(const bool onlyMove = false);
     280              : 
     281              :     /** @brief loads routes for the next few steps */
     282              :     void loadRoutes();
     283              : 
     284              : 
     285              :     /** @brief Writes performance output and running vehicle stats
     286              :      *
     287              :      * @param[in] start The step the simulation was started with
     288              :      */
     289              :     const std::string generateStatistics(const SUMOTime start, const long now);
     290              : 
     291              :     /// @brief write collision output to (xml) file
     292              :     void writeCollisions() const;
     293              : 
     294              :     /// @brief write statistic output to (xml) file
     295              :     void writeStatistics(const SUMOTime start, const long now) const;
     296              : 
     297              :     /// @brief write summary-output to (xml) file
     298              :     void writeSummaryOutput(bool finalStep = false);
     299              : 
     300              :     /** @brief Closes the simulation (all files, connections, etc.)
     301              :      *
     302              :      * Writes also performance output
     303              :      *
     304              :      * @param[in] start The step the simulation was started with
     305              :      */
     306              :     void closeSimulation(SUMOTime start, const std::string& reason = "");
     307              : 
     308              : 
     309              :     /** @brief This method returns the current simulation state. It should not modify status.
     310              :      * @param[in] stopTime The time the simulation shall stop at
     311              :      * @return The current simulation state
     312              :      * @see SimulationState
     313              :      */
     314              :     SimulationState simulationState(SUMOTime stopTime) const;
     315              : 
     316              : 
     317              :     /** @brief Called after a simulation step, this method adapts the current simulation state if necessary
     318              :      * @param[in] state The current simulation state
     319              :      * @return The new simulation state
     320              :      * @see SimulationState
     321              :      */
     322              :     SimulationState adaptToState(const SimulationState state, const bool isLibsumo = false) const;
     323              : 
     324              : 
     325              :     /** @brief Returns the message to show if a certain state occurs
     326              :      * @return Readable description of the state
     327              :      */
     328              :     static std::string getStateMessage(SimulationState state);
     329              : 
     330              : 
     331              :     /** @brief Returns the current simulation step
     332              :      * @return the current simulation step
     333              :      */
     334              :     inline SUMOTime getCurrentTimeStep() const {
     335   3172113999 :         return myStep;
     336              :     }
     337              : 
     338              : 
     339              :     /** @brief Sets the current simulation step (used by state loading)
     340              :      * @param step the current simulation step
     341              :      */
     342              :     inline void setCurrentTimeStep(const SUMOTime step) {
     343         8588 :         myStep = step;
     344              :     }
     345              : 
     346              : 
     347              :     /** @brief Resets events when quick-loading state
     348              :      * @param step The new simulation step
     349              :      */
     350              :     void clearState(const SUMOTime step, bool quickReload = false);
     351              : 
     352              :     /** @brief Write netstate, summary and detector output
     353              :      * @todo Which exceptions may occur?
     354              :      */
     355              :     void writeOutput();
     356              : 
     357              : 
     358              :     /** @brief Returns whether duration shall be logged
     359              :      * @return Whether duration shall be logged
     360              :      */
     361              :     bool logSimulationDuration() const;
     362              : 
     363              : 
     364              : 
     365              :     /// @name Output during the simulation
     366              :     //@{
     367              : 
     368              :     /** @brief Prints the current step number
     369              :      *
     370              :      * Called on the begin of a simulation step
     371              :      */
     372              :     void preSimStepOutput() const;
     373              : 
     374              : 
     375              :     /** @brief Prints the statistics of the step at its end
     376              :      *
     377              :      * Called on the end of a simulation step
     378              :      */
     379              :     void postSimStepOutput() const;
     380              :     //}
     381              : 
     382              : 
     383              : 
     384              :     /// @name Retrieval of references to substructures
     385              :     /// @{
     386              : 
     387              :     /** @brief Returns the vehicle control
     388              :      * @return The vehicle control
     389              :      * @see MSVehicleControl
     390              :      * @see myVehicleControl
     391              :      */
     392              :     MSVehicleControl& getVehicleControl() {
     393    731184777 :         return *myVehicleControl;
     394              :     }
     395              : 
     396              : 
     397              :     /** @brief Returns the person control
     398              :      *
     399              :      * If the person control does not exist, yet, it is created.
     400              :      *
     401              :      * @return The person control
     402              :      * @see MSPersonControl
     403              :      * @see myPersonControl
     404              :      */
     405              :     virtual MSTransportableControl& getPersonControl();
     406              : 
     407              :     /** @brief Returns whether persons are simulated
     408              :      */
     409              :     bool hasPersons() const {
     410    410678276 :         return myPersonControl != nullptr;
     411              :     }
     412              : 
     413              :     /** @brief Returns the container control
     414              :      *
     415              :      * If the container control does not exist, yet, it is created.
     416              :      *
     417              :      * @return The container control
     418              :      * @see MSContainerControl
     419              :      * @see myContainerControl
     420              :      */
     421              :     virtual MSTransportableControl& getContainerControl();
     422              : 
     423              :     /** @brief Returns whether containers are simulated
     424              :     */
     425              :     bool hasContainers() const {
     426     45631504 :         return myContainerControl != nullptr;
     427              :     }
     428              : 
     429              : 
     430              :     /** @brief Returns the edge control
     431              :      * @return The edge control
     432              :      * @see MSEdgeControl
     433              :      * @see myEdges
     434              :      */
     435              :     MSEdgeControl& getEdgeControl() {
     436    198442062 :         return *myEdges;
     437              :     }
     438              : 
     439              : 
     440              :     /** @brief Returns the insertion control
     441              :      * @return The insertion control
     442              :      * @see MSInsertionControl
     443              :      * @see myInserter
     444              :      */
     445              :     MSInsertionControl& getInsertionControl() {
     446     15421871 :         return *myInserter;
     447              :     }
     448              : 
     449              : 
     450              :     /** @brief Returns the detector control
     451              :      * @return The detector control
     452              :      * @see MSDetectorControl
     453              :      * @see myDetectorControl
     454              :      */
     455              :     MSDetectorControl& getDetectorControl() {
     456       198124 :         return *myDetectorControl;
     457              :     }
     458              : 
     459              : 
     460              :     /** @brief Returns the tls logics control
     461              :      * @return The tls logics control
     462              :      * @see MSTLLogicControl
     463              :      * @see myLogics
     464              :      */
     465              :     MSTLLogicControl& getTLSControl() {
     466       354114 :         return *myLogics;
     467              :     }
     468              : 
     469              : 
     470              :     /** @brief Returns the junctions control
     471              :      * @return The junctions control
     472              :      * @see MSJunctionControl
     473              :      * @see myJunctions
     474              :      */
     475              :     MSJunctionControl& getJunctionControl() {
     476        32957 :         return *myJunctions;
     477              :     }
     478              : 
     479              : 
     480              :     /** @brief Returns the event control for events executed at the begin of a time step
     481              :      * @return The control responsible for events that are executed at the begin of a time step
     482              :      * @see MSEventControl
     483              :      * @see myBeginOfTimestepEvents
     484              :      */
     485              :     MSEventControl* getBeginOfTimestepEvents() {
     486       342930 :         return myBeginOfTimestepEvents;
     487              :     }
     488              : 
     489              : 
     490              :     /** @brief Returns the event control for events executed at the end of a time step
     491              :      * @return The control responsible for events that are executed at the end of a time step
     492              :      * @see MSEventControl
     493              :      * @see myEndOfTimestepEvents
     494              :      */
     495              :     MSEventControl* getEndOfTimestepEvents() {
     496        25913 :         return myEndOfTimestepEvents;
     497              :     }
     498              : 
     499              : 
     500              :     /** @brief Returns the event control for insertion events
     501              :      * @return The control responsible for insertion events
     502              :      * @see MSEventControl
     503              :      * @see myInsertionEvents
     504              :      */
     505              :     MSEventControl* getInsertionEvents() {
     506      1575036 :         return myInsertionEvents;
     507              :     }
     508              : 
     509              : 
     510              :     /** @brief Returns the shapes container
     511              :      * @return The shapes container
     512              :      * @see ShapeContainer
     513              :      * @see myShapeContainer
     514              :      */
     515              :     ShapeContainer& getShapeContainer() {
     516        96750 :         return *myShapeContainer;
     517              :     }
     518              : 
     519              :     /** @brief Returns the dynamic shapes updater
     520              :      * @see PolygonDynamics
     521              :      */
     522              :     MSDynamicShapeUpdater* getDynamicShapeUpdater() {
     523              :         return myDynamicShapeUpdater.get();
     524              :     }
     525              : 
     526              :     /** @brief Creates and returns a dynamic shapes updater
     527              :      * @see PolygonDynamics
     528              :      */
     529              :     MSDynamicShapeUpdater* makeDynamicShapeUpdater();
     530              : 
     531              :     /** @brief Returns the net's internal edge travel times/efforts container
     532              :      *
     533              :      * If the net does not have such a container, it is built.
     534              :      * @return The net's knowledge about edge weights
     535              :      */
     536              :     MSEdgeWeightsStorage& getWeightsStorage();
     537              :     /// @}
     538              : 
     539              :     /// @name Insertion and retrieval of stopping places
     540              :     /// @{
     541              : 
     542              :     /** @brief Adds a stopping place
     543              :      *
     544              :      * If another stop with the same id and category exists, false is returned.
     545              :      *  Otherwise, the stop is added to the internal stopping place container.
     546              :      *
     547              :      * This control gets responsible for deletion of the added stop.
     548              :      *
     549              :      * @param[in] stop The stop to add
     550              :      * @return Whether the stop could be added
     551              :      */
     552              :     bool addStoppingPlace(SumoXMLTag category, MSStoppingPlace* stop);
     553              : 
     554              : 
     555              :     /** @brief Adds a traction substation
     556              :      *
     557              :      * If another traction substation with the same id and category exists, false is returned.
     558              :      *  Otherwise, the traction substation is added to the internal substations container.
     559              :      *
     560              :      * @param[in] substation The traction substation to add
     561              :      * @return Whether the stop could be added
     562              :      */
     563              :     bool addTractionSubstation(MSTractionSubstation* substation);
     564              : 
     565              : 
     566              :     /** @brief Returns the named stopping place of the given category
     567              :      * @param[in] id The id of the stop to return.
     568              :      * @param[in] category The type of stop
     569              :      * @return The named stop, or 0 if no such stop exists
     570              :      */
     571              :     MSStoppingPlace* getStoppingPlace(const std::string& id, const SumoXMLTag category) const;
     572              : 
     573              :     /** @brief Returns the named stopping place by looking through all categories
     574              :      * @param[in] id The id of the stop to return.
     575              :      * @return The named stop, or 0 if no such stop exists
     576              :      */
     577              :     MSStoppingPlace* getStoppingPlace(const std::string& id) const;
     578              : 
     579              :     /** @brief Returns the stop of the given category close to the given position
     580              :      * @param[in] lane the lane of the stop to return.
     581              :      * @param[in] pos the position of the stop to return.
     582              :      * @param[in] category The type of stop
     583              :      * @return The stop id on the location, or "" if no such stop exists
     584              :      */
     585              :     std::string getStoppingPlaceID(const MSLane* lane, const double pos, const SumoXMLTag category) const;
     586              : 
     587              :     /* @brief returns all stopping places of that category with the same (non-empty) name attribute
     588              :      */
     589              :     const std::vector<MSStoppingPlace*>& getStoppingPlaceAlternatives(const std::string& name, SumoXMLTag category) const;
     590              :     /// @}
     591              : 
     592              :     const NamedObjectCont<MSStoppingPlace*>& getStoppingPlaces(SumoXMLTag category) const;
     593              : 
     594              :     /// @brief write charging station output
     595              :     void writeChargingStationOutput() const;
     596              : 
     597              :     /// @brief write rail signal block output
     598              :     void writeRailSignalBlocks() const;
     599              : 
     600              :     /// @brief creates a wrapper for the given logic (see GUINet)
     601           57 :     virtual void createTLWrapper(MSTrafficLightLogic*) {};
     602              : 
     603              :     /// @brief write the output generated by an overhead wire segment
     604              :     void writeOverheadWireSegmentOutput() const;
     605              : 
     606              :     /// @brief write electrical substation output
     607              :     void writeSubstationOutput() const;
     608              : 
     609              :     /// @brief return wheter the given logic (or rather its wrapper) is selected in the GUI
     610            0 :     virtual bool isSelected(const MSTrafficLightLogic*) const {
     611            0 :         return false;
     612              :     }
     613              :     /// @brief update view after simulation.loadState
     614          143 :     virtual void updateGUI() const { }
     615              : 
     616              :     /// @brief load state from file and return new time
     617              :     SUMOTime loadState(const std::string& fileName, const bool catchExceptions);
     618              : 
     619              :     /// @brief reset state to the beginning without reloading the network
     620              :     void quickReload();
     621              : 
     622              :     /// @name Notification about vehicle state changes
     623              :     /// @{
     624              : 
     625              :     /// @brief Definition of a vehicle state
     626              :     enum class VehicleState {
     627              :         /// @brief The vehicle was built, but has not yet departed
     628              :         BUILT,
     629              :         /// @brief The vehicle has departed (was inserted into the network)
     630              :         DEPARTED,
     631              :         /// @brief The vehicle started to teleport
     632              :         STARTING_TELEPORT,
     633              :         /// @brief The vehicle ended being teleported
     634              :         ENDING_TELEPORT,
     635              :         /// @brief The vehicle arrived at his destination (is deleted)
     636              :         ARRIVED,
     637              :         /// @brief The vehicle got a new route
     638              :         NEWROUTE,
     639              :         /// @brief The vehicles starts to park
     640              :         STARTING_PARKING,
     641              :         /// @brief The vehicle ends to park
     642              :         ENDING_PARKING,
     643              :         /// @brief The vehicles starts to stop
     644              :         STARTING_STOP,
     645              :         /// @brief The vehicle ends to stop
     646              :         ENDING_STOP,
     647              :         /// @brief The vehicle is involved in a collision
     648              :         COLLISION,
     649              :         /// @brief The vehicle had to brake harder than permitted
     650              :         EMERGENCYSTOP,
     651              :         /// @brief Vehicle maneuvering either entering or exiting a parking space
     652              :         MANEUVERING
     653              :     };
     654              : 
     655              : 
     656              :     /** @class VehicleStateListener
     657              :      * @brief Interface for objects listening to vehicle state changes
     658              :      */
     659              :     class VehicleStateListener {
     660              :     public:
     661              :         /// @brief Constructor
     662         3792 :         VehicleStateListener() { }
     663              : 
     664              :         /// @brief Destructor
     665              :         virtual ~VehicleStateListener() { }
     666              : 
     667              :         /** @brief Called if a vehicle changes its state
     668              :          * @param[in] vehicle The vehicle which changed its state
     669              :          * @param[in] to The state the vehicle has changed to
     670              :          * @param[in] info Additional information on the state change
     671              :          */
     672              :         virtual void vehicleStateChanged(const SUMOVehicle* const vehicle, VehicleState to, const std::string& info = "") = 0;
     673              : 
     674              :     };
     675              : 
     676              : 
     677              :     /** @brief Adds a vehicle states listener
     678              :      * @param[in] listener The listener to add
     679              :      */
     680              :     void addVehicleStateListener(VehicleStateListener* listener);
     681              : 
     682              : 
     683              :     /** @brief Removes a vehicle states listener
     684              :      * @param[in] listener The listener to remove
     685              :      */
     686              :     void removeVehicleStateListener(VehicleStateListener* listener);
     687              : 
     688              : 
     689              :     /** @brief Informs all added listeners about a vehicle's state change
     690              :      * @param[in] vehicle The vehicle which changed its state
     691              :      * @param[in] to The state the vehicle has changed to
     692              :      * @param[in] info Information regarding the replacement
     693              :      * @see VehicleStateListener:vehicleStateChanged
     694              :      */
     695              :     void informVehicleStateListener(const SUMOVehicle* const vehicle, VehicleState to, const std::string& info = "");
     696              :     /// @}
     697              : 
     698              : 
     699              :     /// @name Notification about transportable state changes
     700              :     /// @{
     701              : 
     702              :     /// @brief Definition of a transportable state
     703              :     enum class TransportableState {
     704              :         /// @brief The transportable person has departed (was inserted into the network)
     705              :         PERSON_DEPARTED,
     706              :         /// @brief The transportable person arrived at his destination (is deleted)
     707              :         PERSON_ARRIVED,
     708              :         /// @brief The transportable container has departed (was inserted into the network)
     709              :         CONTAINER_DEPARTED,
     710              :         /// @brief The transportable container arrived at his destination (is deleted)
     711              :         CONTAINER_ARRIVED
     712              :     };
     713              : 
     714              : 
     715              :     /** @class TransportableStateListener
     716              :      * @brief Interface for objects listening to transportable state changes
     717              :      */
     718              :     class TransportableStateListener {
     719              :     public:
     720              :         /// @brief Constructor
     721         2559 :         TransportableStateListener() { }
     722              : 
     723              :         /// @brief Destructor
     724              :         virtual ~TransportableStateListener() { }
     725              : 
     726              :         /** @brief Called if a transportable changes its state
     727              :          * @param[in] transportable The transportable which changed its state
     728              :          * @param[in] to The state the transportable has changed to
     729              :          * @param[in] info Additional information on the state change
     730              :          */
     731              :         virtual void transportableStateChanged(const MSTransportable* const transportable, TransportableState to, const std::string& info = "") = 0;
     732              : 
     733              :     };
     734              : 
     735              : 
     736              :     /** @brief Adds a transportable states listener
     737              :      * @param[in] listener The listener to add
     738              :      */
     739              :     void addTransportableStateListener(TransportableStateListener* listener);
     740              : 
     741              : 
     742              :     /** @brief Removes a transportable states listener
     743              :      * @param[in] listener The listener to remove
     744              :      */
     745              :     void removeTransportableStateListener(TransportableStateListener* listener);
     746              : 
     747              : 
     748              :     /** @brief Informs all added listeners about a transportable's state change
     749              :      * @param[in] transportable The transportable which changed its state
     750              :      * @param[in] to The state the transportable has changed to
     751              :      * @param[in] info Information regarding the replacement
     752              :      * @see TransportableStateListener:TransportableStateChanged
     753              :      */
     754              :     void informTransportableStateListener(const MSTransportable* const transportable, TransportableState to, const std::string& info = "");
     755              :     /// @}
     756              : 
     757              : 
     758              :     /// @brief register collision and return whether it was the first one involving these vehicles
     759              :     bool registerCollision(const SUMOTrafficObject* collider, const SUMOTrafficObject* victim, const std::string& collisionType, const MSLane* lane, double pos);
     760              : 
     761              :     const CollisionMap& getCollisions() const {
     762              :         return myCollisions;
     763              :     }
     764              : 
     765              : 
     766              :     /** @brief Returns the travel time to pass an edge
     767              :      * @param[in] e The edge for which the travel time to be passed shall be returned
     768              :      * @param[in] v The vehicle that is rerouted
     769              :      * @param[in] t The time for which the travel time shall be returned [s]
     770              :      * @return The travel time for an edge
     771              :      * @see DijkstraRouter_ByProxi
     772              :      */
     773              :     static double getTravelTime(const MSEdge* const e, const SUMOVehicle* const v, double t);
     774              : 
     775              : 
     776              :     /** @brief Returns the effort to pass an edge
     777              :      * @param[in] e The edge for which the effort to be passed shall be returned
     778              :      * @param[in] v The vehicle that is rerouted
     779              :      * @param[in] t The time for which the effort shall be returned [s]
     780              :      * @return The effort (abstract) for an edge
     781              :      * @see DijkstraRouter_ByProxi
     782              :      */
     783              :     static double getEffort(const MSEdge* const e, const SUMOVehicle* const v, double t);
     784              : 
     785              : 
     786              :     /* @brief get the router, initialize on first use
     787              :      * @param[in] prohibited The vector of forbidden edges (optional)
     788              :      */
     789              :     MSVehicleRouter& getRouterTT(int rngIndex, const Prohibitions& prohibited = {}) const;
     790              :     MSVehicleRouter& getRouterEffort(int rngIndex, const Prohibitions& prohibited = {}) const;
     791              :     MSPedestrianRouter& getPedestrianRouter(int rngIndex, const Prohibitions& prohibited = {}) const;
     792              :     MSTransportableRouter& getIntermodalRouter(int rngIndex, const int routingMode = 0, const Prohibitions& prohibited = {}) const;
     793              : 
     794              :     static void adaptIntermodalRouter(MSTransportableRouter& router);
     795              : 
     796              : 
     797              :     /// @brief return whether the network contains internal links
     798              :     bool hasInternalLinks() const {
     799       295170 :         return myHasInternalLinks;
     800              :     }
     801              : 
     802              :     /// @brief return whether the network was built with higher junction speeds
     803              :     bool hasJunctionHigherSpeeds() const {
     804           20 :         return myJunctionHigherSpeeds;
     805              :     }
     806              : 
     807              :     /// @brief return whether the network contains elevation data
     808              :     bool hasElevation() const {
     809   1526866244 :         return myHasElevation;
     810              :     }
     811              : 
     812              :     /// @brief return whether the network contains walkingareas and crossings
     813              :     bool hasPedestrianNetwork() const {
     814       123836 :         return myHasPedestrianNetwork;
     815              : 
     816              :     }
     817              :     /// @brief return whether the network contains bidirectional rail edges
     818              :     bool hasBidiEdges() const {
     819       114041 :         return myHasBidiEdges;
     820              :     }
     821              : 
     822              :     /// @brief return the network version
     823              :     MMVersion getNetworkVersion() const {
     824         5414 :         return myVersion;
     825              :     }
     826              : 
     827              :     /// @brief return whether a warning regarding the given object shall be issued
     828              :     bool warnOnce(const std::string& typeAndID);
     829              : 
     830              :     void interrupt() {
     831            5 :         myAmInterrupted = true;
     832            5 :     }
     833              : 
     834              :     bool isInterrupted() const {
     835            5 :         return myAmInterrupted;
     836              :     }
     837              : 
     838              :     /// @brief gui may prevent final meanData reset to keep live data visible
     839     16739040 :     virtual bool skipFinalReset() const {
     840     16739040 :         return false;
     841              :     }
     842              : 
     843              :     MSMapMatcher* getMapMatcher() const;
     844              : 
     845              :     /// @brief find electrical substation by its id
     846              :     MSTractionSubstation* findTractionSubstation(const std::string& substationId);
     847              : 
     848              :     /// @brief return whether given electrical substation exists in the network
     849              :     bool existTractionSubstation(const std::string& substationId);
     850              : 
     851              :     /// @brief string constants for simstep stages
     852              :     static const std::string STAGE_EVENTS;
     853              :     static const std::string STAGE_MOVEMENTS;
     854              :     static const std::string STAGE_LANECHANGE;
     855              :     static const std::string STAGE_INSERTIONS;
     856              :     static const std::string STAGE_REMOTECONTROL;
     857              : 
     858              : protected:
     859              :     /// @brief check all lanes for elevation data
     860              :     bool checkElevation();
     861              : 
     862              :     /// @brief check all lanes for type walkingArea
     863              :     bool checkWalkingarea();
     864              : 
     865              :     /// @brief check wether bidirectional edges occur in the network
     866              :     bool checkBidiEdges();
     867              : 
     868              :     /// @brief remove collisions from the previous simulation step
     869              :     void removeOutdatedCollisions();
     870              : 
     871              :     /** @brief Performs the parts of the simulation step which happen after the move
     872              :      */
     873              :     void postMoveStep();
     874              : 
     875              : protected:
     876              :     /// @brief Unique instance of MSNet
     877              :     static MSNet* myInstance;
     878              : 
     879              :     /// @brief Route loader for dynamic loading of routes
     880              :     SUMORouteLoaderControl* myRouteLoaders;
     881              : 
     882              :     /// @brief Current time step
     883              :     SUMOTime myStep;
     884              : 
     885              :     /// @brief whether libsumo triggered a partial step (executeMove)
     886              :     bool myStepCompletionMissing = false;
     887              : 
     888              :     /// @brief Maximum number of teleports.
     889              :     int myMaxTeleports;
     890              : 
     891              :     /// @brief whether an interrupt occurred
     892              :     bool myAmInterrupted;
     893              : 
     894              : 
     895              : 
     896              :     /// @name Substructures
     897              :     /// @{
     898              : 
     899              :     /// @brief Controls vehicle building and deletion; @see MSVehicleControl
     900              :     MSVehicleControl* myVehicleControl;
     901              :     /// @brief Controls person building and deletion; @see MSTransportableControl
     902              :     MSTransportableControl* myPersonControl;
     903              :     /// @brief Controls container building and deletion; @see MSTransportableControl
     904              :     MSTransportableControl* myContainerControl;
     905              :     /// @brief Controls edges, performs vehicle movement; @see MSEdgeControl
     906              :     MSEdgeControl* myEdges;
     907              :     /// @brief Controls junctions, realizes right-of-way rules; @see MSJunctionControl
     908              :     MSJunctionControl* myJunctions;
     909              :     /// @brief Controls tls logics, realizes waiting on tls rules; @see MSJunctionControl
     910              :     MSTLLogicControl* myLogics;
     911              :     /// @brief Controls vehicle insertion; @see MSInsertionControl
     912              :     MSInsertionControl* myInserter;
     913              :     /// @brief Controls detectors; @see MSDetectorControl
     914              :     MSDetectorControl* myDetectorControl;
     915              :     /// @brief Controls events executed at the begin of a time step; @see MSEventControl
     916              :     MSEventControl* myBeginOfTimestepEvents;
     917              :     /// @brief Controls events executed at the end of a time step; @see MSEventControl
     918              :     MSEventControl* myEndOfTimestepEvents;
     919              :     /// @brief Controls insertion events; @see MSEventControl
     920              :     MSEventControl* myInsertionEvents;
     921              :     /// @brief A container for geometrical shapes; @see ShapeContainer
     922              :     ShapeContainer* myShapeContainer;
     923              :     /// @brief The net's knowledge about edge efforts/travel times; @see MSEdgeWeightsStorage
     924              :     MSEdgeWeightsStorage* myEdgeWeights;
     925              :     /// @}
     926              : 
     927              : 
     928              : 
     929              :     /// @name data needed for computing performance values
     930              :     /// @{
     931              : 
     932              :     /// @brief Information whether the simulation duration shall be logged
     933              :     bool myLogExecutionTime;
     934              : 
     935              :     /// @brief Information whether the number of the simulation step shall be logged
     936              :     bool myLogStepNumber;
     937              :     /// @brief Period between successive step-log outputs
     938              :     int myLogStepPeriod;
     939              : 
     940              :     /// @brief The last simulation step duration
     941              :     long myTraCIStepDuration = 0, mySimStepDuration = 0;
     942              : 
     943              :     /// @brief The overall simulation duration
     944              :     long mySimBeginMillis;
     945              : 
     946              :     /// @brief The overall time spent waiting for traci operations including
     947              :     long myTraCIMillis;
     948              : 
     949              :     /// @brief The overall number of vehicle movements
     950              :     long long int myVehiclesMoved;
     951              :     long long int myPersonsMoved;
     952              :     //}
     953              : 
     954              : 
     955              : 
     956              :     /// @name State output variables
     957              :     /// @{
     958              : 
     959              :     /// @brief Times at which a state shall be written
     960              :     std::vector<SUMOTime> myStateDumpTimes;
     961              :     /// @brief The names for the state files
     962              :     std::vector<std::string> myStateDumpFiles;
     963              :     /// @brief The names of the last K periodic state files (only only K shall be kept)
     964              :     std::vector<std::string> myPeriodicStateFiles;
     965              :     /// @brief The period for writing state
     966              :     SUMOTime myStateDumpPeriod;
     967              :     /// @brief name components for periodic state
     968              :     std::string myStateDumpPrefix;
     969              :     std::string myStateDumpSuffix;
     970              :     /// @}
     971              : 
     972              : 
     973              : 
     974              :     /// @brief Whether the network contains edges which not all vehicles may pass
     975              :     bool myHavePermissions;
     976              : 
     977              :     /// @brief The vehicle class specific speed restrictions
     978              :     std::map<std::string, std::map<SUMOVehicleClass, double> > myRestrictions;
     979              : 
     980              :     /// @brief Preferences for routing
     981              :     std::map<SUMOVehicleClass, std::map<std::string, double> > myVClassPreferences;
     982              :     std::map<std::string, std::map<std::string, double> > myVTypePreferences;
     983              : 
     984              :     /// @brief The edge type specific meso parameters
     985              :     std::map<std::string, MESegment::MesoEdgeType> myMesoEdgeTypes;
     986              : 
     987              :     /// @brief Whether the network contains internal links/lanes/edges
     988              :     bool myHasInternalLinks;
     989              : 
     990              :     /// @brief Whether the network was built with higher speed on junctions
     991              :     bool myJunctionHigherSpeeds;
     992              : 
     993              :     /// @brief Whether the network contains elevation data
     994              :     bool myHasElevation;
     995              : 
     996              :     /// @brief Whether the network contains pedestrian network elements
     997              :     bool myHasPedestrianNetwork;
     998              : 
     999              :     /// @brief Whether the network contains bidirectional rail edges
    1000              :     bool myHasBidiEdges;
    1001              : 
    1002              :     /// @brief Whether the network was built for left-hand traffic
    1003              :     bool myLefthand;
    1004              : 
    1005              :     /// @brief the network version
    1006              :     MMVersion myVersion;
    1007              : 
    1008              :     /// @brief end of loaded edgeData
    1009              :     SUMOTime myEdgeDataEndTime;
    1010              : 
    1011              :     /// @brief Dictionary of bus / container stops
    1012              :     std::map<SumoXMLTag, NamedObjectCont<MSStoppingPlace*> > myStoppingPlaces;
    1013              : 
    1014              :     /// @brief dictionary of named stopping places
    1015              :     std::map<SumoXMLTag, std::map<std::string, std::vector<MSStoppingPlace*> > > myNamedStoppingPlaces;
    1016              : 
    1017              :     /// @brief Dictionary of traction substations
    1018              :     std::vector<MSTractionSubstation*> myTractionSubstations;
    1019              : 
    1020              :     /// @brief Container for vehicle state listener
    1021              :     std::vector<VehicleStateListener*> myVehicleStateListeners;
    1022              : 
    1023              :     /// @brief Container for transportable state listener
    1024              :     std::vector<TransportableStateListener*> myTransportableStateListeners;
    1025              : 
    1026              :     /// @brief collisions in the current time step
    1027              :     CollisionMap myCollisions;
    1028              : 
    1029              : #ifdef HAVE_FOX
    1030              :     /// @brief to avoid concurrent access to the state update function
    1031              :     FXMutex myVehicleStateListenerMutex;
    1032              : 
    1033              :     /// @brief to avoid concurrent access to the state update function
    1034              :     FXMutex myTransportableStateListenerMutex;
    1035              : #endif
    1036              :     static const NamedObjectCont<MSStoppingPlace*> myEmptyStoppingPlaceCont;
    1037              :     static const std::vector<MSStoppingPlace*> myEmptyStoppingPlaceVector;
    1038              : 
    1039              :     /// @brief container to record warnings that shall only be issued once
    1040              :     std::map<std::string, bool> myWarnedOnce;
    1041              : 
    1042              :     /* @brief The router instance for routing by trigger and by traci
    1043              :      * @note MSDevice_Routing has its own instance since it uses a different weight function
    1044              :      * @note we provide one member for every switchable router type
    1045              :      * because the class structure makes it inconvenient to use a superclass
    1046              :      */
    1047              :     mutable std::map<int, MSVehicleRouter*> myRouterTT;
    1048              :     mutable std::map<int, MSVehicleRouter*> myRouterEffort;
    1049              :     mutable std::map<int, MSPedestrianRouter*> myPedestrianRouter;
    1050              :     mutable std::map<int, MSTransportableRouter*> myIntermodalRouter;
    1051              : 
    1052              :     /// @brief An RTree structure holding lane IDs
    1053              :     mutable std::pair<bool, NamedRTree> myLanesRTree;
    1054              : 
    1055              :     /// @brief Updater for dynamic shapes that are tracking traffic objects
    1056              :     ///        (ensures removal of shape dynamics when the objects are removed)
    1057              :     /// @see utils/shapes/PolygonDynamics
    1058              :     std::unique_ptr<MSDynamicShapeUpdater> myDynamicShapeUpdater;
    1059              : 
    1060              : private:
    1061              :     /// @brief Invalidated copy constructor.
    1062              :     MSNet(const MSNet&);
    1063              : 
    1064              :     /// @brief Invalidated assignment operator.
    1065              :     MSNet& operator=(const MSNet&);
    1066              : 
    1067              : 
    1068              : };
        

Generated by: LCOV version 2.0-1