LCOV - code coverage report
Current view: top level - src/microsim - MSNet.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 95.5 % 964 921
Test Date: 2026-10-12 15:53:19 Functions: 95.9 % 74 71

            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.cpp
      15              : /// @author  Christian Roessel
      16              : /// @author  Daniel Krajzewicz
      17              : /// @author  Jakob Erdmann
      18              : /// @author  Clemens Honomichl
      19              : /// @author  Eric Nicolay
      20              : /// @author  Mario Krumnow
      21              : /// @author  Michael Behrisch
      22              : /// @author  Christoph Sommer
      23              : /// @date    Tue, 06 Mar 2001
      24              : ///
      25              : // The simulated network and simulation performer
      26              : /****************************************************************************/
      27              : #include <config.h>
      28              : 
      29              : #ifdef HAVE_VERSION_H
      30              : #include <version.h>
      31              : #endif
      32              : 
      33              : #include <string>
      34              : #include <iostream>
      35              : #include <sstream>
      36              : #include <typeinfo>
      37              : #include <algorithm>
      38              : #include <cassert>
      39              : #include <vector>
      40              : #include <ctime>
      41              : 
      42              : #ifdef HAVE_FOX
      43              : #include <utils/common/ScopedLocker.h>
      44              : #endif
      45              : #include <utils/common/MsgHandler.h>
      46              : #include <utils/common/ToString.h>
      47              : #include <utils/common/SysUtils.h>
      48              : #include <utils/common/UtilExceptions.h>
      49              : #include <utils/common/WrappingCommand.h>
      50              : #include <utils/common/SystemFrame.h>
      51              : #include <utils/geom/GeoConvHelper.h>
      52              : #include <utils/iodevices/OutputDevice_File.h>
      53              : #include <utils/iodevices/OutputDevice.h>
      54              : #include <utils/options/OptionsCont.h>
      55              : #include <utils/options/OptionsIO.h>
      56              : #include <utils/shapes/ShapeContainer.h>
      57              : #include <utils/router/DijkstraRouter.h>
      58              : #include <utils/router/AStarRouter.h>
      59              : #include <utils/router/CCHGraph.h>
      60              : #include <utils/router/CCHRouter.h>
      61              : #include <utils/router/IntermodalRouter.h>
      62              : #include <utils/router/PedestrianRouter.h>
      63              : #include <utils/vehicle/SUMORouteLoaderControl.h>
      64              : #include <utils/vehicle/SUMORouteLoader.h>
      65              : #include <utils/vehicle/SUMOVehicleParserHelper.h>
      66              : #include <utils/xml/XMLSubSys.h>
      67              : #include <traci-server/TraCIServer.h>
      68              : #include <libsumo/Helper.h>
      69              : #include <libsumo/Simulation.h>
      70              : #include <mesosim/MELoop.h>
      71              : #include <mesosim/MESegment.h>
      72              : #include <microsim/output/MSDetectorControl.h>
      73              : #include <microsim/MSVehicleTransfer.h>
      74              : #include <microsim/devices/MSRoutingEngine.h>
      75              : #include <microsim/devices/MSDevice_Vehroutes.h>
      76              : #include <microsim/devices/MSDevice_Tripinfo.h>
      77              : #include <microsim/devices/MSDevice_BTsender.h>
      78              : #include <microsim/devices/MSDevice_SSM.h>
      79              : #include <microsim/devices/MSDevice_ElecHybrid.h>
      80              : #include <microsim/devices/MSDevice_ToC.h>
      81              : #include <microsim/devices/MSDevice_Taxi.h>
      82              : #include <microsim/output/MSBatteryExport.h>
      83              : #include <microsim/output/MSChargingStationExport.h>
      84              : #include <microsim/output/MSElecHybridExport.h>
      85              : #include <microsim/output/MSEmissionExport.h>
      86              : #include <microsim/output/MSFCDExport.h>
      87              : #include <microsim/output/MSFullExport.h>
      88              : #include <microsim/output/MSQueueExport.h>
      89              : #include <microsim/output/MSVTKExport.h>
      90              : #include <microsim/output/MSXMLRawOut.h>
      91              : #include <microsim/output/MSAmitranTrajectories.h>
      92              : #include <microsim/output/MSStopOut.h>
      93              : #include <microsim/transportables/MSPModel.h>
      94              : #include <microsim/transportables/MSPerson.h>
      95              : #include <microsim/traffic_lights/MSTrafficLightLogic.h>
      96              : #include <microsim/transportables/MSTransportableControl.h>
      97              : #include <microsim/traffic_lights/MSRailSignal.h>
      98              : #include <microsim/traffic_lights/MSRailSignalConstraint.h>
      99              : #include <microsim/traffic_lights/MSRailSignalControl.h>
     100              : #include <microsim/traffic_lights/MSTLLogicControl.h>
     101              : #include <microsim/traffic_lights/MSDriveWay.h>
     102              : #include <microsim/trigger/MSCalibrator.h>
     103              : #include <microsim/trigger/MSChargingStation.h>
     104              : #include <microsim/trigger/MSLaneSpeedTrigger.h>
     105              : #include <microsim/trigger/MSOverheadWire.h>
     106              : #include <microsim/trigger/MSTriggeredRerouter.h>
     107              : #include <utils/router/FareModul.h>
     108              : #include <netload/NLBuilder.h>
     109              : 
     110              : #include "MSEdgeControl.h"
     111              : #include "MSJunctionControl.h"
     112              : #include "MSInsertionControl.h"
     113              : #include "MSDynamicShapeUpdater.h"
     114              : #include "MSEventControl.h"
     115              : #include "MSEdge.h"
     116              : #include "MSJunction.h"
     117              : #include "MSJunctionLogic.h"
     118              : #include "MSLane.h"
     119              : #include "MSVehicleControl.h"
     120              : #include "MSVehicleTransfer.h"
     121              : #include "MSRoute.h"
     122              : #include "MSGlobals.h"
     123              : #include "MSEdgeWeightsStorage.h"
     124              : #include "MSStateHandler.h"
     125              : #include "MSFrame.h"
     126              : #include "MSParkingArea.h"
     127              : #include "MSStoppingPlace.h"
     128              : #include "MSNet.h"
     129              : 
     130              : 
     131              : // ===========================================================================
     132              : // debug constants
     133              : // ===========================================================================
     134              : //#define DEBUG_SIMSTEP
     135              : 
     136              : 
     137              : // ===========================================================================
     138              : // static member definitions
     139              : // ===========================================================================
     140              : MSNet* MSNet::myInstance = nullptr;
     141              : 
     142              : const std::string MSNet::STAGE_EVENTS("events");
     143              : const std::string MSNet::STAGE_MOVEMENTS("move");
     144              : const std::string MSNet::STAGE_LANECHANGE("laneChange");
     145              : const std::string MSNet::STAGE_INSERTIONS("insertion");
     146              : const std::string MSNet::STAGE_REMOTECONTROL("remoteControl");
     147              : 
     148              : const NamedObjectCont<MSStoppingPlace*> MSNet::myEmptyStoppingPlaceCont;
     149              : const std::vector<MSStoppingPlace*> MSNet::myEmptyStoppingPlaceVector;
     150              : 
     151              : // ===========================================================================
     152              : // static member method definitions
     153              : // ===========================================================================
     154              : double
     155          257 : MSNet::getEffort(const MSEdge* const e, const SUMOVehicle* const v, double t) {
     156              :     double value;
     157          257 :     const MSVehicle* const veh = dynamic_cast<const MSVehicle* const>(v);
     158          257 :     if (veh != nullptr && veh->getWeightsStorage().retrieveExistingEffort(e, t, value)) {
     159            2 :         return value;
     160              :     }
     161          255 :     if (getInstance()->getWeightsStorage().retrieveExistingEffort(e, t, value)) {
     162            2 :         return value;
     163              :     }
     164              :     return 0;
     165              : }
     166              : 
     167              : 
     168              : double
     169      7002483 : MSNet::getTravelTime(const MSEdge* const e, const SUMOVehicle* const v, double t) {
     170              :     double value;
     171      7002483 :     const MSVehicle* const veh = dynamic_cast<const MSVehicle* const>(v);
     172      7001550 :     if (veh != nullptr && veh->getWeightsStorage().retrieveExistingTravelTime(e, t, value)) {
     173          418 :         return value;
     174              :     }
     175      7002065 :     if (getInstance()->getWeightsStorage().retrieveExistingTravelTime(e, t, value)) {
     176          168 :         return value;
     177              :     }
     178      7001897 :     if (veh != nullptr) {
     179      6798000 :         if ((veh->getRoutingMode() & libsumo::ROUTING_MODE_AGGREGATED_CUSTOM) != 0) {
     180         2849 :             return MSRoutingEngine::getEffortExtra(e, v, t);
     181      6795151 :         } else if ((veh->getRoutingMode() & libsumo::ROUTING_MODE_AGGREGATED) != 0) {
     182          534 :             if (MSRoutingEngine::hasBikeSpeeds() && v->getVClass() == SVC_BICYCLE) {
     183            0 :                 return MSRoutingEngine::getEffortBike(e, v, t);
     184              :             } else {
     185          534 :                 return MSRoutingEngine::getEffort(e, v, t);
     186              :             }
     187      6794617 :         } else if (MSRoutingEngine::haveExtras()) {
     188       132963 :             double tt = e->getMinimumTravelTime(v);
     189       132963 :             MSRoutingEngine::applyExtras(e, v, SIMSTEP, tt);
     190       132963 :             return tt;
     191              :         }
     192              :     }
     193      6865551 :     return e->getMinimumTravelTime(v);
     194              : }
     195              : 
     196              : 
     197              : // ---------------------------------------------------------------------------
     198              : // MSNet - methods
     199              : // ---------------------------------------------------------------------------
     200              : MSNet*
     201   6065816904 : MSNet::getInstance(void) {
     202   6065816904 :     if (myInstance != nullptr) {
     203   6065816859 :         return myInstance;
     204              :     }
     205           90 :     throw ProcessError(TL("A network was not yet constructed."));
     206              : }
     207              : 
     208              : void
     209        43536 : MSNet::initStatic() {
     210        43536 :     gRoutingPreferences = false;
     211        43536 :     MSDriveWay::init();
     212        43536 : }
     213              : 
     214              : void
     215        42913 : MSNet::cleanupStatic() {
     216        42913 :     if (!MSGlobals::gUseMesoSim) {
     217        35955 :         MSVehicle::Influencer::cleanup();
     218              :     }
     219        42913 : }
     220              : 
     221              : 
     222        43536 : MSNet::MSNet(MSVehicleControl* vc, MSEventControl* beginOfTimestepEvents,
     223              :              MSEventControl* endOfTimestepEvents,
     224              :              MSEventControl* insertionEvents,
     225        43536 :              ShapeContainer* shapeCont):
     226        43536 :     myAmInterrupted(false),
     227        43536 :     myVehiclesMoved(0),
     228        43536 :     myPersonsMoved(0),
     229        43536 :     myHavePermissions(false),
     230        43536 :     myHasInternalLinks(false),
     231        43536 :     myJunctionHigherSpeeds(false),
     232        43536 :     myHasElevation(false),
     233        43536 :     myHasPedestrianNetwork(false),
     234        43536 :     myHasBidiEdges(false),
     235        43536 :     myEdgeDataEndTime(-1),
     236        43536 :     myDynamicShapeUpdater(nullptr) {
     237        43536 :     if (myInstance != nullptr) {
     238            0 :         throw ProcessError(TL("A network was already constructed."));
     239              :     }
     240        43536 :     OptionsCont& oc = OptionsCont::getOptions();
     241        43536 :     myStep = string2time(oc.getString("begin"));
     242        43536 :     myStateLoaderTime = myStep - 1,
     243        43536 :     myMaxTeleports = oc.getInt("max-num-teleports");
     244        43536 :     myLogExecutionTime = !oc.getBool("no-duration-log");
     245        43536 :     myLogStepNumber = !oc.getBool("no-step-log");
     246        43536 :     myLogStepPeriod = oc.getInt("step-log.period");
     247       174144 :     myInserter = new MSInsertionControl(*vc, string2time(oc.getString("max-depart-delay")), oc.getBool("eager-insert"), oc.getInt("max-num-vehicles"),
     248       174144 :                                         string2time(oc.getString("random-depart-offset")));
     249        43536 :     myVehicleControl = vc;
     250        43536 :     myDetectorControl = new MSDetectorControl();
     251        43536 :     myEdges = nullptr;
     252        43536 :     myJunctions = nullptr;
     253        43536 :     myRouteLoaders = nullptr;
     254        43536 :     myLogics = nullptr;
     255        43536 :     myPersonControl = nullptr;
     256        43536 :     myContainerControl = nullptr;
     257        43536 :     myEdgeWeights = nullptr;
     258        43536 :     myShapeContainer = shapeCont == nullptr ? new ShapeContainer() : shapeCont;
     259              : 
     260        43536 :     myBeginOfTimestepEvents = beginOfTimestepEvents;
     261        43536 :     myEndOfTimestepEvents = endOfTimestepEvents;
     262        43536 :     myInsertionEvents = insertionEvents;
     263        43536 :     myLanesRTree.first = false;
     264              : 
     265        43536 :     if (MSGlobals::gUseMesoSim) {
     266        14116 :         MSGlobals::gMesoNet = new MELoop(string2time(oc.getString("meso-recheck")));
     267              :     }
     268        43536 :     myInstance = this;
     269        43536 :     initStatic();
     270        43536 : }
     271              : 
     272              : 
     273              : void
     274        43053 : MSNet::closeBuilding(const OptionsCont& oc, MSEdgeControl* edges, MSJunctionControl* junctions,
     275              :                      SUMORouteLoaderControl* routeLoaders,
     276              :                      MSTLLogicControl* tlc,
     277              :                      std::vector<SUMOTime> stateDumpTimes,
     278              :                      std::vector<std::string> stateDumpFiles,
     279              :                      bool hasInternalLinks,
     280              :                      bool junctionHigherSpeeds,
     281              :                      const MMVersion& version) {
     282        43053 :     myEdges = edges;
     283        43053 :     myJunctions = junctions;
     284        43053 :     myRouteLoaders = routeLoaders;
     285        43053 :     myLogics = tlc;
     286              :     // save the time the network state shall be saved at
     287        43053 :     myStateDumpTimes = stateDumpTimes;
     288        43053 :     myStateDumpFiles = stateDumpFiles;
     289        43053 :     myStateDumpPeriod = string2time(oc.getString("save-state.period"));
     290        43053 :     myStateDumpPrefix = oc.getString("save-state.prefix");
     291        43053 :     myStateDumpSuffix = oc.getString("save-state.suffix");
     292              : 
     293              :     // initialise performance computation
     294        43053 :     mySimBeginMillis = SysUtils::getCurrentMillis();
     295        43053 :     myTraCIMillis = 0;
     296        43053 :     myHasInternalLinks = hasInternalLinks;
     297        43053 :     myJunctionHigherSpeeds = junctionHigherSpeeds;
     298        43053 :     myHasElevation = checkElevation();
     299        43053 :     myHasPedestrianNetwork = checkWalkingarea();
     300        43053 :     myHasBidiEdges = checkBidiEdges();
     301              :     myVersion = version;
     302        43053 :     if ((!MSGlobals::gUsingInternalLanes || !myHasInternalLinks)
     303        15450 :             && MSGlobals::gWeightsSeparateTurns > 0) {
     304            0 :         throw ProcessError(TL("Option weights.separate-turns is only supported when simulating with internal lanes"));
     305              :     }
     306        43053 : }
     307              : 
     308              : 
     309        76859 : MSNet::~MSNet() {
     310        42913 :     cleanupStatic();
     311              :     // delete controls
     312        42913 :     delete myJunctions;
     313        42913 :     delete myDetectorControl;
     314              :     // delete mean data
     315        42913 :     delete myEdges;
     316        42913 :     delete myInserter;
     317        42913 :     myInserter = nullptr;
     318        42913 :     delete myLogics;
     319        42913 :     delete myRouteLoaders;
     320        42913 :     if (myPersonControl != nullptr) {
     321         8377 :         delete myPersonControl;
     322         8377 :         myPersonControl = nullptr; // just to have that clear for later cleanups
     323              :     }
     324        42913 :     if (myContainerControl != nullptr) {
     325         1949 :         delete myContainerControl;
     326         1949 :         myContainerControl = nullptr; // just to have that clear for later cleanups
     327              :     }
     328              :     // the CCH metric families (myCCHLive/myCCHFreeflow) own ref vehicles
     329              :     // that hold a raw MSVehicleType*; tear them down before the vehicle
     330              :     // types go away below (MSDevice::cleanupAll() -> MSRoutingEngine::
     331              :     // cleanup() runs this again later via clearAll(), harmlessly, since
     332              :     // cleanupCCH() nulls out what it deletes)
     333        42913 :     MSRoutingEngine::cleanupCCH();
     334        42913 :     delete myVehicleControl; // must happen after deleting transportables
     335              :     // ShapeContainer registers polygon-update commands with the event controls.
     336              :     // It must be torn down before the event controls so that ~ShapeContainer
     337              :     // can still deschedule() its (live) commands; the event controls then
     338              :     // delete the commands themselves.
     339        42913 :     delete myShapeContainer;
     340        42913 :     myShapeContainer = nullptr;
     341              :     // delete events late so that vehicles can get rid of references first
     342        42913 :     delete myBeginOfTimestepEvents;
     343        42913 :     myBeginOfTimestepEvents = nullptr;
     344        42913 :     delete myEndOfTimestepEvents;
     345        42913 :     myEndOfTimestepEvents = nullptr;
     346        42913 :     delete myInsertionEvents;
     347        42913 :     myInsertionEvents = nullptr;
     348        42913 :     delete myEdgeWeights;
     349        44553 :     for (auto& router : myRouterTT) {
     350         1640 :         delete router.second;
     351              :     }
     352              :     myRouterTT.clear();
     353        42924 :     for (auto& router : myRouterEffort) {
     354           11 :         delete router.second;
     355              :     }
     356              :     myRouterEffort.clear();
     357        45761 :     for (auto& router : myPedestrianRouter) {
     358         2848 :         delete router.second;
     359              :     }
     360              :     myPedestrianRouter.clear();
     361        42913 :     resetIntermodalRouter();
     362              :     myLanesRTree.second.RemoveAll();
     363        42930 :     for (MSTractionSubstation* sub : myTractionSubstations) {
     364           17 :         delete sub;
     365              :     }
     366              :     myTractionSubstations.clear();
     367        42913 :     clearAll();
     368        42913 :     if (MSGlobals::gUseMesoSim) {
     369         6958 :         delete MSGlobals::gMesoNet;
     370              :     }
     371        42913 :     myInstance = nullptr;
     372       162685 : }
     373              : 
     374              : 
     375              : void
     376          221 : MSNet::addRestriction(const std::string& id, const SUMOVehicleClass svc, const double speed) {
     377          221 :     myRestrictions[id][svc] = speed;
     378          221 : }
     379              : 
     380              : 
     381              : const std::map<SUMOVehicleClass, double>*
     382      2199782 : MSNet::getRestrictions(const std::string& id) const {
     383              :     std::map<std::string, std::map<SUMOVehicleClass, double> >::const_iterator i = myRestrictions.find(id);
     384      2199782 :     if (i == myRestrictions.end()) {
     385              :         return nullptr;
     386              :     }
     387         1130 :     return &i->second;
     388              : }
     389              : 
     390              : 
     391              : double
     392        13539 : MSNet::getPreference(const std::string& routingType, const SUMOVTypeParameter& pars) const {
     393        13539 :     if (gRoutingPreferences) {
     394        13539 :         auto it = myVTypePreferences.find(pars.id);
     395        13539 :         if (it != myVTypePreferences.end()) {
     396              :             auto it2 = it->second.find(routingType);
     397          393 :             if (it2 != it->second.end()) {
     398           81 :                 return it2->second;
     399              :             }
     400              :         }
     401              :         auto it3 = myVClassPreferences.find(pars.vehicleClass);
     402        13458 :         if (it3 != myVClassPreferences.end()) {
     403              :             auto it4 = it3->second.find(routingType);
     404          876 :             if (it4 != it3->second.end()) {
     405          378 :                 return it4->second;
     406              :             }
     407              :         }
     408              :         // fallback to generel preferences
     409        13080 :         it = myVTypePreferences.find("");
     410        13080 :         if (it != myVTypePreferences.end()) {
     411              :             auto it2 = it->second.find(routingType);
     412         9690 :             if (it2 != it->second.end()) {
     413         4554 :                 return it2->second;
     414              :             }
     415              :         }
     416              :     }
     417              :     return 1;
     418              : }
     419              : 
     420              : 
     421              : void
     422           32 : MSNet::addPreference(const std::string& routingType, SUMOVehicleClass svc, double prio) {
     423           32 :     myVClassPreferences[svc][routingType] = prio;
     424           32 :     gRoutingPreferences = true;
     425           32 : }
     426              : 
     427              : 
     428              : void
     429          102 : MSNet::addPreference(const std::string& routingType, std::string vType, double prio) {
     430          102 :     myVTypePreferences[vType][routingType] = prio;
     431          102 :     gRoutingPreferences = true;
     432          102 : }
     433              : 
     434              : void
     435           24 : MSNet::addMesoType(const std::string& typeID, const MESegment::MesoEdgeType& edgeType) {
     436           24 :     myMesoEdgeTypes[typeID] = edgeType;
     437           24 : }
     438              : 
     439              : const MESegment::MesoEdgeType&
     440       924328 : MSNet::getMesoType(const std::string& typeID) {
     441              :     if (myMesoEdgeTypes.count(typeID) == 0) {
     442              :         // init defaults
     443         7570 :         const OptionsCont& oc = OptionsCont::getOptions();
     444              :         MESegment::MesoEdgeType edgeType;
     445         7570 :         edgeType.tauff = string2time(oc.getString("meso-tauff"));
     446         7570 :         edgeType.taufj = string2time(oc.getString("meso-taufj"));
     447         7570 :         edgeType.taujf = string2time(oc.getString("meso-taujf"));
     448         7570 :         edgeType.taujj = string2time(oc.getString("meso-taujj"));
     449         7570 :         edgeType.jamThreshold = oc.getFloat("meso-jam-threshold");
     450         7570 :         edgeType.junctionControl = oc.getBool("meso-junction-control");
     451         7570 :         edgeType.tlsPenalty = oc.getFloat("meso-tls-penalty");
     452         7570 :         edgeType.tlsFlowPenalty = oc.getFloat("meso-tls-flow-penalty");
     453         7570 :         edgeType.minorPenalty = string2time(oc.getString("meso-minor-penalty"));
     454         7570 :         edgeType.overtaking = oc.getBool("meso-overtaking");
     455         7570 :         edgeType.edgeLength = oc.getFloat("meso-edgelength");
     456         7570 :         myMesoEdgeTypes[typeID] = edgeType;
     457              :     }
     458       924328 :     return myMesoEdgeTypes[typeID];
     459              : }
     460              : 
     461              : 
     462              : bool
     463      7381692 : MSNet::hasFlow(const std::string& id) const {
     464              :     // inserter is deleted at the end of the simulation
     465      7381692 :     return myInserter != nullptr && myInserter->hasFlow(id);
     466              : }
     467              : 
     468              : 
     469              : MSNet::SimulationState
     470        32508 : MSNet::simulate(SUMOTime start, SUMOTime stop) {
     471              :     // report the begin when wished
     472        65016 :     WRITE_MESSAGEF(TL("Simulation version % started with time: %."), VERSION_STRING, time2string(start));
     473              :     // the simulation loop
     474              :     SimulationState state = SIMSTATE_RUNNING;
     475              :     // state loading may have changed the start time so we need to reinit it
     476        32508 :     myStep = start;
     477              :     int numSteps = 0;
     478              :     bool doStepLog = false;
     479    114349987 :     while (state == SIMSTATE_RUNNING) {
     480    114317910 :         doStepLog = myLogStepNumber && (numSteps % myLogStepPeriod == 0);
     481              :         if (doStepLog) {
     482          110 :             preSimStepOutput();
     483              :         }
     484    114317910 :         simulationStep();
     485    114317479 :         if (doStepLog) {
     486          110 :             postSimStepOutput();
     487              :         }
     488    114317479 :         state = adaptToState(simulationState(stop));
     489              : #ifdef DEBUG_SIMSTEP
     490              :         std::cout << SIMTIME << " MSNet::simulate(" << start << ", " << stop << ")"
     491              :                   << "\n simulation state: " << getStateMessage(state)
     492              :                   << std::endl;
     493              : #endif
     494    114317479 :         numSteps++;
     495              :     }
     496        32077 :     if (myLogStepNumber && !doStepLog) {
     497              :         // ensure some output on the last step
     498           17 :         preSimStepOutput();
     499           17 :         postSimStepOutput();
     500              :     }
     501              :     // exit simulation loop
     502        32077 :     if (myLogStepNumber) {
     503              :         // start new line for final verbose output
     504           20 :         std::cout << "\n";
     505              :     }
     506        32077 :     closeSimulation(start, getStateMessage(state));
     507        32077 :     return state;
     508              : }
     509              : 
     510              : 
     511              : void
     512    127641200 : MSNet::loadRoutes() {
     513    127641200 :     myRouteLoaders->loadNext(myStep);
     514    127640609 : }
     515              : 
     516              : 
     517              : const std::string
     518        13590 : MSNet::generateStatistics(const SUMOTime start, const long now) {
     519        13590 :     std::ostringstream msg;
     520        13590 :     if (myLogExecutionTime) {
     521        13175 :         const long duration = now - mySimBeginMillis;
     522              :         // print performance notice
     523        26350 :         msg << "Performance:\n" << " Duration: " << elapsedMs2string(duration) << "\n";
     524        13175 :         if (duration != 0) {
     525        13082 :             if (TraCIServer::getInstance() != nullptr) {
     526         4341 :                 msg << " TraCI-Duration: " << elapsedMs2string(myTraCIMillis) << "\n";
     527              :             }
     528        13082 :             msg << " Real time factor: " << (STEPS2TIME(myStep - start) * 1000. / (double)duration) << "\n";
     529              :             msg.setf(std::ios::fixed, std::ios::floatfield);     // use decimal format
     530              :             msg.setf(std::ios::showpoint);    // print decimal point
     531        13082 :             msg << " UPS: " << ((double)myVehiclesMoved / ((double)duration / 1000)) << "\n";
     532        13082 :             if (myPersonsMoved > 0) {
     533         2486 :                 msg << " UPS-Persons: " << ((double)myPersonsMoved / ((double)duration / 1000)) << "\n";
     534              :             }
     535              :         }
     536              :         // print vehicle statistics
     537        13175 :         const std::string vehDiscardNotice = ((myVehicleControl->getLoadedVehicleNo() != myVehicleControl->getDepartedVehicleNo()) ?
     538        17450 :                                               " (Loaded: " + toString(myVehicleControl->getLoadedVehicleNo()) + ")" : "");
     539              :         msg << "Vehicles:\n"
     540        13175 :             << " Inserted: " << myVehicleControl->getDepartedVehicleNo() << vehDiscardNotice << "\n"
     541        26350 :             << " Running: " << myVehicleControl->getRunningVehicleNo() << "\n"
     542        26350 :             << " Waiting: " << myInserter->getWaitingVehicleNo() << "\n";
     543              : 
     544        13175 :         if (myVehicleControl->getTeleportCount() > 0 || myVehicleControl->getCollisionCount() > 0) {
     545              :             // print optional teleport statistics
     546              :             std::vector<std::string> reasons;
     547          705 :             if (myVehicleControl->getCollisionCount() > 0) {
     548          654 :                 reasons.push_back("Collisions: " + toString(myVehicleControl->getCollisionCount()));
     549              :             }
     550          705 :             if (myVehicleControl->getTeleportsJam() > 0) {
     551          486 :                 reasons.push_back("Jam: " + toString(myVehicleControl->getTeleportsJam()));
     552              :             }
     553          705 :             if (myVehicleControl->getTeleportsYield() > 0) {
     554          242 :                 reasons.push_back("Yield: " + toString(myVehicleControl->getTeleportsYield()));
     555              :             }
     556          705 :             if (myVehicleControl->getTeleportsWrongLane() > 0) {
     557          272 :                 reasons.push_back("Wrong Lane: " + toString(myVehicleControl->getTeleportsWrongLane()));
     558              :             }
     559         2115 :             msg << " Teleports: " << myVehicleControl->getTeleportCount() << " (" << joinToString(reasons, ", ") << ")\n";
     560          705 :         }
     561        13175 :         if (myVehicleControl->getEmergencyStops() > 0) {
     562           66 :             msg << " Emergency Stops: " << myVehicleControl->getEmergencyStops() << "\n";
     563              :         }
     564        13175 :         if (myVehicleControl->getEmergencyBrakingCount() > 0) {
     565          301 :             msg << " Emergency Braking: " << myVehicleControl->getEmergencyBrakingCount() << "\n";
     566              :         }
     567        13175 :         if (myPersonControl != nullptr && myPersonControl->getLoadedNumber() > 0) {
     568         2519 :             const std::string discardNotice = ((myPersonControl->getLoadedNumber() != myPersonControl->getDepartedNumber()) ?
     569         2906 :                                                " (Loaded: " + toString(myPersonControl->getLoadedNumber()) + ")" : "");
     570              :             msg << "Persons:\n"
     571         2519 :                 << " Inserted: " << myPersonControl->getDepartedNumber() << discardNotice << "\n"
     572         5038 :                 << " Running: " << myPersonControl->getRunningNumber() << "\n";
     573         2519 :             if (myPersonControl->getJammedNumber() > 0) {
     574           56 :                 msg << " Jammed: " << myPersonControl->getJammedNumber() << "\n";
     575              :             }
     576         2519 :             if (myPersonControl->getTeleportCount() > 0) {
     577              :                 std::vector<std::string> reasons;
     578            8 :                 if (myPersonControl->getTeleportsAbortWait() > 0) {
     579            0 :                     reasons.push_back("Abort Wait: " + toString(myPersonControl->getTeleportsAbortWait()));
     580              :                 }
     581            8 :                 if (myPersonControl->getTeleportsWrongDest() > 0) {
     582           16 :                     reasons.push_back("Wrong Dest: " + toString(myPersonControl->getTeleportsWrongDest()));
     583              :                 }
     584           24 :                 msg << " Teleports: " << myPersonControl->getTeleportCount() << " (" << joinToString(reasons, ", ") << ")\n";
     585            8 :             }
     586              :         }
     587        13175 :         if (myContainerControl != nullptr && myContainerControl->getLoadedNumber() > 0) {
     588           75 :             const std::string discardNotice = ((myContainerControl->getLoadedNumber() != myContainerControl->getDepartedNumber()) ?
     589           75 :                                                " (Loaded: " + toString(myContainerControl->getLoadedNumber()) + ")" : "");
     590              :             msg << "Containers:\n"
     591           75 :                 << " Inserted: " << myContainerControl->getDepartedNumber() << "\n"
     592          150 :                 << " Running: " << myContainerControl->getRunningNumber() << "\n";
     593           75 :             if (myContainerControl->getJammedNumber() > 0) {
     594            0 :                 msg << " Jammed: " << myContainerControl->getJammedNumber() << "\n";
     595              :             }
     596           75 :             if (myContainerControl->getTeleportCount() > 0) {
     597              :                 std::vector<std::string> reasons;
     598            0 :                 if (myContainerControl->getTeleportsAbortWait() > 0) {
     599            0 :                     reasons.push_back("Abort Wait: " + toString(myContainerControl->getTeleportsAbortWait()));
     600              :                 }
     601            0 :                 if (myContainerControl->getTeleportsWrongDest() > 0) {
     602            0 :                     reasons.push_back("Wrong Dest: " + toString(myContainerControl->getTeleportsWrongDest()));
     603              :                 }
     604            0 :                 msg << " Teleports: " << myContainerControl->getTeleportCount() << " (" << joinToString(reasons, ", ") << ")\n";
     605            0 :             }
     606              :         }
     607              :     }
     608        27180 :     if (OptionsCont::getOptions().getBool("duration-log.statistics")) {
     609         7054 :         msg << MSDevice_Tripinfo::printStatistics();
     610              :     }
     611              :     std::string result = msg.str();
     612              :     result.erase(result.end() - 1);
     613        13590 :     return result;
     614        13590 : }
     615              : 
     616              : 
     617              : void
     618        10390 : MSNet::writeCollisions() const {
     619        20780 :     OutputDevice& od = OutputDevice::getDeviceByOption("collision-output");
     620        10543 :     for (const auto& item : myCollisions) {
     621          306 :         for (const auto& c : item.second) {
     622          153 :             if (c.time != SIMSTEP) {
     623           13 :                 continue;
     624              :             }
     625          280 :             od.openTag("collision");
     626          140 :             od.writeAttr("time", time2string(getCurrentTimeStep()));
     627          140 :             od.writeAttr("type", c.type);
     628          140 :             od.writeAttr("lane", c.lane->getID());
     629          140 :             od.writeAttr("pos", c.pos);
     630          140 :             od.writeAttr("collider", item.first);
     631          140 :             od.writeAttr("victim", c.victim);
     632          140 :             od.writeAttr("colliderType", c.colliderType);
     633          140 :             od.writeAttr("victimType", c.victimType);
     634          140 :             od.writeAttr("colliderSpeed", c.colliderSpeed);
     635          140 :             od.writeAttr("victimSpeed", c.victimSpeed);
     636          140 :             od.writeAttr("colliderFront", c.colliderFront);
     637          140 :             od.writeAttr("colliderBack", c.colliderBack);
     638          140 :             od.writeAttr("victimFront", c.victimFront);
     639          140 :             od.writeAttr("victimBack", c.victimBack);
     640          280 :             od.closeTag();
     641              :         }
     642              :     }
     643        10390 : }
     644              : 
     645              : 
     646              : void
     647          379 : MSNet::writeStatistics(const SUMOTime start, const long now) const {
     648          379 :     const long duration = now - mySimBeginMillis;
     649          379 :     OutputDevice& od = OutputDevice::getDeviceByOption("statistic-output");
     650          379 :     od.openTag("performance");
     651          379 :     od.writeAttr("clockBegin", time2string(mySimBeginMillis));
     652          379 :     od.writeAttr("clockEnd", time2string(now));
     653          379 :     od.writeAttr("clockDuration", time2string(duration));
     654          379 :     od.writeAttr("traciDuration", time2string(myTraCIMillis));
     655          379 :     od.writeAttr("realTimeFactor", duration != 0 ? (double)(myStep - start) / (double)duration : -1);
     656          379 :     od.writeAttr("vehicleUpdatesPerSecond", duration != 0 ? (double)myVehiclesMoved / ((double)duration / 1000) : -1);
     657          379 :     od.writeAttr("personUpdatesPerSecond", duration != 0 ? (double)myPersonsMoved / ((double)duration / 1000) : -1);
     658          379 :     od.writeAttr("begin", time2string(start));
     659          379 :     od.writeAttr("end", time2string(myStep));
     660          379 :     od.writeAttr("duration", time2string(myStep - start));
     661          379 :     od.closeTag();
     662          379 :     od.openTag("vehicles");
     663          379 :     od.writeAttr("loaded", myVehicleControl->getLoadedVehicleNo());
     664          379 :     od.writeAttr("inserted", myVehicleControl->getDepartedVehicleNo());
     665          379 :     od.writeAttr("running", myVehicleControl->getRunningVehicleNo());
     666          379 :     od.writeAttr("waiting", myInserter->getWaitingVehicleNo());
     667          379 :     od.closeTag();
     668          379 :     od.openTag("teleports");
     669          379 :     od.writeAttr("total", myVehicleControl->getTeleportCount());
     670          379 :     od.writeAttr("jam", myVehicleControl->getTeleportsJam());
     671          379 :     od.writeAttr("yield", myVehicleControl->getTeleportsYield());
     672          379 :     od.writeAttr("wrongLane", myVehicleControl->getTeleportsWrongLane());
     673          379 :     od.closeTag();
     674          379 :     od.openTag("safety");
     675          379 :     od.writeAttr("collisions", myVehicleControl->getCollisionCount());
     676          379 :     od.writeAttr("emergencyStops", myVehicleControl->getEmergencyStops());
     677          379 :     od.writeAttr("emergencyBraking", myVehicleControl->getEmergencyBrakingCount());
     678          379 :     od.closeTag();
     679          379 :     od.openTag("persons");
     680          385 :     od.writeAttr("loaded", myPersonControl != nullptr ? myPersonControl->getLoadedNumber() : 0);
     681          385 :     od.writeAttr("running", myPersonControl != nullptr ? myPersonControl->getRunningNumber() : 0);
     682          385 :     od.writeAttr("jammed", myPersonControl != nullptr ? myPersonControl->getJammedNumber() : 0);
     683          379 :     od.closeTag();
     684          379 :     od.openTag("personTeleports");
     685          385 :     od.writeAttr("total", myPersonControl != nullptr ? myPersonControl->getTeleportCount() : 0);
     686          385 :     od.writeAttr("abortWait", myPersonControl != nullptr ? myPersonControl->getTeleportsAbortWait() : 0);
     687          385 :     od.writeAttr("wrongDest", myPersonControl != nullptr ? myPersonControl->getTeleportsWrongDest() : 0);
     688          379 :     od.closeTag();
     689          603 :     if (OptionsCont::getOptions().isSet("tripinfo-output") || OptionsCont::getOptions().getBool("duration-log.statistics")) {
     690          264 :         MSDevice_Tripinfo::writeStatistics(od);
     691              :     }
     692          379 : }
     693              : 
     694              : 
     695              : void
     696    127639898 : MSNet::writeSummaryOutput(bool finalStep) {
     697              :     // summary output
     698    127639898 :     const OptionsCont& oc = OptionsCont::getOptions();
     699    127639898 :     const bool hasOutput = oc.isSet("summary-output");
     700    127639898 :     const bool hasPersonOutput = oc.isSet("person-summary-output");
     701    127639898 :     if (hasOutput || hasPersonOutput) {
     702       531916 :         const SUMOTime period = string2time(oc.getString("summary-output.period"));
     703       531916 :         const SUMOTime begin = string2time(oc.getString("begin"));
     704       531916 :         if ((period > 0 && (myStep - begin) % period != 0 && !finalStep)
     705              :                 // it's the final step but we already wrote output
     706       530996 :                 || (finalStep && (period <= 0 || (myStep - begin) % period == 0))) {
     707              :             return;
     708              :         }
     709              :     }
     710       530473 :     if (hasOutput) {
     711       522721 :         OutputDevice& od = OutputDevice::getDeviceByOption("summary-output");
     712       522721 :         int departedVehiclesNumber = myVehicleControl->getDepartedVehicleNo();
     713       522721 :         const double meanWaitingTime = departedVehiclesNumber != 0 ? myVehicleControl->getTotalDepartureDelay() / (double) departedVehiclesNumber : -1.;
     714              :         int endedVehicleNumber = myVehicleControl->getEndedVehicleNo();
     715       522721 :         const double meanTravelTime = endedVehicleNumber != 0 ? myVehicleControl->getTotalTravelTime() / (double) endedVehicleNumber : -1.;
     716       522721 :         od.openTag("step");
     717       522721 :         od.writeAttr("time", time2string(myStep));
     718       522721 :         od.writeAttr("loaded", myVehicleControl->getLoadedVehicleNo());
     719       522721 :         od.writeAttr("inserted", myVehicleControl->getDepartedVehicleNo());
     720       522721 :         od.writeAttr("running", myVehicleControl->getRunningVehicleNo());
     721       522721 :         od.writeAttr("waiting", myInserter->getWaitingVehicleNo());
     722       522721 :         od.writeAttr("ended", myVehicleControl->getEndedVehicleNo());
     723       522721 :         od.writeAttr("arrived", myVehicleControl->getArrivedVehicleNo());
     724       522721 :         od.writeAttr("collisions", myVehicleControl->getCollisionCount());
     725       522721 :         od.writeAttr("teleports", myVehicleControl->getTeleportCount());
     726       522721 :         od.writeAttr("halting", myVehicleControl->getHaltingVehicleNo());
     727       522721 :         od.writeAttr("stopped", myVehicleControl->getStoppedVehiclesCount());
     728       522721 :         od.writeAttr("meanWaitingTime", meanWaitingTime);
     729       522721 :         od.writeAttr("meanTravelTime", meanTravelTime);
     730       522721 :         std::pair<double, double> meanSpeed = myVehicleControl->getVehicleMeanSpeeds();
     731       522721 :         od.writeAttr("meanSpeed", meanSpeed.first);
     732       522721 :         od.writeAttr("meanSpeedRelative", meanSpeed.second);
     733       522721 :         od.writeAttr("discarded", myVehicleControl->getDiscardedVehicleNo());
     734       522721 :         if (myLogExecutionTime) {
     735       235433 :             od.writeAttr("duration", mySimStepDuration);
     736              :         }
     737      1045442 :         od.closeTag();
     738              :     }
     739    127638455 :     if (hasPersonOutput) {
     740         7752 :         OutputDevice& od = OutputDevice::getDeviceByOption("person-summary-output");
     741         7752 :         MSTransportableControl& pc = getPersonControl();
     742         7752 :         od.openTag("step");
     743        15504 :         od.writeAttr("time", time2string(myStep));
     744         7752 :         od.writeAttr("loaded", pc.getLoadedNumber());
     745         7752 :         od.writeAttr("inserted", pc.getDepartedNumber());
     746         7752 :         od.writeAttr("walking", pc.getMovingNumber());
     747         7752 :         od.writeAttr("waitingForRide", pc.getWaitingForVehicleNumber());
     748         7752 :         od.writeAttr("riding", pc.getRidingNumber());
     749         7752 :         od.writeAttr("stopping", pc.getWaitingUntilNumber());
     750         7752 :         od.writeAttr("jammed", pc.getJammedNumber());
     751         7752 :         od.writeAttr("ended", pc.getEndedNumber());
     752         7752 :         od.writeAttr("arrived", pc.getArrivedNumber());
     753         7752 :         od.writeAttr("teleports", pc.getTeleportCount());
     754         7752 :         od.writeAttr("discarded", pc.getDiscardedNumber());
     755         7752 :         if (myLogExecutionTime) {
     756            0 :             od.writeAttr("duration", mySimStepDuration);
     757              :         }
     758        15504 :         od.closeTag();
     759              :     }
     760              : }
     761              : 
     762              : 
     763              : void
     764        41363 : MSNet::closeSimulation(SUMOTime start, const std::string& reason) {
     765              :     // report the end when wished
     766        82726 :     WRITE_MESSAGE(TLF("Simulation ended at time: %.", time2string(getCurrentTimeStep())));
     767        41363 :     if (reason != "") {
     768        81838 :         WRITE_MESSAGE(TL("Reason: ") + reason);
     769              :     }
     770        41363 :     myDetectorControl->close(myStep);
     771        82726 :     if (OptionsCont::getOptions().isSet("queue-output")) {
     772          358 :         MSQueueExport::finish(OutputDevice::getDeviceByOption("queue-output"), myStep);
     773              :     }
     774        42856 :     if (MSStopOut::active() && OptionsCont::getOptions().getBool("stop-output.write-unfinished")) {
     775          141 :         MSStopOut::getInstance()->generateOutputForUnfinished();
     776              :     }
     777        41363 :     MSDevice_Vehroutes::writePendingOutput(OptionsCont::getOptions().getBool("vehroute-output.write-unfinished"));
     778        82726 :     if (OptionsCont::getOptions().getBool("tripinfo-output.write-unfinished")) {
     779         1114 :         MSDevice_Tripinfo::generateOutputForUnfinished();
     780              :     }
     781        82726 :     if (OptionsCont::getOptions().isSet("chargingstations-output")) {
     782          252 :         if (!OptionsCont::getOptions().getBool("chargingstations-output.aggregated")) {
     783          106 :             writeChargingStationOutput();
     784           40 :         } else if (OptionsCont::getOptions().getBool("chargingstations-output.aggregated.write-unfinished")) {
     785           12 :             MSChargingStationExport::write(OutputDevice::getDeviceByOption("chargingstations-output"), true);
     786              :         }
     787              :     }
     788        82726 :     if (OptionsCont::getOptions().isSet("overheadwiresegments-output")) {
     789            5 :         writeOverheadWireSegmentOutput();
     790              :     }
     791        82726 :     if (OptionsCont::getOptions().isSet("substations-output")) {
     792            5 :         writeSubstationOutput();
     793              :     }
     794        41363 :     writeRailSignalBlocks();
     795        41363 :     const long now = SysUtils::getCurrentMillis();
     796        69551 :     if (myLogExecutionTime || OptionsCont::getOptions().getBool("duration-log.statistics")) {
     797        27180 :         WRITE_MESSAGE(generateStatistics(start, now));
     798              :     }
     799        82726 :     if (OptionsCont::getOptions().isSet("statistic-output")) {
     800          379 :         writeStatistics(start, now);
     801              :     }
     802              :     // maybe write a final line of output if reporting is periodic
     803        41363 :     writeSummaryOutput(true);
     804        41363 : }
     805              : 
     806              : 
     807              : void
     808    127601759 : MSNet::simulationStep(const bool onlyMove) {
     809    127601759 :     if (myStepCompletionMissing) {
     810            4 :         postMoveStep();
     811            4 :         myStepCompletionMissing = false;
     812         2672 :         return;
     813              :     }
     814              : #ifdef DEBUG_SIMSTEP
     815              :     std::cout << SIMTIME << ": MSNet::simulationStep() called"
     816              :               << ", myStep = " << myStep
     817              :               << std::endl;
     818              : #endif
     819              :     TraCIServer* t = TraCIServer::getInstance();
     820              :     int lastTraCICmd = 0;
     821    127601755 :     if (t != nullptr) {
     822      1700923 :         if (myLogExecutionTime) {
     823      1496756 :             myTraCIStepDuration = SysUtils::getCurrentMillis();
     824              :         }
     825      1700923 :         lastTraCICmd = t->processCommands(myStep);
     826              : #ifdef DEBUG_SIMSTEP
     827              :         bool loadRequested = !TraCI::getLoadArgs().empty();
     828              :         assert(t->getTargetTime() >= myStep || loadRequested || TraCIServer::wasClosed());
     829              : #endif
     830      1700818 :         if (myLogExecutionTime) {
     831      1496681 :             myTraCIStepDuration = SysUtils::getCurrentMillis() - myTraCIStepDuration;
     832              :         }
     833      1700818 :         if (TraCIServer::wasClosed() || !t->getLoadArgs().empty()) {
     834              :             return;
     835              :         }
     836              :     }
     837              : #ifdef DEBUG_SIMSTEP
     838              :     std::cout << SIMTIME << ": TraCI target time: " << t->getTargetTime() << std::endl;
     839              : #endif
     840              :     // execute beginOfTimestepEvents
     841    127598986 :     if (myLogExecutionTime) {
     842     89086257 :         mySimStepDuration = SysUtils::getCurrentMillis();
     843              :     }
     844              :     // simulation state output
     845    127598986 :     std::vector<SUMOTime>::iterator timeIt = std::find(myStateDumpTimes.begin(), myStateDumpTimes.end(), myStep);
     846    127598986 :     if (timeIt != myStateDumpTimes.end()) {
     847          375 :         const int dist = (int)distance(myStateDumpTimes.begin(), timeIt);
     848          375 :         MSStateHandler::saveState(myStateDumpFiles[dist], myStep);
     849              :     }
     850    127598986 :     if (myStateDumpPeriod > 0 && myStep % myStateDumpPeriod == 0) {
     851           84 :         std::string timeStamp = time2string(myStep);
     852              :         std::replace(timeStamp.begin(), timeStamp.end(), ':', '-');
     853           84 :         const std::string filename = myStateDumpPrefix + "_" + timeStamp + myStateDumpSuffix;
     854           84 :         MSStateHandler::saveState(filename, myStep);
     855           84 :         myPeriodicStateFiles.push_back(filename);
     856           84 :         int keep = OptionsCont::getOptions().getInt("save-state.period.keep");
     857           84 :         if (keep > 0 && (int)myPeriodicStateFiles.size() > keep) {
     858            0 :             std::remove(myPeriodicStateFiles.front().c_str());
     859              :             myPeriodicStateFiles.erase(myPeriodicStateFiles.begin());
     860              :         }
     861              :     }
     862    127598986 :     myBeginOfTimestepEvents->execute(myStep);
     863    127598978 :     if (MSRailSignalControl::hasInstance()) {
     864       506296 :         MSRailSignalControl::getInstance().updateSignals(myStep);
     865              :     }
     866              : #ifdef HAVE_FOX
     867    127598978 :     MSRoutingEngine::waitForAll();
     868              : #endif
     869    127598978 :     if (MSGlobals::gCheck4Accidents && !MSGlobals::gUseMesoSim) {
     870    115012411 :         myEdges->detectCollisions(myStep, STAGE_EVENTS);
     871              :     }
     872              :     // check whether the tls programs need to be switched
     873    127598978 :     myLogics->check2Switch(myStep);
     874              : 
     875    127598978 :     if (MSGlobals::gUseMesoSim) {
     876     12586567 :         MSGlobals::gMesoNet->simulate(myStep);
     877              :     } else {
     878              :         // assure all lanes with vehicles are 'active'
     879    115012411 :         myEdges->patchActiveLanes();
     880              : 
     881              :         // compute safe velocities for all vehicles for the next few lanes
     882              :         // also register ApproachingVehicleInformation for all links
     883    115012411 :         myEdges->planMovements(myStep);
     884              : 
     885              :         // register junction approaches based on planned velocities as basis for right-of-way decision
     886    115012411 :         myEdges->setJunctionApproaches();
     887              : 
     888              :         // decide right-of-way and execute movements
     889    115012411 :         myEdges->executeMovements(myStep);
     890    115012408 :         if (MSGlobals::gCheck4Accidents) {
     891    115012408 :             myEdges->detectCollisions(myStep, STAGE_MOVEMENTS);
     892              :         }
     893              : 
     894              :         // vehicles may change lanes
     895    115012408 :         myEdges->changeLanes(myStep);
     896              : 
     897    115012408 :         if (MSGlobals::gCheck4Accidents) {
     898    115012408 :             myEdges->detectCollisions(myStep, STAGE_LANECHANGE);
     899              :         }
     900              :     }
     901              :     // flush arrived meso vehicles and micro vehicles that were removed due to collision
     902    127598975 :     myVehicleControl->removePending();
     903    127598975 :     loadRoutes();
     904              : 
     905              :     // persons
     906    127598959 :     if (myPersonControl != nullptr && myPersonControl->hasTransportables()) {
     907     74797111 :         myPersonControl->checkWaiting(this, myStep);
     908              :     }
     909              :     // containers
     910    127598907 :     if (myContainerControl != nullptr && myContainerControl->hasTransportables()) {
     911      4678969 :         myContainerControl->checkWaiting(this, myStep);
     912              :     }
     913              : #ifdef HAVE_FOX
     914    127598907 :     MSRoutingEngine::waitForAll();
     915    127598907 :     if (myPersonControl != nullptr) {
     916     76652481 :         myPersonControl->processPendingRouting(this, myStep);
     917              :     }
     918    127598899 :     if (myContainerControl != nullptr) {
     919      4739997 :         myContainerControl->processPendingRouting(this, myStep);
     920              :     }
     921              : #endif
     922    127598899 :     if (MSRailSignalControl::hasInstance()) {
     923       506296 :         MSRailSignalControl::getInstance().resetWaitRelations();
     924              :         // preserve waitRelation from insertion for the next step
     925              :     }
     926              :     // insert vehicles
     927    127598899 :     myInserter->determineCandidates(myStep);
     928    127598850 :     myInsertionEvents->execute(myStep);
     929              : #ifdef HAVE_FOX
     930    127598737 :     MSRoutingEngine::waitForAll();
     931              : #endif
     932    127598711 :     myInserter->emitVehicles(myStep);
     933    127598560 :     if (MSGlobals::gCheck4Accidents && !MSGlobals::gUseMesoSim) {
     934              :         //myEdges->patchActiveLanes(); // @note required to detect collisions on lanes that were empty before insertion. wasteful?
     935    115012101 :         myEdges->detectCollisions(myStep, STAGE_INSERTIONS);
     936              :     }
     937    127598560 :     MSVehicleTransfer::getInstance()->checkInsertions(myStep);
     938              : 
     939              :     // execute endOfTimestepEvents
     940    127598560 :     myEndOfTimestepEvents->execute(myStep);
     941              : 
     942    127598550 :     if (myLogExecutionTime) {
     943     89086063 :         myTraCIStepDuration -= SysUtils::getCurrentMillis();
     944              :     }
     945    127598550 :     if (onlyMove) {
     946            4 :         myStepCompletionMissing = true;
     947            4 :         return;
     948              :     }
     949    127598546 :     if (t != nullptr && lastTraCICmd == libsumo::CMD_EXECUTEMOVE) {
     950            6 :         t->processCommands(myStep, true);
     951              :     }
     952    127598546 :     postMoveStep();
     953              : }
     954              : 
     955              : 
     956              : void
     957    127598550 : MSNet::postMoveStep() {
     958    127598550 :     const int numControlled = libsumo::Helper::postProcessRemoteControl();
     959    127598550 :     if (numControlled > 0 && MSGlobals::gCheck4Accidents) {
     960      1228803 :         myEdges->detectCollisions(myStep, STAGE_REMOTECONTROL);
     961              :     }
     962    127598550 :     if (myLogExecutionTime) {
     963     89086063 :         myTraCIStepDuration += SysUtils::getCurrentMillis();
     964     89086063 :         myTraCIMillis += myTraCIStepDuration;
     965              :     }
     966    127598550 :     if (MSGlobals::gCheck4Accidents && !MSGlobals::gUseMesoSim) {
     967              :         // collisions from the previous step were kept to avoid duplicate
     968              :         // warnings. we must remove them now to ensure correct output.
     969    115012096 :         removeOutdatedCollisions();
     970              :     }
     971              :     // update and write (if needed) detector values
     972    127598550 :     mySimStepDuration = SysUtils::getCurrentMillis() - mySimStepDuration;
     973    127598550 :     writeOutput();
     974              : 
     975    127598534 :     if (myLogExecutionTime) {
     976     89086063 :         myVehiclesMoved += myVehicleControl->getRunningVehicleNo();
     977     89086063 :         if (myPersonControl != nullptr) {
     978     74090400 :             myPersonsMoved += myPersonControl->getRunningNumber();
     979              :         }
     980              :     }
     981    127598534 :     myStep += DELTA_T;
     982    127598534 : }
     983              : 
     984              : 
     985              : MSNet::SimulationState
     986    127499214 : MSNet::simulationState(SUMOTime stopTime) const {
     987    127499214 :     if (TraCIServer::wasClosed()) {
     988              :         return SIMSTATE_CONNECTION_CLOSED;
     989              :     }
     990    127496427 :     if (TraCIServer::getInstance() != nullptr && !TraCIServer::getInstance()->getLoadArgs().empty()) {
     991              :         return SIMSTATE_LOADING;
     992              :     }
     993    127496414 :     if ((stopTime < 0 || myStep > stopTime) && TraCIServer::getInstance() == nullptr && (stopTime > 0 || myStep > myEdgeDataEndTime)) {
     994    104302706 :         if ((myVehicleControl->getActiveVehicleCount() == 0)
     995     76266788 :                 && (myInserter->getPendingFlowCount() == 0)
     996     71940265 :                 && (myPersonControl == nullptr || !myPersonControl->hasNonWaiting())
     997       413337 :                 && (myContainerControl == nullptr || !myContainerControl->hasNonWaiting())
     998    104366930 :                 && !MSDevice_Taxi::hasServableReservations()) {
     999              :             return SIMSTATE_NO_FURTHER_VEHICLES;
    1000              :         }
    1001              :     }
    1002    127449182 :     if (stopTime >= 0 && myStep >= stopTime) {
    1003              :         return SIMSTATE_END_STEP_REACHED;
    1004              :     }
    1005    127428011 :     if (myMaxTeleports >= 0 && myVehicleControl->getTeleportCount() > myMaxTeleports) {
    1006              :         return SIMSTATE_TOO_MANY_TELEPORTS;
    1007              :     }
    1008    127428003 :     if (myAmInterrupted) {
    1009            7 :         return SIMSTATE_INTERRUPTED;
    1010              :     }
    1011              :     return SIMSTATE_RUNNING;
    1012              : }
    1013              : 
    1014              : 
    1015              : MSNet::SimulationState
    1016    127490538 : MSNet::adaptToState(MSNet::SimulationState state, const bool isLibsumo) const {
    1017    127490538 :     if (state == SIMSTATE_LOADING) {
    1018           13 :         OptionsIO::setArgs(TraCIServer::getInstance()->getLoadArgs());
    1019              :         TraCIServer::getInstance()->getLoadArgs().clear();
    1020    127490525 :     } else if (state != SIMSTATE_RUNNING && ((TraCIServer::getInstance() != nullptr && !TraCIServer::wasClosed()) || isLibsumo)) {
    1021              :         // overrides SIMSTATE_END_STEP_REACHED, e.g. (TraCI / Libsumo ignore SUMO's --end option)
    1022        23050 :         return SIMSTATE_RUNNING;
    1023    127467475 :     } else if (state == SIMSTATE_NO_FURTHER_VEHICLES) {
    1024        28942 :         if (myPersonControl != nullptr) {
    1025         7003 :             myPersonControl->abortAnyWaitingForVehicle();
    1026              :         }
    1027        28942 :         if (myContainerControl != nullptr) {
    1028         1862 :             myContainerControl->abortAnyWaitingForVehicle();
    1029              :         }
    1030        28942 :         myVehicleControl->abortWaiting();
    1031              :     }
    1032              :     return state;
    1033              : }
    1034              : 
    1035              : 
    1036              : std::string
    1037        40753 : MSNet::getStateMessage(MSNet::SimulationState state) {
    1038        40753 :     switch (state) {
    1039              :         case MSNet::SIMSTATE_RUNNING:
    1040          444 :             return "";
    1041              :         case MSNet::SIMSTATE_END_STEP_REACHED:
    1042         8321 :             return TL("The final simulation step has been reached.");
    1043              :         case MSNet::SIMSTATE_NO_FURTHER_VEHICLES:
    1044        29311 :             return TL("All vehicles have left the simulation.");
    1045              :         case MSNet::SIMSTATE_CONNECTION_CLOSED:
    1046         2651 :             return TL("TraCI requested termination.");
    1047              :         case MSNet::SIMSTATE_ERROR_IN_SIM:
    1048            0 :             return TL("An error occurred (see log).");
    1049              :         case MSNet::SIMSTATE_INTERRUPTED:
    1050            7 :             return TL("Interrupted.");
    1051              :         case MSNet::SIMSTATE_TOO_MANY_TELEPORTS:
    1052            6 :             return TL("Too many teleports.");
    1053              :         case MSNet::SIMSTATE_LOADING:
    1054           13 :             return TL("TraCI issued load command.");
    1055              :         default:
    1056            0 :             return TL("Unknown reason.");
    1057              :     }
    1058              : }
    1059              : 
    1060              : 
    1061              : void
    1062        43204 : MSNet::clearAll() {
    1063              :     // clear container
    1064        43204 :     MSEdge::clear();
    1065        43204 :     MSLane::clear();
    1066        43204 :     MSRoute::clear();
    1067        43204 :     delete MSVehicleTransfer::getInstance();
    1068        43204 :     MSDevice::cleanupAll();
    1069        43204 :     MSCalibrator::cleanup();
    1070        86912 :     while (!MSLaneSpeedTrigger::getInstances().empty()) {
    1071          504 :         delete MSLaneSpeedTrigger::getInstances().begin()->second;
    1072              :     }
    1073        47907 :     while (!MSTriggeredRerouter::getInstances().empty()) {
    1074         4703 :         delete MSTriggeredRerouter::getInstances().begin()->second;
    1075              :     }
    1076        43204 :     MSDevice_BTsender::cleanup();
    1077        43204 :     MSDevice_SSM::cleanup();
    1078        43204 :     MSDevice_ToC::cleanup();
    1079        43204 :     MSStopOut::cleanup();
    1080        43204 :     MSRailSignalConstraint::cleanup();
    1081        43204 :     MSRailSignalControl::cleanup();
    1082        43204 :     MSDriveWay::cleanup();
    1083              :     TraCIServer* t = TraCIServer::getInstance();
    1084        43204 :     if (t != nullptr) {
    1085         2770 :         t->cleanup();
    1086              :     }
    1087        43204 :     libsumo::Helper::cleanup();
    1088        43204 :     OutputDevice::closeAll(true);
    1089        43204 : }
    1090              : 
    1091              : 
    1092              : void
    1093          164 : MSNet::clearState(const SUMOTime step, bool quickReload) {
    1094          164 :     MSGlobals::gClearState = true;
    1095          164 :     if (MSGlobals::gUseMesoSim) {
    1096           12 :         MSGlobals::gMesoNet->clearState();
    1097          390 :         for (MSEdge* const edge : MSEdge::getAllEdges()) {
    1098          776 :             for (MESegment* s = MSGlobals::gMesoNet->getSegmentForEdge(*edge); s != nullptr; s = s->getNextSegment()) {
    1099          398 :                 s->clearState();
    1100              :             }
    1101              :         }
    1102              :     } else {
    1103         7184 :         for (MSEdge* const edge : MSEdge::getAllEdges()) {
    1104        15576 :             for (MSLane* const lane : edge->getLanes()) {
    1105         8544 :                 lane->getVehiclesSecure();
    1106         8544 :                 lane->clearState();
    1107         8544 :                 lane->releaseVehicles();
    1108              :             }
    1109         7032 :             edge->clearState();
    1110              :         }
    1111              :     }
    1112          164 :     myInserter->clearState();
    1113              :     // detectors may still reference persons/vehicles
    1114          164 :     myDetectorControl->updateDetectors(myStep);
    1115          164 :     myDetectorControl->writeOutput(myStep, true);
    1116          164 :     myDetectorControl->clearState(step);
    1117              : 
    1118          164 :     if (myPersonControl != nullptr) {
    1119           20 :         myPersonControl->clearState();
    1120              :     }
    1121          164 :     if (myContainerControl != nullptr) {
    1122            0 :         myContainerControl->clearState();
    1123              :     }
    1124              :     // delete vtypes after transportables have removed their types
    1125          164 :     myVehicleControl->clearState(true);
    1126          164 :     MSVehicleTransfer::getInstance()->clearState();
    1127          164 :     myLogics->clearState(step, quickReload);
    1128              :     // delete all routes after vehicles and detector output is done
    1129          164 :     MSRoute::dict_clearState();
    1130          205 :     for (auto& item : myStoppingPlaces) {
    1131           82 :         for (auto& item2 : item.second) {
    1132           41 :             item2.second->clearState();
    1133              :         }
    1134              :     }
    1135          164 :     myShapeContainer->clearState();
    1136          164 :     myBeginOfTimestepEvents->clearState(myStep, step);
    1137          164 :     myEndOfTimestepEvents->clearState(myStep, step);
    1138          164 :     myInsertionEvents->clearState(myStep, step);
    1139          164 :     MSRailSignalControl::clearState();
    1140          164 :     MSDriveWay::clearState();
    1141          164 :     myStep = step;
    1142          164 :     MSGlobals::gClearState = false;
    1143          164 : }
    1144              : 
    1145              : 
    1146              : SUMOTime
    1147          571 : MSNet::getLoaderTime() const {
    1148          571 :     return myRouteLoaders->getCurrentLoadTime();
    1149              : }
    1150              : 
    1151              : void
    1152          712 : MSNet::setLoaderTime(SUMOTime time) {
    1153          712 :     myRouteLoaders->setCurrentLoadTime(time);
    1154          712 :     myStateLoaderTime = MAX2(myStateLoaderTime, time);
    1155          712 : }
    1156              : 
    1157              : void
    1158    127598550 : MSNet::writeOutput() {
    1159              :     // update detector values
    1160    127598550 :     myDetectorControl->updateDetectors(myStep);
    1161    127598541 :     const OptionsCont& oc = OptionsCont::getOptions();
    1162              : 
    1163              :     // check state dumps
    1164    255197082 :     if (oc.isSet("netstate-dump")) {
    1165        12936 :         MSXMLRawOut::write(OutputDevice::getDeviceByOption("netstate-dump"), *myEdges, myStep,
    1166              :                            oc.getInt("netstate-dump.precision"));
    1167              :     }
    1168              : 
    1169              :     // check fcd dumps
    1170    255197082 :     if (OptionsCont::getOptions().isSet("fcd-output")) {
    1171     12326764 :         if (OptionsCont::getOptions().isSet("person-fcd-output")) {
    1172           24 :             MSFCDExport::write(OutputDevice::getDeviceByOption("fcd-output"), myStep, SUMO_TAG_VEHICLE);
    1173           48 :             MSFCDExport::write(OutputDevice::getDeviceByOption("person-fcd-output"), myStep, SUMO_TAG_PERSON);
    1174              :         } else {
    1175     12326716 :             MSFCDExport::write(OutputDevice::getDeviceByOption("fcd-output"), myStep);
    1176              :         }
    1177              :     }
    1178              : 
    1179              :     // check emission dumps
    1180    255197082 :     if (OptionsCont::getOptions().isSet("emission-output")) {
    1181       215992 :         MSEmissionExport::write(OutputDevice::getDeviceByOption("emission-output"), myStep);
    1182              :     }
    1183              : 
    1184              :     // battery dumps
    1185    255197082 :     if (OptionsCont::getOptions().isSet("battery-output")) {
    1186       148254 :         MSBatteryExport::write(OutputDevice::getDeviceByOption("battery-output"), myStep,
    1187              :                                oc.getInt("battery-output.precision"));
    1188              :     }
    1189              : 
    1190              :     // charging station aggregated dumps
    1191    127689655 :     if (OptionsCont::getOptions().isSet("chargingstations-output") && OptionsCont::getOptions().getBool("chargingstations-output.aggregated")) {
    1192        22248 :         MSChargingStationExport::write(OutputDevice::getDeviceByOption("chargingstations-output"));
    1193              :     }
    1194              : 
    1195              :     // elecHybrid dumps
    1196    255197082 :     if (OptionsCont::getOptions().isSet("elechybrid-output")) {
    1197          450 :         std::string output = OptionsCont::getOptions().getString("elechybrid-output");
    1198              : 
    1199          900 :         if (oc.getBool("elechybrid-output.aggregated")) {
    1200              :             // build a xml file with aggregated device.elechybrid output
    1201          600 :             MSElecHybridExport::writeAggregated(OutputDevice::getDeviceByOption("elechybrid-output"), myStep,
    1202              :                                                 oc.getInt("elechybrid-output.precision"));
    1203              :         } else {
    1204              :             // build a separate xml file for each vehicle equipped with device.elechybrid
    1205              :             // RICE_TODO: Does this have to be placed here in MSNet.cpp ?
    1206          150 :             MSVehicleControl& vc = MSNet::getInstance()->getVehicleControl();
    1207          204 :             for (MSVehicleControl::constVehIt it = vc.loadedVehBegin(); it != vc.loadedVehEnd(); ++it) {
    1208           54 :                 const SUMOVehicle* veh = it->second;
    1209           54 :                 if (!veh->isOnRoad()) {
    1210            0 :                     continue;
    1211              :                 }
    1212           54 :                 if (static_cast<MSDevice_ElecHybrid*>(veh->getDevice(typeid(MSDevice_ElecHybrid))) != nullptr) {
    1213              :                     std::string vehID = veh->getID();
    1214           54 :                     std::string filename2 = output + "_" + vehID + ".xml";
    1215           54 :                     OutputDevice& dev = OutputDevice::getDevice(filename2);
    1216              :                     std::map<SumoXMLAttr, std::string> attrs;
    1217           54 :                     attrs[SUMO_ATTR_VEHICLE] = vehID;
    1218           54 :                     attrs[SUMO_ATTR_MAXIMUMBATTERYCAPACITY] = toString(dynamic_cast<MSDevice_ElecHybrid*>(veh->getDevice(typeid(MSDevice_ElecHybrid)))->getMaximumBatteryCapacity());
    1219           54 :                     attrs[SUMO_ATTR_RECUPERATIONENABLE] = toString(MSGlobals::gOverheadWireRecuperation);
    1220          108 :                     dev.writeXMLHeader("elecHybrid-export", "", attrs);
    1221          108 :                     MSElecHybridExport::write(OutputDevice::getDevice(filename2), veh, myStep, oc.getInt("elechybrid-output.precision"));
    1222              :                 }
    1223              :             }
    1224              :         }
    1225              :     }
    1226              : 
    1227              : 
    1228              :     // check full dumps
    1229    255197082 :     if (OptionsCont::getOptions().isSet("full-output")) {
    1230         1138 :         MSGlobals::gHaveEmissions = true;
    1231         2276 :         MSFullExport::write(OutputDevice::getDeviceByOption("full-output"), myStep);
    1232              :     }
    1233              : 
    1234              :     // check queue dumps
    1235    255197082 :     if (OptionsCont::getOptions().isSet("queue-output")) {
    1236       330534 :         MSQueueExport::write(OutputDevice::getDeviceByOption("queue-output"), myStep);
    1237              :     }
    1238              : 
    1239              :     // check amitran dumps
    1240    255197082 :     if (OptionsCont::getOptions().isSet("amitran-output")) {
    1241         2040 :         MSAmitranTrajectories::write(OutputDevice::getDeviceByOption("amitran-output"), myStep);
    1242              :     }
    1243              : 
    1244              :     // check vtk dumps
    1245    255197082 :     if (OptionsCont::getOptions().isSet("vtk-output")) {
    1246              : 
    1247           60 :         if (MSNet::getInstance()->getVehicleControl().getRunningVehicleNo() > 0) {
    1248           60 :             std::string timestep = time2string(myStep);
    1249           60 :             if (TS >= 1.0) {
    1250           48 :                 timestep = timestep.substr(0, timestep.length() - 3);
    1251           36 :             } else if (DELTA_T % 100 == 0) {
    1252           72 :                 timestep = timestep.substr(0, timestep.length() - 1);
    1253              :             }
    1254           66 :             std::string output = OptionsCont::getOptions().getString("vtk-output");
    1255           66 :             std::string filename = output + "_" + timestep + ".vtp";
    1256              : 
    1257           60 :             OutputDevice_File dev(filename);
    1258              : 
    1259              :             //build a huge mass of xml files
    1260           54 :             MSVTKExport::write(dev, myStep);
    1261              : 
    1262           54 :         }
    1263              : 
    1264              :     }
    1265              : 
    1266    127598535 :     writeSummaryOutput();
    1267              : 
    1268              :     // write detector values
    1269    127598535 :     myDetectorControl->writeOutput(myStep + DELTA_T, false);
    1270              : 
    1271              :     // write link states
    1272    255197068 :     if (OptionsCont::getOptions().isSet("link-output")) {
    1273         4048 :         OutputDevice& od = OutputDevice::getDeviceByOption("link-output");
    1274         4048 :         od.openTag("timestep");
    1275         4048 :         od.writeAttr(SUMO_ATTR_ID, STEPS2TIME(myStep));
    1276        85848 :         for (const MSEdge* const edge : myEdges->getEdges()) {
    1277       180200 :             for (const MSLane* const lane : edge->getLanes()) {
    1278       212304 :                 for (const MSLink* const link : lane->getLinkCont()) {
    1279       227808 :                     link->writeApproaching(od, lane->getID());
    1280              :                 }
    1281              :             }
    1282              :         }
    1283         8096 :         od.closeTag();
    1284              :     }
    1285              : 
    1286              :     // write SSM output
    1287    130131354 :     for (MSDevice_SSM* dev : MSDevice_SSM::getInstances()) {
    1288      2532820 :         dev->updateAndWriteOutput();
    1289              :     }
    1290              : 
    1291              :     // write ToC output
    1292    127614253 :     for (MSDevice_ToC* dev : MSDevice_ToC::getInstances()) {
    1293        15719 :         if (dev->generatesOutput()) {
    1294        15513 :             dev->writeOutput();
    1295              :         }
    1296              :     }
    1297              : 
    1298    255197068 :     if (OptionsCont::getOptions().isSet("collision-output")) {
    1299        10390 :         writeCollisions();
    1300              :     }
    1301    127598534 : }
    1302              : 
    1303              : 
    1304              : bool
    1305            0 : MSNet::logSimulationDuration() const {
    1306            0 :     return myLogExecutionTime;
    1307              : }
    1308              : 
    1309              : 
    1310              : MSTransportableControl&
    1311     23785191 : MSNet::getPersonControl() {
    1312     23785191 :     if (myPersonControl == nullptr) {
    1313         6820 :         myPersonControl = new MSTransportableControl(true);
    1314              :     }
    1315     23785167 :     return *myPersonControl;
    1316              : }
    1317              : 
    1318              : 
    1319              : MSTransportableControl&
    1320      8536510 : MSNet::getContainerControl() {
    1321      8536510 :     if (myContainerControl == nullptr) {
    1322         1782 :         myContainerControl = new MSTransportableControl(false);
    1323              :     }
    1324      8536510 :     return *myContainerControl;
    1325              : }
    1326              : 
    1327              : MSDynamicShapeUpdater*
    1328           23 : MSNet::makeDynamicShapeUpdater() {
    1329           23 :     myDynamicShapeUpdater = std::unique_ptr<MSDynamicShapeUpdater> (new MSDynamicShapeUpdater(*myShapeContainer));
    1330           23 :     return myDynamicShapeUpdater.get();
    1331              : }
    1332              : 
    1333              : MSEdgeWeightsStorage&
    1334      7019071 : MSNet::getWeightsStorage() {
    1335      7019071 :     if (myEdgeWeights == nullptr) {
    1336         2161 :         myEdgeWeights = new MSEdgeWeightsStorage();
    1337              :     }
    1338      7019071 :     return *myEdgeWeights;
    1339              : }
    1340              : 
    1341              : 
    1342              : void
    1343          127 : MSNet::preSimStepOutput() const {
    1344          127 :     std::cout << "Step #" << time2string(myStep);
    1345          127 : }
    1346              : 
    1347              : 
    1348              : void
    1349          127 : MSNet::postSimStepOutput() const {
    1350          127 :     if (myLogExecutionTime) {
    1351          125 :         std::ostringstream oss;
    1352              :         oss.setf(std::ios::fixed, std::ios::floatfield);     // use decimal format
    1353              :         oss.setf(std::ios::showpoint);    // print decimal point
    1354          125 :         oss << std::setprecision(gPrecision);
    1355          125 :         if (mySimStepDuration != 0) {
    1356           76 :             const double durationSec = (double)mySimStepDuration / 1000.;
    1357           76 :             oss << " (" << mySimStepDuration << "ms ~= "
    1358           76 :                 << (TS / durationSec) << "*RT, ~"
    1359           76 :                 << ((double) myVehicleControl->getRunningVehicleNo() / durationSec);
    1360              :         } else {
    1361           49 :             oss << " (0ms ?*RT. ?";
    1362              :         }
    1363          125 :         oss << "UPS, ";
    1364          125 :         if (TraCIServer::getInstance() != nullptr) {
    1365           79 :             oss << "TraCI: " << myTraCIStepDuration << "ms, ";
    1366              :         }
    1367          125 :         oss << "vehicles TOT " << myVehicleControl->getDepartedVehicleNo()
    1368          250 :             << " ACT " << myVehicleControl->getRunningVehicleNo()
    1369          125 :             << " BUF " << myInserter->getWaitingVehicleNo()
    1370          125 :             << ")                                              ";
    1371          250 :         std::string prev = "Step #" + time2string(myStep - DELTA_T);
    1372          250 :         std::cout << oss.str().substr(0, 90 - prev.length());
    1373          125 :     }
    1374          127 :     std::cout << '\r';
    1375          127 : }
    1376              : 
    1377              : 
    1378              : void
    1379        12062 : MSNet::addVehicleStateListener(VehicleStateListener* listener) {
    1380        12062 :     if (find(myVehicleStateListeners.begin(), myVehicleStateListeners.end(), listener) == myVehicleStateListeners.end()) {
    1381        12062 :         myVehicleStateListeners.push_back(listener);
    1382              :     }
    1383        12062 : }
    1384              : 
    1385              : 
    1386              : void
    1387           58 : MSNet::removeVehicleStateListener(VehicleStateListener* listener) {
    1388           58 :     std::vector<VehicleStateListener*>::iterator i = std::find(myVehicleStateListeners.begin(), myVehicleStateListeners.end(), listener);
    1389           58 :     if (i != myVehicleStateListeners.end()) {
    1390           58 :         myVehicleStateListeners.erase(i);
    1391              :     }
    1392           58 : }
    1393              : 
    1394              : 
    1395              : void
    1396     16140964 : MSNet::informVehicleStateListener(const SUMOVehicle* const vehicle, VehicleState to, const std::string& info) {
    1397              : #ifdef HAVE_FOX
    1398     16140964 :     ScopedLocker<> lock(myVehicleStateListenerMutex, MSGlobals::gNumThreads > 1);
    1399              : #endif
    1400     16887314 :     for (VehicleStateListener* const listener : myVehicleStateListeners) {
    1401       746350 :         listener->vehicleStateChanged(vehicle, to, info);
    1402              :     }
    1403     16140964 : }
    1404              : 
    1405              : 
    1406              : void
    1407         3932 : MSNet::addTransportableStateListener(TransportableStateListener* listener) {
    1408         3932 :     if (find(myTransportableStateListeners.begin(), myTransportableStateListeners.end(), listener) == myTransportableStateListeners.end()) {
    1409         3932 :         myTransportableStateListeners.push_back(listener);
    1410              :     }
    1411         3932 : }
    1412              : 
    1413              : 
    1414              : void
    1415            0 : MSNet::removeTransportableStateListener(TransportableStateListener* listener) {
    1416            0 :     std::vector<TransportableStateListener*>::iterator i = std::find(myTransportableStateListeners.begin(), myTransportableStateListeners.end(), listener);
    1417            0 :     if (i != myTransportableStateListeners.end()) {
    1418            0 :         myTransportableStateListeners.erase(i);
    1419              :     }
    1420            0 : }
    1421              : 
    1422              : 
    1423              : void
    1424      1010792 : MSNet::informTransportableStateListener(const MSTransportable* const transportable, TransportableState to, const std::string& info) {
    1425              : #ifdef HAVE_FOX
    1426      1010792 :     ScopedLocker<> lock(myTransportableStateListenerMutex, MSGlobals::gNumThreads > 1);
    1427              : #endif
    1428      1013610 :     for (TransportableStateListener* const listener : myTransportableStateListeners) {
    1429         2818 :         listener->transportableStateChanged(transportable, to, info);
    1430              :     }
    1431      1010792 : }
    1432              : 
    1433              : 
    1434              : bool
    1435        19626 : MSNet::registerCollision(const SUMOTrafficObject* collider, const SUMOTrafficObject* victim, const std::string& collisionType, const MSLane* lane, double pos) {
    1436              :     auto it = myCollisions.find(collider->getID());
    1437        19626 :     if (it != myCollisions.end()) {
    1438        12751 :         for (Collision& old : it->second) {
    1439        12632 :             if (old.victim == victim->getID()) {
    1440              :                 // collision from previous step continues
    1441        11253 :                 old.continuationTime = myStep;
    1442              :                 return false;
    1443              :             }
    1444              :         }
    1445              :     } else {
    1446              :         // maybe the roles have been reversed
    1447              :         auto it2 = myCollisions.find(victim->getID());
    1448         8254 :         if (it2 != myCollisions.end()) {
    1449         2053 :             for (Collision& old : it2->second) {
    1450         1896 :                 if (old.victim == collider->getID()) {
    1451              :                     // collision from previous step continues (keep the old roles)
    1452         1729 :                     old.continuationTime = myStep;
    1453              :                     return false;
    1454              :                 }
    1455              :             }
    1456              :         }
    1457              :     }
    1458              :     Collision c;
    1459              :     c.victim = victim->getID();
    1460         6644 :     c.colliderType = collider->getVehicleType().getID();
    1461         6644 :     c.victimType = victim->getVehicleType().getID();
    1462         6644 :     c.colliderSpeed = collider->getSpeed();
    1463         6644 :     c.victimSpeed = victim->getSpeed();
    1464         6644 :     c.colliderFront = collider->getPosition();
    1465         6644 :     c.victimFront = victim->getPosition();
    1466         6644 :     c.colliderBack = collider->getPosition(-collider->getVehicleType().getLength());
    1467         6644 :     c.victimBack = victim->getPosition(-victim->getVehicleType().getLength());
    1468              :     c.type = collisionType;
    1469         6644 :     c.lane = lane;
    1470         6644 :     c.pos = pos;
    1471         6644 :     c.time = myStep;
    1472         6644 :     c.continuationTime = myStep;
    1473         6644 :     myCollisions[collider->getID()].push_back(c);
    1474              :     return true;
    1475         6644 : }
    1476              : 
    1477              : 
    1478              : void
    1479    115012096 : MSNet::removeOutdatedCollisions() {
    1480    115031141 :     for (auto it = myCollisions.begin(); it != myCollisions.end();) {
    1481        38897 :         for (auto it2 = it->second.begin(); it2 != it->second.end();) {
    1482        19852 :             if (it2->continuationTime != myStep) {
    1483         6633 :                 it2 = it->second.erase(it2);
    1484              :             } else {
    1485              :                 it2++;
    1486              :             }
    1487              :         }
    1488        19045 :         if (it->second.size() == 0) {
    1489              :             it = myCollisions.erase(it);
    1490              :         } else {
    1491              :             it++;
    1492              :         }
    1493              :     }
    1494    115012096 : }
    1495              : 
    1496              : 
    1497              : bool
    1498        84805 : MSNet::addStoppingPlace(SumoXMLTag category, MSStoppingPlace* stop) {
    1499        84805 :     if (category == SUMO_TAG_TRAIN_STOP) {
    1500        14081 :         category = SUMO_TAG_BUS_STOP;
    1501              :     }
    1502        84805 :     const bool isNew = myStoppingPlaces[category].add(stop->getID(), stop);
    1503        84805 :     if (isNew && stop->getMyName() != "") {
    1504        16204 :         myNamedStoppingPlaces[category][stop->getMyName()].push_back(stop);
    1505              :     }
    1506        84805 :     return isNew;
    1507              : }
    1508              : 
    1509              : 
    1510              : bool
    1511           17 : MSNet::addTractionSubstation(MSTractionSubstation* substation) {
    1512           17 :     if (find(myTractionSubstations.begin(), myTractionSubstations.end(), substation) == myTractionSubstations.end()) {
    1513           17 :         myTractionSubstations.push_back(substation);
    1514           17 :         return true;
    1515              :     }
    1516              :     return false;
    1517              : }
    1518              : 
    1519              : 
    1520              : MSStoppingPlace*
    1521      1634047 : MSNet::getStoppingPlace(const std::string& id, const SumoXMLTag category) const {
    1522              :     if (myStoppingPlaces.count(category) > 0) {
    1523              :         return myStoppingPlaces.find(category)->second.get(id);
    1524              :     }
    1525              :     return nullptr;
    1526              : }
    1527              : 
    1528              : 
    1529              : MSStoppingPlace*
    1530       173258 : MSNet::getStoppingPlace(const std::string& id) const {
    1531       859194 :     for (SumoXMLTag category : std::vector<SumoXMLTag>({SUMO_TAG_BUS_STOP, SUMO_TAG_PARKING_AREA, SUMO_TAG_CONTAINER_STOP, SUMO_TAG_CHARGING_STATION, SUMO_TAG_OVERHEAD_WIRE_SEGMENT})) {
    1532       722518 :         MSStoppingPlace* result = getStoppingPlace(id, category);
    1533       722518 :         if (result != nullptr) {
    1534              :             return result;
    1535              :         }
    1536       173258 :     }
    1537       136676 :     return nullptr;
    1538              : }
    1539              : 
    1540              : 
    1541              : std::string
    1542       465942 : MSNet::getStoppingPlaceID(const MSLane* lane, const double pos, const SumoXMLTag category) const {
    1543              :     if (myStoppingPlaces.count(category) > 0) {
    1544       955672 :         for (const auto& it : myStoppingPlaces.find(category)->second) {
    1545       875373 :             MSStoppingPlace* stop = it.second;
    1546       875373 :             if (&stop->getLane() == lane && stop->getBeginLanePosition() - POSITION_EPS <= pos && stop->getEndLanePosition() + POSITION_EPS >= pos) {
    1547              :                 return stop->getID();
    1548              :             }
    1549              :         }
    1550              :     }
    1551       359997 :     return "";
    1552              : }
    1553              : 
    1554              : 
    1555              : const std::vector<MSStoppingPlace*>&
    1556         1937 : MSNet::getStoppingPlaceAlternatives(const std::string& name, SumoXMLTag category) const {
    1557         1937 :     if (category == SUMO_TAG_TRAIN_STOP) {
    1558              :         category = SUMO_TAG_BUS_STOP;
    1559              :     }
    1560              :     auto it = myNamedStoppingPlaces.find(category);
    1561         1937 :     if (it != myNamedStoppingPlaces.end()) {
    1562              :         auto it2 = it->second.find(name);
    1563         1858 :         if (it2 != it->second.end()) {
    1564         1858 :             return it2->second;
    1565              :         }
    1566              :     }
    1567              :     return myEmptyStoppingPlaceVector;
    1568              : }
    1569              : 
    1570              : 
    1571              : const NamedObjectCont<MSStoppingPlace*>&
    1572        13996 : MSNet::getStoppingPlaces(SumoXMLTag category) const {
    1573              :     auto it = myStoppingPlaces.find(category);
    1574        13996 :     if (it != myStoppingPlaces.end()) {
    1575        13724 :         return it->second;
    1576              :     } else {
    1577              :         return myEmptyStoppingPlaceCont;
    1578              :     }
    1579              : }
    1580              : 
    1581              : 
    1582              : void
    1583          106 : MSNet::writeChargingStationOutput() const {
    1584              :     if (myStoppingPlaces.count(SUMO_TAG_CHARGING_STATION) > 0) {
    1585          204 :         OutputDevice& output = OutputDevice::getDeviceByOption("chargingstations-output");
    1586          586 :         for (const auto& it : myStoppingPlaces.find(SUMO_TAG_CHARGING_STATION)->second) {
    1587          484 :             static_cast<MSChargingStation*>(it.second)->writeChargingStationOutput(output);
    1588              :         }
    1589              :     }
    1590          106 : }
    1591              : 
    1592              : 
    1593              : void
    1594        41363 : MSNet::writeRailSignalBlocks() const {
    1595        82726 :     if (OptionsCont::getOptions().isSet("railsignal-block-output")) {
    1596         1369 :         OutputDevice& output = OutputDevice::getDeviceByOption("railsignal-block-output");
    1597         5422 :         for (auto tls : myLogics->getAllLogics()) {
    1598         4053 :             MSRailSignal* rs = dynamic_cast<MSRailSignal*>(tls);
    1599         4053 :             if (rs != nullptr) {
    1600         4009 :                 rs->writeBlocks(output, false);
    1601              :             }
    1602         1369 :         }
    1603         1369 :         MSDriveWay::writeDepatureBlocks(output, false);
    1604              :     }
    1605        82726 :     if (OptionsCont::getOptions().isSet("railsignal-vehicle-output")) {
    1606          185 :         OutputDevice& output = OutputDevice::getDeviceByOption("railsignal-vehicle-output");
    1607          599 :         for (auto tls : myLogics->getAllLogics()) {
    1608          414 :             MSRailSignal* rs = dynamic_cast<MSRailSignal*>(tls);
    1609          414 :             if (rs != nullptr) {
    1610          414 :                 rs->writeBlocks(output, true);
    1611              :             }
    1612          185 :         }
    1613          185 :         MSDriveWay::writeDepatureBlocks(output, true);
    1614              :     }
    1615        41363 : }
    1616              : 
    1617              : 
    1618              : void
    1619            5 : MSNet::writeOverheadWireSegmentOutput() const {
    1620              :     if (myStoppingPlaces.count(SUMO_TAG_OVERHEAD_WIRE_SEGMENT) > 0) {
    1621           10 :         OutputDevice& output = OutputDevice::getDeviceByOption("overheadwiresegments-output");
    1622           53 :         for (const auto& it : myStoppingPlaces.find(SUMO_TAG_OVERHEAD_WIRE_SEGMENT)->second) {
    1623           48 :             static_cast<MSOverheadWire*>(it.second)->writeOverheadWireSegmentOutput(output);
    1624              :         }
    1625              :     }
    1626            5 : }
    1627              : 
    1628              : 
    1629              : void
    1630            5 : MSNet::writeSubstationOutput() const {
    1631            5 :     if (myTractionSubstations.size() > 0) {
    1632            5 :         OutputDevice& output = OutputDevice::getDeviceByOption("substations-output");
    1633           10 :         output.setPrecision(OptionsCont::getOptions().getInt("substations-output.precision"));
    1634           13 :         for (auto& it : myTractionSubstations) {
    1635            8 :             it->writeTractionSubstationOutput(output);
    1636              :         }
    1637              :     }
    1638            5 : }
    1639              : 
    1640              : 
    1641              : MSTractionSubstation*
    1642           19 : MSNet::findTractionSubstation(const std::string& substationId) {
    1643           22 :     for (std::vector<MSTractionSubstation*>::iterator it = myTractionSubstations.begin(); it != myTractionSubstations.end(); ++it) {
    1644           22 :         if ((*it)->getID() == substationId) {
    1645              :             return *it;
    1646              :         }
    1647              :     }
    1648              :     return nullptr;
    1649              : }
    1650              : 
    1651              : 
    1652              : MSVehicleRouter&
    1653       152840 : MSNet::getRouterTT(int rngIndex, const Prohibitions& prohibited) const {
    1654       152840 :     if (MSGlobals::gNumSimThreads == 1) {
    1655       133356 :         rngIndex = 0;
    1656              :     }
    1657              :     if (myRouterTT.count(rngIndex) == 0) {
    1658         1641 :         const std::string routingAlgorithm = OptionsCont::getOptions().getString("routing-algorithm");
    1659         1641 :         if (routingAlgorithm == "dijkstra") {
    1660         1426 :             myRouterTT[rngIndex] = new DijkstraRouter<MSEdge, SUMOVehicle>(MSEdge::getAllEdges(), true, &MSNet::getTravelTime, nullptr, false, nullptr, true);
    1661          215 :         } else if (routingAlgorithm == "CCH") {
    1662              :             // free-flow CCH metrics per vehicle type; every query a shared
    1663              :             // metric cannot serve (TraCI edge weights, non-default routing
    1664              :             // modes, prohibitions beyond live closures) routes on the exact
    1665              :             // embedded fallback -- see MSRoutingEngine::getFreeflowCCHMetric
    1666              :             SUMOAbstractRouter<MSEdge, SUMOVehicle>* fallback =
    1667          109 :                 new AStarRouter<MSEdge, SUMOVehicle, MSMapMatcher>(MSEdge::getAllEdges(), true, &MSNet::getTravelTime, nullptr, true);
    1668          109 :             myRouterTT[rngIndex] = new CCHRouter<MSEdge, SUMOVehicle, MSCCHGraph>(
    1669          109 :                 MSRoutingEngine::ensureCCHGraph(), &MSRoutingEngine::getFreeflowCCHMetric,
    1670          218 :                 &MSNet::getTravelTime, true, fallback);
    1671              :         } else {
    1672          106 :             if (routingAlgorithm != "astar") {
    1673            0 :                 WRITE_WARNINGF(TL("TraCI and Triggers cannot use routing algorithm '%'. using 'astar' instead."), routingAlgorithm);
    1674              :             }
    1675          106 :             myRouterTT[rngIndex] = new AStarRouter<MSEdge, SUMOVehicle, MSMapMatcher>(MSEdge::getAllEdges(), true, &MSNet::getTravelTime, nullptr, true);
    1676              :         }
    1677              :     }
    1678       152840 :     myRouterTT[rngIndex]->prohibit(prohibited);
    1679       152840 :     return *myRouterTT[rngIndex];
    1680              : }
    1681              : 
    1682              : 
    1683              : MSVehicleRouter&
    1684           11 : MSNet::getRouterEffort(int rngIndex, const Prohibitions& prohibited) const {
    1685           11 :     if (MSGlobals::gNumSimThreads == 1) {
    1686           11 :         rngIndex = 0;
    1687              :     }
    1688              :     if (myRouterEffort.count(rngIndex) == 0) {
    1689           11 :         myRouterEffort[rngIndex] = new DijkstraRouter<MSEdge, SUMOVehicle>(MSEdge::getAllEdges(), true, &MSNet::getEffort, &MSNet::getTravelTime, false, nullptr, true);
    1690              :     }
    1691           11 :     myRouterEffort[rngIndex]->prohibit(prohibited);
    1692           11 :     return *myRouterEffort[rngIndex];
    1693              : }
    1694              : 
    1695              : 
    1696              : MSPedestrianRouter&
    1697       816996 : MSNet::getPedestrianRouter(int rngIndex, const Prohibitions& prohibited) const {
    1698       816996 :     if (MSGlobals::gNumSimThreads == 1) {
    1699       728104 :         rngIndex = 0;
    1700              :     }
    1701              :     if (myPedestrianRouter.count(rngIndex) == 0) {
    1702         2848 :         myPedestrianRouter[rngIndex] = new MSPedestrianRouter();
    1703              :     }
    1704       816996 :     myPedestrianRouter[rngIndex]->prohibit(prohibited);
    1705       816996 :     return *myPedestrianRouter[rngIndex];
    1706              : }
    1707              : 
    1708              : 
    1709              : MSTransportableRouter&
    1710       165438 : MSNet::getIntermodalRouter(int rngIndex, const int routingMode, const Prohibitions& prohibited) const {
    1711       165438 :     if (MSGlobals::gNumSimThreads == 1) {
    1712              :         rngIndex = 0;
    1713              :     }
    1714       165438 :     const OptionsCont& oc = OptionsCont::getOptions();
    1715       165438 :     const int key = rngIndex * oc.getInt("thread-rngs") + routingMode;
    1716              :     if (myIntermodalRouter.count(key) == 0) {
    1717         4014 :         const int carWalk = SUMOVehicleParserHelper::parseCarWalkTransfer(oc, MSDevice_Taxi::hasFleet() || myInserter->hasTaxiFlow());
    1718         3833 :         const std::string routingAlgorithm = OptionsCont::getOptions().getString("routing-algorithm");
    1719         3833 :         const double taxiWait = STEPS2TIME(string2time(OptionsCont::getOptions().getString("persontrip.taxi.waiting-time")));
    1720         3833 :         if (routingMode == libsumo::ROUTING_MODE_COMBINED) {
    1721            0 :             myIntermodalRouter[key] = new MSTransportableRouter(MSNet::adaptIntermodalRouter, carWalk, taxiWait, routingAlgorithm, routingMode, new FareModul());
    1722              :         } else {
    1723         3833 :             myIntermodalRouter[key] = new MSTransportableRouter(MSNet::adaptIntermodalRouter, carWalk, taxiWait, routingAlgorithm, routingMode);
    1724              :         }
    1725              :     }
    1726       165438 :     myIntermodalRouter[key]->prohibit(prohibited);
    1727       165438 :     return *myIntermodalRouter[key];
    1728              : }
    1729              : 
    1730              : 
    1731              : void
    1732        43010 : MSNet::resetIntermodalRouter() const {
    1733        46842 :     for (auto& router : myIntermodalRouter) {
    1734         3832 :         delete router.second;
    1735              :     }
    1736              :     myIntermodalRouter.clear();
    1737        43010 : }
    1738              : 
    1739              : 
    1740              : void
    1741         4987 : MSNet::adaptIntermodalRouter(MSTransportableRouter& router) {
    1742         9974 :     double taxiWait = STEPS2TIME(string2time(OptionsCont::getOptions().getString("persontrip.taxi.waiting-time")));
    1743              :     // add access to all parking areas
    1744              :     EffortCalculator* const external = router.getExternalEffort();
    1745        14740 :     for (const auto& stopType : myInstance->myStoppingPlaces) {
    1746              :         // add access to all stopping places
    1747         9753 :         const SumoXMLTag element = stopType.first;
    1748        36016 :         for (const auto& i : stopType.second) {
    1749        26263 :             const MSEdge* const edge = &i.second->getLane().getEdge();
    1750        26263 :             router.getNetwork()->addAccess(i.first, edge, i.second->getBeginLanePosition(), i.second->getEndLanePosition(),
    1751              :                                            0., element, false, taxiWait);
    1752        26263 :             if (element == SUMO_TAG_BUS_STOP) {
    1753              :                 // add access to all public transport stops
    1754        12784 :                 for (const auto& a : i.second->getAllAccessPos()) {
    1755         1189 :                     router.getNetwork()->addAccess(i.first, &a.lane->getEdge(), a.startPos, a.endPos, a.length, element, true, taxiWait);
    1756              :                 }
    1757        11595 :                 if (external != nullptr) {
    1758            0 :                     external->addStop(router.getNetwork()->getStopEdge(i.first)->getNumericalID(), *i.second);
    1759              :                 }
    1760              :             }
    1761              :         }
    1762              :     }
    1763         4987 :     myInstance->getInsertionControl().adaptIntermodalRouter(router);
    1764         4987 :     myInstance->getVehicleControl().adaptIntermodalRouter(router);
    1765              :     // add access to transfer from walking to taxi-use
    1766         4987 :     if ((router.getCarWalkTransfer() & ModeChangeOptions::TAXI_PICKUP_ANYWHERE) != 0) {
    1767        60955 :         for (MSEdge* edge : myInstance->getEdgeControl().getEdges()) {
    1768        60725 :             if ((edge->getPermissions() & SVC_PEDESTRIAN) != 0 && (edge->getPermissions() & SVC_TAXI) != 0) {
    1769        20261 :                 router.getNetwork()->addCarAccess(edge, SVC_TAXI, taxiWait);
    1770              :             }
    1771              :         }
    1772              :     }
    1773         4987 : }
    1774              : 
    1775              : 
    1776              : bool
    1777        43053 : MSNet::checkElevation() {
    1778        43053 :     const MSEdgeVector& edges = myEdges->getEdges();
    1779      1864489 :     for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
    1780      4006968 :         for (std::vector<MSLane*>::const_iterator i = (*e)->getLanes().begin(); i != (*e)->getLanes().end(); ++i) {
    1781      2185532 :             if ((*i)->getShape().hasElevation()) {
    1782              :                 return true;
    1783              :             }
    1784              :         }
    1785              :     }
    1786              :     return false;
    1787              : }
    1788              : 
    1789              : 
    1790              : bool
    1791        43053 : MSNet::checkWalkingarea() {
    1792      1294338 :     for (const MSEdge* e : myEdges->getEdges()) {
    1793      1261894 :         if (e->getFunction() == SumoXMLEdgeFunc::WALKINGAREA) {
    1794              :             return true;
    1795              :         }
    1796              :     }
    1797              :     return false;
    1798              : }
    1799              : 
    1800              : 
    1801              : bool
    1802        43053 : MSNet::checkBidiEdges() {
    1803      1801400 :     for (const MSEdge* e : myEdges->getEdges()) {
    1804      1759609 :         if (e->getBidiEdge() != nullptr) {
    1805              :             return true;
    1806              :         }
    1807              :     }
    1808              :     return false;
    1809              : }
    1810              : 
    1811              : bool
    1812          303 : MSNet::warnOnce(const std::string& typeAndID) {
    1813          303 :     if (myWarnedOnce.find(typeAndID) == myWarnedOnce.end()) {
    1814          303 :         myWarnedOnce[typeAndID] = true;
    1815          303 :         return true;
    1816              :     }
    1817              :     return false;
    1818              : }
    1819              : 
    1820              : 
    1821              : MSMapMatcher*
    1822           35 : MSNet::getMapMatcher() const {
    1823           35 :     auto loader = myRouteLoaders->getFirstLoader();
    1824           35 :     if (loader != nullptr) {
    1825           35 :         return dynamic_cast<MSMapMatcher*>(loader->getRouteHandler());
    1826              :     } else {
    1827              :         return nullptr;
    1828              :     }
    1829              : }
    1830              : 
    1831              : void
    1832            0 : MSNet::quickReload() {
    1833            0 :     const OptionsCont& oc = OptionsCont::getOptions();
    1834            0 :     clearState(string2time(oc.getString("begin")), true);
    1835            0 :     NLBuilder::initRandomness();
    1836              :     // load traffic from additional files
    1837            0 :     for (std::string file : oc.getStringVector("additional-files")) {
    1838              :         // ignore failure on parsing calibrator flow
    1839            0 :         MSRouteHandler rh(file, true);
    1840            0 :         const long before = PROGRESS_BEGIN_TIME_MESSAGE("Loading traffic from '" + file + "'");
    1841            0 :         if (!XMLSubSys::runParser(rh, file, false)) {
    1842            0 :             throw ProcessError(TLF("Loading of % failed.", file));
    1843              :         }
    1844            0 :         PROGRESS_TIME_MESSAGE(before);
    1845            0 :     }
    1846            0 :     delete myRouteLoaders;
    1847            0 :     myRouteLoaders = NLBuilder::buildRouteLoaderControl(OptionsCont::getOptions());
    1848            0 :     updateGUI();
    1849            0 : }
    1850              : 
    1851              : 
    1852              : SUMOTime
    1853          174 : MSNet::loadState(const std::string& fileName, const bool catchExceptions) {
    1854              :     // load time only
    1855          174 :     const SUMOTime newTime = MSStateHandler::MSStateTimeHandler::getTime(fileName);
    1856              :     // clean up state
    1857          164 :     clearState(newTime);
    1858              :     // load state
    1859          164 :     MSStateHandler h(fileName, 0);
    1860          164 :     XMLSubSys::runParser(h, fileName, false, false, false, catchExceptions);
    1861          160 :     if (MsgHandler::getErrorInstance()->wasInformed()) {
    1862            0 :         throw ProcessError(TLF("Loading state from '%' failed.", fileName));
    1863              :     }
    1864              :     // reset route loaders
    1865          160 :     delete myRouteLoaders;
    1866          160 :     myRouteLoaders = NLBuilder::buildRouteLoaderControl(OptionsCont::getOptions());
    1867              :     // prevent loading errors on rewound route file
    1868          160 :     MSGlobals::gStateLoaded = true;
    1869              : 
    1870          160 :     updateGUI();
    1871          160 :     return newTime;
    1872          164 : }
    1873              : 
    1874              : 
    1875              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1