LCOV - code coverage report
Current view: top level - src/microsim - MSNet.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 94.7 % 38 36
Test Date: 2026-05-24 16:29:35 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-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    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*, RouterProhibition> 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           37 :     virtual bool isGUINet() const {
     145           37 :         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         2414 :         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 = nullptr);
     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     41619473 :         return myHavePermissions;
     215              :     }
     216              : 
     217              : 
     218              :     /// @brief Labels the network to contain vehicle class permissions
     219              :     void setPermissionsFound() {
     220       938183 :         myHavePermissions = true;
     221       938183 :     }
     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   2627895515 :         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         9367 :         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              : 
     353              :     SUMOTime getLoaderTime() const;
     354              : 
     355              :     void setLoaderTime(SUMOTime time);
     356              : 
     357              :     /// @brief return the next time for route loading the time of state loading
     358              :     SUMOTime getStateLoaderTime() const {
     359       359173 :         return myStateLoaderTime;
     360              :     }
     361              : 
     362              :     /** @brief Write netstate, summary and detector output
     363              :      * @todo Which exceptions may occur?
     364              :      */
     365              :     void writeOutput();
     366              : 
     367              : 
     368              :     /** @brief Returns whether duration shall be logged
     369              :      * @return Whether duration shall be logged
     370              :      */
     371              :     bool logSimulationDuration() const;
     372              : 
     373              : 
     374              : 
     375              :     /// @name Output during the simulation
     376              :     //@{
     377              : 
     378              :     /** @brief Prints the current step number
     379              :      *
     380              :      * Called on the begin of a simulation step
     381              :      */
     382              :     void preSimStepOutput() const;
     383              : 
     384              : 
     385              :     /** @brief Prints the statistics of the step at its end
     386              :      *
     387              :      * Called on the end of a simulation step
     388              :      */
     389              :     void postSimStepOutput() const;
     390              :     //}
     391              : 
     392              : 
     393              : 
     394              :     /// @name Retrieval of references to substructures
     395              :     /// @{
     396              : 
     397              :     /** @brief Returns the vehicle control
     398              :      * @return The vehicle control
     399              :      * @see MSVehicleControl
     400              :      * @see myVehicleControl
     401              :      */
     402              :     MSVehicleControl& getVehicleControl() {
     403    544699528 :         return *myVehicleControl;
     404              :     }
     405              : 
     406              : 
     407              :     /** @brief Returns the person control
     408              :      *
     409              :      * If the person control does not exist, yet, it is created.
     410              :      *
     411              :      * @return The person control
     412              :      * @see MSPersonControl
     413              :      * @see myPersonControl
     414              :      */
     415              :     virtual MSTransportableControl& getPersonControl();
     416              : 
     417              :     /** @brief Returns whether persons are simulated
     418              :      */
     419              :     bool hasPersons() const {
     420    483581315 :         return myPersonControl != nullptr;
     421              :     }
     422              : 
     423              :     /** @brief Returns the container control
     424              :      *
     425              :      * If the container control does not exist, yet, it is created.
     426              :      *
     427              :      * @return The container control
     428              :      * @see MSContainerControl
     429              :      * @see myContainerControl
     430              :      */
     431              :     virtual MSTransportableControl& getContainerControl();
     432              : 
     433              :     /** @brief Returns whether containers are simulated
     434              :     */
     435              :     bool hasContainers() const {
     436     50251815 :         return myContainerControl != nullptr;
     437              :     }
     438              : 
     439              : 
     440              :     /** @brief Returns the edge control
     441              :      * @return The edge control
     442              :      * @see MSEdgeControl
     443              :      * @see myEdges
     444              :      */
     445              :     MSEdgeControl& getEdgeControl() {
     446    176696263 :         return *myEdges;
     447              :     }
     448              : 
     449              : 
     450              :     /** @brief Returns the insertion control
     451              :      * @return The insertion control
     452              :      * @see MSInsertionControl
     453              :      * @see myInserter
     454              :      */
     455              :     MSInsertionControl& getInsertionControl() {
     456     21235522 :         return *myInserter;
     457              :     }
     458              : 
     459              : 
     460              :     /** @brief Returns the detector control
     461              :      * @return The detector control
     462              :      * @see MSDetectorControl
     463              :      * @see myDetectorControl
     464              :      */
     465              :     MSDetectorControl& getDetectorControl() {
     466       265303 :         return *myDetectorControl;
     467              :     }
     468              : 
     469              : 
     470              :     /** @brief Returns the tls logics control
     471              :      * @return The tls logics control
     472              :      * @see MSTLLogicControl
     473              :      * @see myLogics
     474              :      */
     475              :     MSTLLogicControl& getTLSControl() {
     476       372266 :         return *myLogics;
     477              :     }
     478              : 
     479              : 
     480              :     /** @brief Returns the junctions control
     481              :      * @return The junctions control
     482              :      * @see MSJunctionControl
     483              :      * @see myJunctions
     484              :      */
     485              :     MSJunctionControl& getJunctionControl() {
     486        31834 :         return *myJunctions;
     487              :     }
     488              : 
     489              : 
     490              :     /** @brief Returns the event control for events executed at the begin of a time step
     491              :      * @return The control responsible for events that are executed at the begin of a time step
     492              :      * @see MSEventControl
     493              :      * @see myBeginOfTimestepEvents
     494              :      */
     495              :     MSEventControl* getBeginOfTimestepEvents() {
     496       358277 :         return myBeginOfTimestepEvents;
     497              :     }
     498              : 
     499              : 
     500              :     /** @brief Returns the event control for events executed at the end of a time step
     501              :      * @return The control responsible for events that are executed at the end of a time step
     502              :      * @see MSEventControl
     503              :      * @see myEndOfTimestepEvents
     504              :      */
     505              :     MSEventControl* getEndOfTimestepEvents() {
     506        28666 :         return myEndOfTimestepEvents;
     507              :     }
     508              : 
     509              : 
     510              :     /** @brief Returns the event control for insertion events
     511              :      * @return The control responsible for insertion events
     512              :      * @see MSEventControl
     513              :      * @see myInsertionEvents
     514              :      */
     515              :     MSEventControl* getInsertionEvents() {
     516      1388467 :         return myInsertionEvents;
     517              :     }
     518              : 
     519              : 
     520              :     /** @brief Returns the shapes container
     521              :      * @return The shapes container
     522              :      * @see ShapeContainer
     523              :      * @see myShapeContainer
     524              :      */
     525              :     ShapeContainer& getShapeContainer() {
     526       117093 :         return *myShapeContainer;
     527              :     }
     528              : 
     529              :     /** @brief Returns the dynamic shapes updater
     530              :      * @see PolygonDynamics
     531              :      */
     532              :     MSDynamicShapeUpdater* getDynamicShapeUpdater() {
     533              :         return myDynamicShapeUpdater.get();
     534              :     }
     535              : 
     536              :     /** @brief Creates and returns a dynamic shapes updater
     537              :      * @see PolygonDynamics
     538              :      */
     539              :     MSDynamicShapeUpdater* makeDynamicShapeUpdater();
     540              : 
     541              :     /** @brief Returns the net's internal edge travel times/efforts container
     542              :      *
     543              :      * If the net does not have such a container, it is built.
     544              :      * @return The net's knowledge about edge weights
     545              :      */
     546              :     MSEdgeWeightsStorage& getWeightsStorage();
     547              :     /// @}
     548              : 
     549              :     /// @name Insertion and retrieval of stopping places
     550              :     /// @{
     551              : 
     552              :     /** @brief Adds a stopping place
     553              :      *
     554              :      * If another stop with the same id and category exists, false is returned.
     555              :      *  Otherwise, the stop is added to the internal stopping place container.
     556              :      *
     557              :      * This control gets responsible for deletion of the added stop.
     558              :      *
     559              :      * @param[in] stop The stop to add
     560              :      * @return Whether the stop could be added
     561              :      */
     562              :     bool addStoppingPlace(SumoXMLTag category, MSStoppingPlace* stop);
     563              : 
     564              : 
     565              :     /** @brief Adds a traction substation
     566              :      *
     567              :      * If another traction substation with the same id and category exists, false is returned.
     568              :      *  Otherwise, the traction substation is added to the internal substations container.
     569              :      *
     570              :      * @param[in] substation The traction substation to add
     571              :      * @return Whether the stop could be added
     572              :      */
     573              :     bool addTractionSubstation(MSTractionSubstation* substation);
     574              : 
     575              : 
     576              :     /** @brief Returns the named stopping place of the given category
     577              :      * @param[in] id The id of the stop to return.
     578              :      * @param[in] category The type of stop
     579              :      * @return The named stop, or 0 if no such stop exists
     580              :      */
     581              :     MSStoppingPlace* getStoppingPlace(const std::string& id, const SumoXMLTag category) const;
     582              : 
     583              :     /** @brief Returns the named stopping place by looking through all categories
     584              :      * @param[in] id The id of the stop to return.
     585              :      * @return The named stop, or 0 if no such stop exists
     586              :      */
     587              :     MSStoppingPlace* getStoppingPlace(const std::string& id) const;
     588              : 
     589              :     /** @brief Returns the stop of the given category close to the given position
     590              :      * @param[in] lane the lane of the stop to return.
     591              :      * @param[in] pos the position of the stop to return.
     592              :      * @param[in] category The type of stop
     593              :      * @return The stop id on the location, or "" if no such stop exists
     594              :      */
     595              :     std::string getStoppingPlaceID(const MSLane* lane, const double pos, const SumoXMLTag category) const;
     596              : 
     597              :     /* @brief returns all stopping places of that category with the same (non-empty) name attribute
     598              :      */
     599              :     const std::vector<MSStoppingPlace*>& getStoppingPlaceAlternatives(const std::string& name, SumoXMLTag category) const;
     600              :     /// @}
     601              : 
     602              :     const NamedObjectCont<MSStoppingPlace*>& getStoppingPlaces(SumoXMLTag category) const;
     603              : 
     604              :     /// @brief write charging station output
     605              :     void writeChargingStationOutput() const;
     606              : 
     607              :     /// @brief write rail signal block output
     608              :     void writeRailSignalBlocks() const;
     609              : 
     610              :     /// @brief creates a wrapper for the given logic (see GUINet)
     611           62 :     virtual void createTLWrapper(MSTrafficLightLogic*) {};
     612              : 
     613              :     /// @brief write the output generated by an overhead wire segment
     614              :     void writeOverheadWireSegmentOutput() const;
     615              : 
     616              :     /// @brief write electrical substation output
     617              :     void writeSubstationOutput() const;
     618              : 
     619              :     /// @brief return wheter the given logic (or rather its wrapper) is selected in the GUI
     620            0 :     virtual bool isSelected(const MSTrafficLightLogic*) const {
     621            0 :         return false;
     622              :     }
     623              :     /// @brief update view after simulation.loadState
     624          120 :     virtual void updateGUI() const { }
     625              : 
     626              :     /// @brief load state from file and return new time
     627              :     SUMOTime loadState(const std::string& fileName, const bool catchExceptions);
     628              : 
     629              :     /// @brief reset state to the beginning without reloading the network
     630              :     void quickReload();
     631              : 
     632              :     /// @name Notification about vehicle state changes
     633              :     /// @{
     634              : 
     635              :     /// @brief Definition of a vehicle state
     636              :     enum class VehicleState {
     637              :         /// @brief The vehicle was built, but has not yet departed
     638              :         BUILT,
     639              :         /// @brief The vehicle has departed (was inserted into the network)
     640              :         DEPARTED,
     641              :         /// @brief The vehicle started to teleport
     642              :         STARTING_TELEPORT,
     643              :         /// @brief The vehicle ended being teleported
     644              :         ENDING_TELEPORT,
     645              :         /// @brief The vehicle arrived at his destination (is deleted)
     646              :         ARRIVED,
     647              :         /// @brief The vehicle got a new route
     648              :         NEWROUTE,
     649              :         /// @brief The vehicles starts to park
     650              :         STARTING_PARKING,
     651              :         /// @brief The vehicle ends to park
     652              :         ENDING_PARKING,
     653              :         /// @brief The vehicles starts to stop
     654              :         STARTING_STOP,
     655              :         /// @brief The vehicle ends to stop
     656              :         ENDING_STOP,
     657              :         /// @brief The vehicle is involved in a collision
     658              :         COLLISION,
     659              :         /// @brief The vehicle had to brake harder than permitted
     660              :         EMERGENCYSTOP,
     661              :         /// @brief Vehicle maneuvering either entering or exiting a parking space
     662              :         MANEUVERING
     663              :     };
     664              : 
     665              : 
     666              :     /** @class VehicleStateListener
     667              :      * @brief Interface for objects listening to vehicle state changes
     668              :      */
     669              :     class VehicleStateListener {
     670              :     public:
     671              :         /// @brief Constructor
     672         4185 :         VehicleStateListener() { }
     673              : 
     674              :         /// @brief Destructor
     675              :         virtual ~VehicleStateListener() { }
     676              : 
     677              :         /** @brief Called if a vehicle changes its state
     678              :          * @param[in] vehicle The vehicle which changed its state
     679              :          * @param[in] to The state the vehicle has changed to
     680              :          * @param[in] info Additional information on the state change
     681              :          */
     682              :         virtual void vehicleStateChanged(const SUMOVehicle* const vehicle, VehicleState to, const std::string& info = "") = 0;
     683              : 
     684              :     };
     685              : 
     686              : 
     687              :     /** @brief Adds a vehicle states listener
     688              :      * @param[in] listener The listener to add
     689              :      */
     690              :     void addVehicleStateListener(VehicleStateListener* listener);
     691              : 
     692              : 
     693              :     /** @brief Removes a vehicle states listener
     694              :      * @param[in] listener The listener to remove
     695              :      */
     696              :     void removeVehicleStateListener(VehicleStateListener* listener);
     697              : 
     698              : 
     699              :     /** @brief Informs all added listeners about a vehicle's state change
     700              :      * @param[in] vehicle The vehicle which changed its state
     701              :      * @param[in] to The state the vehicle has changed to
     702              :      * @param[in] info Information regarding the replacement
     703              :      * @see VehicleStateListener:vehicleStateChanged
     704              :      */
     705              :     void informVehicleStateListener(const SUMOVehicle* const vehicle, VehicleState to, const std::string& info = "");
     706              :     /// @}
     707              : 
     708              : 
     709              :     /// @name Notification about transportable state changes
     710              :     /// @{
     711              : 
     712              :     /// @brief Definition of a transportable state
     713              :     enum class TransportableState {
     714              :         /// @brief The transportable person has departed (was inserted into the network)
     715              :         PERSON_DEPARTED,
     716              :         /// @brief The transportable person arrived at his destination (is deleted)
     717              :         PERSON_ARRIVED,
     718              :         /// @brief The transportable container has departed (was inserted into the network)
     719              :         CONTAINER_DEPARTED,
     720              :         /// @brief The transportable container arrived at his destination (is deleted)
     721              :         CONTAINER_ARRIVED
     722              :     };
     723              : 
     724              : 
     725              :     /** @class TransportableStateListener
     726              :      * @brief Interface for objects listening to transportable state changes
     727              :      */
     728              :     class TransportableStateListener {
     729              :     public:
     730              :         /// @brief Constructor
     731         2759 :         TransportableStateListener() { }
     732              : 
     733              :         /// @brief Destructor
     734              :         virtual ~TransportableStateListener() { }
     735              : 
     736              :         /** @brief Called if a transportable changes its state
     737              :          * @param[in] transportable The transportable which changed its state
     738              :          * @param[in] to The state the transportable has changed to
     739              :          * @param[in] info Additional information on the state change
     740              :          */
     741              :         virtual void transportableStateChanged(const MSTransportable* const transportable, TransportableState to, const std::string& info = "") = 0;
     742              : 
     743              :     };
     744              : 
     745              : 
     746              :     /** @brief Adds a transportable states listener
     747              :      * @param[in] listener The listener to add
     748              :      */
     749              :     void addTransportableStateListener(TransportableStateListener* listener);
     750              : 
     751              : 
     752              :     /** @brief Removes a transportable states listener
     753              :      * @param[in] listener The listener to remove
     754              :      */
     755              :     void removeTransportableStateListener(TransportableStateListener* listener);
     756              : 
     757              : 
     758              :     /** @brief Informs all added listeners about a transportable's state change
     759              :      * @param[in] transportable The transportable which changed its state
     760              :      * @param[in] to The state the transportable has changed to
     761              :      * @param[in] info Information regarding the replacement
     762              :      * @see TransportableStateListener:TransportableStateChanged
     763              :      */
     764              :     void informTransportableStateListener(const MSTransportable* const transportable, TransportableState to, const std::string& info = "");
     765              :     /// @}
     766              : 
     767              : 
     768              :     /// @brief register collision and return whether it was the first one involving these vehicles
     769              :     bool registerCollision(const SUMOTrafficObject* collider, const SUMOTrafficObject* victim, const std::string& collisionType, const MSLane* lane, double pos);
     770              : 
     771              :     const CollisionMap& getCollisions() const {
     772              :         return myCollisions;
     773              :     }
     774              : 
     775              : 
     776              :     /** @brief Returns the travel time to pass an edge
     777              :      * @param[in] e The edge for which the travel time to be passed shall be returned
     778              :      * @param[in] v The vehicle that is rerouted
     779              :      * @param[in] t The time for which the travel time shall be returned [s]
     780              :      * @return The travel time for an edge
     781              :      * @see DijkstraRouter_ByProxi
     782              :      */
     783              :     static double getTravelTime(const MSEdge* const e, const SUMOVehicle* const v, double t);
     784              : 
     785              : 
     786              :     /** @brief Returns the effort to pass an edge
     787              :      * @param[in] e The edge for which the effort to be passed shall be returned
     788              :      * @param[in] v The vehicle that is rerouted
     789              :      * @param[in] t The time for which the effort shall be returned [s]
     790              :      * @return The effort (abstract) for an edge
     791              :      * @see DijkstraRouter_ByProxi
     792              :      */
     793              :     static double getEffort(const MSEdge* const e, const SUMOVehicle* const v, double t);
     794              : 
     795              : 
     796              :     /* @brief get the router, initialize on first use
     797              :      * @param[in] prohibited The vector of forbidden edges (optional)
     798              :      */
     799              :     MSVehicleRouter& getRouterTT(int rngIndex, const Prohibitions& prohibited = {}) const;
     800              :     MSVehicleRouter& getRouterEffort(int rngIndex, const Prohibitions& prohibited = {}) const;
     801              :     MSPedestrianRouter& getPedestrianRouter(int rngIndex, const Prohibitions& prohibited = {}) const;
     802              :     MSTransportableRouter& getIntermodalRouter(int rngIndex, const int routingMode = 0, const Prohibitions& prohibited = {}) const;
     803              : 
     804              :     /// @brief force reconstruction of intermodal network
     805              :     void resetIntermodalRouter() const;
     806              : 
     807              :     static void adaptIntermodalRouter(MSTransportableRouter& router);
     808              : 
     809              : 
     810              :     /// @brief return whether the network contains internal links
     811              :     bool hasInternalLinks() const {
     812       318264 :         return myHasInternalLinks;
     813              :     }
     814              : 
     815              :     /// @brief return whether the network was built with higher junction speeds
     816              :     bool hasJunctionHigherSpeeds() const {
     817           24 :         return myJunctionHigherSpeeds;
     818              :     }
     819              : 
     820              :     /// @brief return whether the network contains elevation data
     821              :     bool hasElevation() const {
     822   1582892151 :         return myHasElevation;
     823              :     }
     824              : 
     825              :     /// @brief return whether the network contains walkingareas and crossings
     826              :     bool hasPedestrianNetwork() const {
     827       124920 :         return myHasPedestrianNetwork;
     828              : 
     829              :     }
     830              :     /// @brief return whether the network contains bidirectional rail edges
     831              :     bool hasBidiEdges() const {
     832      2868609 :         return myHasBidiEdges;
     833              :     }
     834              : 
     835              :     /// @brief return the network version
     836              :     MMVersion getNetworkVersion() const {
     837        12238 :         return myVersion;
     838              :     }
     839              : 
     840              :     /// @brief return whether a warning regarding the given object shall be issued
     841              :     bool warnOnce(const std::string& typeAndID);
     842              : 
     843              :     void interrupt() {
     844            8 :         myAmInterrupted = true;
     845            8 :     }
     846              : 
     847              :     bool isInterrupted() const {
     848            8 :         return myAmInterrupted;
     849              :     }
     850              : 
     851              :     /// @brief gui may prevent final meanData reset to keep live data visible
     852     16814093 :     virtual bool skipFinalReset() const {
     853     16814093 :         return false;
     854              :     }
     855              : 
     856              :     MSMapMatcher* getMapMatcher() const;
     857              : 
     858              :     /// @brief find electrical substation by its id
     859              :     MSTractionSubstation* findTractionSubstation(const std::string& substationId);
     860              : 
     861              :     /// @brief string constants for simstep stages
     862              :     static const std::string STAGE_EVENTS;
     863              :     static const std::string STAGE_MOVEMENTS;
     864              :     static const std::string STAGE_LANECHANGE;
     865              :     static const std::string STAGE_INSERTIONS;
     866              :     static const std::string STAGE_REMOTECONTROL;
     867              : 
     868              : protected:
     869              :     /// @brief check all lanes for elevation data
     870              :     bool checkElevation();
     871              : 
     872              :     /// @brief check all lanes for type walkingArea
     873              :     bool checkWalkingarea();
     874              : 
     875              :     /// @brief check wether bidirectional edges occur in the network
     876              :     bool checkBidiEdges();
     877              : 
     878              :     /// @brief remove collisions from the previous simulation step
     879              :     void removeOutdatedCollisions();
     880              : 
     881              :     /** @brief Performs the parts of the simulation step which happen after the move
     882              :      */
     883              :     void postMoveStep();
     884              : 
     885              : protected:
     886              :     /// @brief Unique instance of MSNet
     887              :     static MSNet* myInstance;
     888              : 
     889              :     /// @brief Route loader for dynamic loading of routes
     890              :     SUMORouteLoaderControl* myRouteLoaders;
     891              : 
     892              :     /// @brief Current time step
     893              :     SUMOTime myStep;
     894              : 
     895              :     /* @brief the time for rejecting vehicle that departed in the past are were already loaded.
     896              :      * When not loading state, this value is the simulation begin time.
     897              :      * When loading state, this is the time up to which vehicles have been
     898              :      * loaded before saving state. This is typically after the state time.
     899              :      * The state will include vehicles up to this time and they should not be
     900              :      * loaded again from a route file. Uniqueness of ids is not a sufficient
     901              :      * guard against loading again because these vehicles could arrive shortly after state loading. */
     902              :     SUMOTime myStateLoaderTime;
     903              : 
     904              :     /// @brief whether libsumo triggered a partial step (executeMove)
     905              :     bool myStepCompletionMissing = false;
     906              : 
     907              :     /// @brief Maximum number of teleports.
     908              :     int myMaxTeleports;
     909              : 
     910              :     /// @brief whether an interrupt occurred
     911              :     bool myAmInterrupted;
     912              : 
     913              : 
     914              : 
     915              :     /// @name Substructures
     916              :     /// @{
     917              : 
     918              :     /// @brief Controls vehicle building and deletion; @see MSVehicleControl
     919              :     MSVehicleControl* myVehicleControl;
     920              :     /// @brief Controls person building and deletion; @see MSTransportableControl
     921              :     MSTransportableControl* myPersonControl;
     922              :     /// @brief Controls container building and deletion; @see MSTransportableControl
     923              :     MSTransportableControl* myContainerControl;
     924              :     /// @brief Controls edges, performs vehicle movement; @see MSEdgeControl
     925              :     MSEdgeControl* myEdges;
     926              :     /// @brief Controls junctions, realizes right-of-way rules; @see MSJunctionControl
     927              :     MSJunctionControl* myJunctions;
     928              :     /// @brief Controls tls logics, realizes waiting on tls rules; @see MSJunctionControl
     929              :     MSTLLogicControl* myLogics;
     930              :     /// @brief Controls vehicle insertion; @see MSInsertionControl
     931              :     MSInsertionControl* myInserter;
     932              :     /// @brief Controls detectors; @see MSDetectorControl
     933              :     MSDetectorControl* myDetectorControl;
     934              :     /// @brief Controls events executed at the begin of a time step; @see MSEventControl
     935              :     MSEventControl* myBeginOfTimestepEvents;
     936              :     /// @brief Controls events executed at the end of a time step; @see MSEventControl
     937              :     MSEventControl* myEndOfTimestepEvents;
     938              :     /// @brief Controls insertion events; @see MSEventControl
     939              :     MSEventControl* myInsertionEvents;
     940              :     /// @brief A container for geometrical shapes; @see ShapeContainer
     941              :     ShapeContainer* myShapeContainer;
     942              :     /// @brief The net's knowledge about edge efforts/travel times; @see MSEdgeWeightsStorage
     943              :     MSEdgeWeightsStorage* myEdgeWeights;
     944              :     /// @}
     945              : 
     946              : 
     947              : 
     948              :     /// @name data needed for computing performance values
     949              :     /// @{
     950              : 
     951              :     /// @brief Information whether the simulation duration shall be logged
     952              :     bool myLogExecutionTime;
     953              : 
     954              :     /// @brief Information whether the number of the simulation step shall be logged
     955              :     bool myLogStepNumber;
     956              :     /// @brief Period between successive step-log outputs
     957              :     int myLogStepPeriod;
     958              : 
     959              :     /// @brief The last simulation step duration
     960              :     long myTraCIStepDuration = 0, mySimStepDuration = 0;
     961              : 
     962              :     /// @brief The overall simulation duration
     963              :     long mySimBeginMillis;
     964              : 
     965              :     /// @brief The overall time spent waiting for traci operations including
     966              :     long myTraCIMillis;
     967              : 
     968              :     /// @brief The overall number of vehicle movements
     969              :     long long int myVehiclesMoved;
     970              :     long long int myPersonsMoved;
     971              :     //}
     972              : 
     973              : 
     974              : 
     975              :     /// @name State output variables
     976              :     /// @{
     977              : 
     978              :     /// @brief Times at which a state shall be written
     979              :     std::vector<SUMOTime> myStateDumpTimes;
     980              :     /// @brief The names for the state files
     981              :     std::vector<std::string> myStateDumpFiles;
     982              :     /// @brief The names of the last K periodic state files (only only K shall be kept)
     983              :     std::vector<std::string> myPeriodicStateFiles;
     984              :     /// @brief The period for writing state
     985              :     SUMOTime myStateDumpPeriod;
     986              :     /// @brief name components for periodic state
     987              :     std::string myStateDumpPrefix;
     988              :     std::string myStateDumpSuffix;
     989              :     /// @}
     990              : 
     991              : 
     992              : 
     993              :     /// @brief Whether the network contains edges which not all vehicles may pass
     994              :     bool myHavePermissions;
     995              : 
     996              :     /// @brief The vehicle class specific speed restrictions
     997              :     std::map<std::string, std::map<SUMOVehicleClass, double> > myRestrictions;
     998              : 
     999              :     /// @brief Preferences for routing
    1000              :     std::map<SUMOVehicleClass, std::map<std::string, double> > myVClassPreferences;
    1001              :     std::map<std::string, std::map<std::string, double> > myVTypePreferences;
    1002              : 
    1003              :     /// @brief The edge type specific meso parameters
    1004              :     std::map<std::string, MESegment::MesoEdgeType> myMesoEdgeTypes;
    1005              : 
    1006              :     /// @brief Whether the network contains internal links/lanes/edges
    1007              :     bool myHasInternalLinks;
    1008              : 
    1009              :     /// @brief Whether the network was built with higher speed on junctions
    1010              :     bool myJunctionHigherSpeeds;
    1011              : 
    1012              :     /// @brief Whether the network contains elevation data
    1013              :     bool myHasElevation;
    1014              : 
    1015              :     /// @brief Whether the network contains pedestrian network elements
    1016              :     bool myHasPedestrianNetwork;
    1017              : 
    1018              :     /// @brief Whether the network contains bidirectional rail edges
    1019              :     bool myHasBidiEdges;
    1020              : 
    1021              :     /// @brief the network version
    1022              :     MMVersion myVersion;
    1023              : 
    1024              :     /// @brief end of loaded edgeData
    1025              :     SUMOTime myEdgeDataEndTime;
    1026              : 
    1027              :     /// @brief Dictionary of bus / container stops
    1028              :     std::map<SumoXMLTag, NamedObjectCont<MSStoppingPlace*> > myStoppingPlaces;
    1029              : 
    1030              :     /// @brief dictionary of named stopping places
    1031              :     std::map<SumoXMLTag, std::map<std::string, std::vector<MSStoppingPlace*> > > myNamedStoppingPlaces;
    1032              : 
    1033              :     /// @brief Dictionary of traction substations
    1034              :     std::vector<MSTractionSubstation*> myTractionSubstations;
    1035              : 
    1036              :     /// @brief Container for vehicle state listener
    1037              :     std::vector<VehicleStateListener*> myVehicleStateListeners;
    1038              : 
    1039              :     /// @brief Container for transportable state listener
    1040              :     std::vector<TransportableStateListener*> myTransportableStateListeners;
    1041              : 
    1042              :     /// @brief collisions in the current time step
    1043              :     CollisionMap myCollisions;
    1044              : 
    1045              : #ifdef HAVE_FOX
    1046              :     /// @brief to avoid concurrent access to the state update function
    1047              :     FXMutex myVehicleStateListenerMutex;
    1048              : 
    1049              :     /// @brief to avoid concurrent access to the state update function
    1050              :     FXMutex myTransportableStateListenerMutex;
    1051              : #endif
    1052              :     static const NamedObjectCont<MSStoppingPlace*> myEmptyStoppingPlaceCont;
    1053              :     static const std::vector<MSStoppingPlace*> myEmptyStoppingPlaceVector;
    1054              : 
    1055              :     /// @brief container to record warnings that shall only be issued once
    1056              :     std::map<std::string, bool> myWarnedOnce;
    1057              : 
    1058              :     /* @brief The router instance for routing by trigger and by traci
    1059              :      * @note MSDevice_Routing has its own instance since it uses a different weight function
    1060              :      * @note we provide one member for every switchable router type
    1061              :      * because the class structure makes it inconvenient to use a superclass
    1062              :      */
    1063              :     mutable std::map<int, MSVehicleRouter*> myRouterTT;
    1064              :     mutable std::map<int, MSVehicleRouter*> myRouterEffort;
    1065              :     mutable std::map<int, MSPedestrianRouter*> myPedestrianRouter;
    1066              :     mutable std::map<int, MSTransportableRouter*> myIntermodalRouter;
    1067              : 
    1068              :     /// @brief An RTree structure holding lane IDs
    1069              :     mutable std::pair<bool, NamedRTree> myLanesRTree;
    1070              : 
    1071              :     /// @brief Updater for dynamic shapes that are tracking traffic objects
    1072              :     ///        (ensures removal of shape dynamics when the objects are removed)
    1073              :     /// @see utils/shapes/PolygonDynamics
    1074              :     std::unique_ptr<MSDynamicShapeUpdater> myDynamicShapeUpdater;
    1075              : 
    1076              : private:
    1077              :     /// @brief Invalidated copy constructor.
    1078              :     MSNet(const MSNet&);
    1079              : 
    1080              :     /// @brief Invalidated assignment operator.
    1081              :     MSNet& operator=(const MSNet&);
    1082              : 
    1083              : 
    1084              : };
        

Generated by: LCOV version 2.0-1