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

Generated by: LCOV version 2.0-1