Eclipse SUMO - Simulation of Urban MObility
MSNet.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
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
44 #endif
46 #include <utils/common/ToString.h>
47 #include <utils/common/SysUtils.h>
63 #include <utils/xml/XMLSubSys.h>
65 #include <libsumo/Helper.h>
66 #include <libsumo/Simulation.h>
67 #include <mesosim/MELoop.h>
68 #include <mesosim/MESegment.h>
103 #include <utils/router/FareModul.h>
104 #include <netload/NLBuilder.h>
105 
106 #include "MSEdgeControl.h"
107 #include "MSJunctionControl.h"
108 #include "MSInsertionControl.h"
109 #include "MSDynamicShapeUpdater.h"
110 #include "MSEventControl.h"
111 #include "MSEdge.h"
112 #include "MSJunction.h"
113 #include "MSJunctionLogic.h"
114 #include "MSLane.h"
115 #include "MSVehicleControl.h"
116 #include "MSVehicleTransfer.h"
117 #include "MSRoute.h"
118 #include "MSGlobals.h"
119 #include "MSEdgeWeightsStorage.h"
120 #include "MSStateHandler.h"
121 #include "MSFrame.h"
122 #include "MSParkingArea.h"
123 #include "MSStoppingPlace.h"
124 #include "MSNet.h"
125 
126 
127 // ===========================================================================
128 // debug constants
129 // ===========================================================================
130 //#define DEBUG_SIMSTEP
131 
132 
133 // ===========================================================================
134 // static member definitions
135 // ===========================================================================
136 MSNet* MSNet::myInstance = nullptr;
137 
138 const std::string MSNet::STAGE_EVENTS("events");
139 const std::string MSNet::STAGE_MOVEMENTS("move");
140 const std::string MSNet::STAGE_LANECHANGE("laneChange");
141 const std::string MSNet::STAGE_INSERTIONS("insertion");
142 const std::string MSNet::STAGE_REMOTECONTROL("remoteControl");
143 
145 
146 // ===========================================================================
147 // static member method definitions
148 // ===========================================================================
149 double
150 MSNet::getEffort(const MSEdge* const e, const SUMOVehicle* const v, double t) {
151  double value;
152  const MSVehicle* const veh = dynamic_cast<const MSVehicle* const>(v);
153  if (veh != nullptr && veh->getWeightsStorage().retrieveExistingEffort(e, t, value)) {
154  return value;
155  }
156  if (getInstance()->getWeightsStorage().retrieveExistingEffort(e, t, value)) {
157  return value;
158  }
159  return 0;
160 }
161 
162 
163 double
164 MSNet::getTravelTime(const MSEdge* const e, const SUMOVehicle* const v, double t) {
165  double value;
166  const MSVehicle* const veh = dynamic_cast<const MSVehicle* const>(v);
167  if (veh != nullptr && veh->getWeightsStorage().retrieveExistingTravelTime(e, t, value)) {
168  return value;
169  }
171  return value;
172  }
173  if (veh != nullptr && veh->getRoutingMode() == libsumo::ROUTING_MODE_AGGREGATED_CUSTOM) {
174  return MSRoutingEngine::getEffortExtra(e, v, t);
175  }
176  return e->getMinimumTravelTime(v);
177 }
178 
179 
180 // ---------------------------------------------------------------------------
181 // MSNet - methods
182 // ---------------------------------------------------------------------------
183 MSNet*
185  if (myInstance != nullptr) {
186  return myInstance;
187  }
188  throw ProcessError(TL("A network was not yet constructed."));
189 }
190 
191 void
193  if (!MSGlobals::gUseMesoSim) {
195  }
196 }
197 
198 void
200  if (!MSGlobals::gUseMesoSim) {
202  }
203 }
204 
205 
206 MSNet::MSNet(MSVehicleControl* vc, MSEventControl* beginOfTimestepEvents,
207  MSEventControl* endOfTimestepEvents,
208  MSEventControl* insertionEvents,
209  ShapeContainer* shapeCont):
210  myAmInterrupted(false),
211  myVehiclesMoved(0),
212  myPersonsMoved(0),
213  myHavePermissions(false),
214  myHasInternalLinks(false),
215  myJunctionHigherSpeeds(false),
216  myHasElevation(false),
217  myHasPedestrianNetwork(false),
218  myHasBidiEdges(false),
219  myEdgeDataEndTime(-1),
220  myDynamicShapeUpdater(nullptr) {
221  if (myInstance != nullptr) {
222  throw ProcessError(TL("A network was already constructed."));
223  }
225  myStep = string2time(oc.getString("begin"));
226  myMaxTeleports = oc.getInt("max-num-teleports");
227  myLogExecutionTime = !oc.getBool("no-duration-log");
228  myLogStepNumber = !oc.getBool("no-step-log");
229  myLogStepPeriod = oc.getInt("step-log.period");
230  myInserter = new MSInsertionControl(*vc, string2time(oc.getString("max-depart-delay")), oc.getBool("eager-insert"), oc.getInt("max-num-vehicles"),
231  string2time(oc.getString("random-depart-offset")));
232  myVehicleControl = vc;
234  myEdges = nullptr;
235  myJunctions = nullptr;
236  myRouteLoaders = nullptr;
237  myLogics = nullptr;
238  myPersonControl = nullptr;
239  myContainerControl = nullptr;
240  myEdgeWeights = nullptr;
241  myShapeContainer = shapeCont == nullptr ? new ShapeContainer() : shapeCont;
242 
243  myBeginOfTimestepEvents = beginOfTimestepEvents;
244  myEndOfTimestepEvents = endOfTimestepEvents;
245  myInsertionEvents = insertionEvents;
246  myLanesRTree.first = false;
247 
249  MSGlobals::gMesoNet = new MELoop(string2time(oc.getString("meso-recheck")));
250  }
251  myInstance = this;
252  initStatic();
253 }
254 
255 
256 void
258  SUMORouteLoaderControl* routeLoaders,
259  MSTLLogicControl* tlc,
260  std::vector<SUMOTime> stateDumpTimes,
261  std::vector<std::string> stateDumpFiles,
262  bool hasInternalLinks,
263  bool junctionHigherSpeeds,
264  const MMVersion& version) {
265  myEdges = edges;
266  myJunctions = junctions;
267  myRouteLoaders = routeLoaders;
268  myLogics = tlc;
269  // save the time the network state shall be saved at
270  myStateDumpTimes = stateDumpTimes;
271  myStateDumpFiles = stateDumpFiles;
272  myStateDumpPeriod = string2time(oc.getString("save-state.period"));
273  myStateDumpPrefix = oc.getString("save-state.prefix");
274  myStateDumpSuffix = oc.getString("save-state.suffix");
275 
276  // initialise performance computation
278  myTraCIMillis = 0;
280  myJunctionHigherSpeeds = junctionHigherSpeeds;
284  myVersion = version;
287  throw ProcessError(TL("Option weights.separate-turns is only supported when simulating with internal lanes"));
288  }
289 }
290 
291 
293  cleanupStatic();
294  // delete controls
295  delete myJunctions;
296  delete myDetectorControl;
297  // delete mean data
298  delete myEdges;
299  delete myInserter;
300  myInserter = nullptr;
301  delete myLogics;
302  delete myRouteLoaders;
303  if (myPersonControl != nullptr) {
304  delete myPersonControl;
305  myPersonControl = nullptr; // just to have that clear for later cleanups
306  }
307  if (myContainerControl != nullptr) {
308  delete myContainerControl;
309  myContainerControl = nullptr; // just to have that clear for later cleanups
310  }
311  delete myVehicleControl; // must happen after deleting transportables
312  // delete events late so that vehicles can get rid of references first
314  myBeginOfTimestepEvents = nullptr;
315  delete myEndOfTimestepEvents;
316  myEndOfTimestepEvents = nullptr;
317  delete myInsertionEvents;
318  myInsertionEvents = nullptr;
319  delete myShapeContainer;
320  delete myEdgeWeights;
321  for (auto& router : myRouterTT) {
322  delete router.second;
323  }
324  myRouterTT.clear();
325  for (auto& router : myRouterEffort) {
326  delete router.second;
327  }
328  myRouterEffort.clear();
329  for (auto& router : myPedestrianRouter) {
330  delete router.second;
331  }
332  myPedestrianRouter.clear();
333  for (auto& router : myIntermodalRouter) {
334  delete router.second;
335  }
336  myIntermodalRouter.clear();
337  myLanesRTree.second.RemoveAll();
338  clearAll();
340  delete MSGlobals::gMesoNet;
341  }
342  myInstance = nullptr;
343 }
344 
345 
346 void
347 MSNet::addRestriction(const std::string& id, const SUMOVehicleClass svc, const double speed) {
348  myRestrictions[id][svc] = speed;
349 }
350 
351 
352 const std::map<SUMOVehicleClass, double>*
353 MSNet::getRestrictions(const std::string& id) const {
354  std::map<std::string, std::map<SUMOVehicleClass, double> >::const_iterator i = myRestrictions.find(id);
355  if (i == myRestrictions.end()) {
356  return nullptr;
357  }
358  return &i->second;
359 }
360 
361 void
362 MSNet::addMesoType(const std::string& typeID, const MESegment::MesoEdgeType& edgeType) {
363  myMesoEdgeTypes[typeID] = edgeType;
364 }
365 
367 MSNet::getMesoType(const std::string& typeID) {
368  if (myMesoEdgeTypes.count(typeID) == 0) {
369  // init defaults
370  const OptionsCont& oc = OptionsCont::getOptions();
371  MESegment::MesoEdgeType edgeType;
372  edgeType.tauff = string2time(oc.getString("meso-tauff"));
373  edgeType.taufj = string2time(oc.getString("meso-taufj"));
374  edgeType.taujf = string2time(oc.getString("meso-taujf"));
375  edgeType.taujj = string2time(oc.getString("meso-taujj"));
376  edgeType.jamThreshold = oc.getFloat("meso-jam-threshold");
377  edgeType.junctionControl = oc.getBool("meso-junction-control");
378  edgeType.tlsPenalty = oc.getFloat("meso-tls-penalty");
379  edgeType.tlsFlowPenalty = oc.getFloat("meso-tls-flow-penalty");
380  edgeType.minorPenalty = string2time(oc.getString("meso-minor-penalty"));
381  edgeType.overtaking = oc.getBool("meso-overtaking");
382  myMesoEdgeTypes[typeID] = edgeType;
383  }
384  return myMesoEdgeTypes[typeID];
385 }
386 
387 
388 bool
389 MSNet::hasFlow(const std::string& id) const {
390  // inserter is deleted at the end of the simulation
391  return myInserter != nullptr && myInserter->hasFlow(id);
392 }
393 
394 
397  // report the begin when wished
398  WRITE_MESSAGEF(TL("Simulation version % started with time: %."), VERSION_STRING, time2string(start));
399  // the simulation loop
401  // state loading may have changed the start time so we need to reinit it
402  myStep = start;
403  int numSteps = 0;
404  bool doStepLog = false;
405  while (state == SIMSTATE_RUNNING) {
406  doStepLog = myLogStepNumber && (numSteps % myLogStepPeriod == 0);
407  if (doStepLog) {
409  }
410  simulationStep();
411  if (doStepLog) {
413  }
414  state = adaptToState(simulationState(stop));
415 #ifdef DEBUG_SIMSTEP
416  std::cout << SIMTIME << " MSNet::simulate(" << start << ", " << stop << ")"
417  << "\n simulation state: " << getStateMessage(state)
418  << std::endl;
419 #endif
420  numSteps++;
421  }
422  if (myLogStepNumber && !doStepLog) {
423  // ensure some output on the last step
426  }
427  // exit simulation loop
428  if (myLogStepNumber) {
429  // start new line for final verbose output
430  std::cout << "\n";
431  }
432  closeSimulation(start, getStateMessage(state));
433  return state;
434 }
435 
436 
437 void
440 }
441 
442 
443 const std::string
444 MSNet::generateStatistics(const SUMOTime start, const long now) {
445  std::ostringstream msg;
446  if (myLogExecutionTime) {
447  const long duration = now - mySimBeginMillis;
448  // print performance notice
449  msg << "Performance:\n" << " Duration: " << elapsedMs2string(duration) << "\n";
450  if (duration != 0) {
451  if (TraCIServer::getInstance() != nullptr) {
452  msg << " TraCI-Duration: " << elapsedMs2string(myTraCIMillis) << "\n";
453  }
454  msg << " Real time factor: " << (STEPS2TIME(myStep - start) * 1000. / (double)duration) << "\n";
455  msg.setf(std::ios::fixed, std::ios::floatfield); // use decimal format
456  msg.setf(std::ios::showpoint); // print decimal point
457  msg << " UPS: " << ((double)myVehiclesMoved / ((double)duration / 1000)) << "\n";
458  if (myPersonsMoved > 0) {
459  msg << " UPS-Persons: " << ((double)myPersonsMoved / ((double)duration / 1000)) << "\n";
460  }
461  }
462  // print vehicle statistics
463  const std::string discardNotice = ((myVehicleControl->getLoadedVehicleNo() != myVehicleControl->getDepartedVehicleNo()) ?
464  " (Loaded: " + toString(myVehicleControl->getLoadedVehicleNo()) + ")" : "");
465  msg << "Vehicles:\n"
466  << " Inserted: " << myVehicleControl->getDepartedVehicleNo() << discardNotice << "\n"
467  << " Running: " << myVehicleControl->getRunningVehicleNo() << "\n"
468  << " Waiting: " << myInserter->getWaitingVehicleNo() << "\n";
469 
471  // print optional teleport statistics
472  std::vector<std::string> reasons;
473  if (myVehicleControl->getCollisionCount() > 0) {
474  reasons.push_back("Collisions: " + toString(myVehicleControl->getCollisionCount()));
475  }
476  if (myVehicleControl->getTeleportsJam() > 0) {
477  reasons.push_back("Jam: " + toString(myVehicleControl->getTeleportsJam()));
478  }
479  if (myVehicleControl->getTeleportsYield() > 0) {
480  reasons.push_back("Yield: " + toString(myVehicleControl->getTeleportsYield()));
481  }
483  reasons.push_back("Wrong Lane: " + toString(myVehicleControl->getTeleportsWrongLane()));
484  }
485  msg << " Teleports: " << myVehicleControl->getTeleportCount() << " (" << joinToString(reasons, ", ") << ")\n";
486  }
487  if (myVehicleControl->getEmergencyStops() > 0) {
488  msg << " Emergency Stops: " << myVehicleControl->getEmergencyStops() << "\n";
489  }
491  msg << " Emergency Braking: " << myVehicleControl->getEmergencyBrakingCount() << "\n";
492  }
493  if (myPersonControl != nullptr && myPersonControl->getLoadedNumber() > 0) {
494  msg << "Persons:\n"
495  << " Inserted: " << myPersonControl->getLoadedNumber() << "\n"
496  << " Running: " << myPersonControl->getRunningNumber() << "\n";
497  if (myPersonControl->getJammedNumber() > 0) {
498  msg << " Jammed: " << myPersonControl->getJammedNumber() << "\n";
499  }
500  if (myPersonControl->getTeleportCount() > 0) {
501  std::vector<std::string> reasons;
503  reasons.push_back("Abort Wait: " + toString(myPersonControl->getTeleportsAbortWait()));
504  }
506  reasons.push_back("Wrong Dest: " + toString(myPersonControl->getTeleportsWrongDest()));
507  }
508  msg << " Teleports: " << myPersonControl->getTeleportCount() << " (" << joinToString(reasons, ", ") << ")\n";
509  }
510  }
511  if (myContainerControl != nullptr && myContainerControl->getLoadedNumber() > 0) {
512  msg << "Containers:\n"
513  << " Inserted: " << myContainerControl->getLoadedNumber() << "\n"
514  << " Running: " << myContainerControl->getRunningNumber() << "\n";
515  if (myContainerControl->getJammedNumber() > 0) {
516  msg << " Jammed: " << myContainerControl->getJammedNumber() << "\n";
517  }
519  std::vector<std::string> reasons;
521  reasons.push_back("Abort Wait: " + toString(myContainerControl->getTeleportsAbortWait()));
522  }
524  reasons.push_back("Wrong Dest: " + toString(myContainerControl->getTeleportsWrongDest()));
525  }
526  msg << " Teleports: " << myContainerControl->getTeleportCount() << " (" << joinToString(reasons, ", ") << ")\n";
527  }
528  }
529  }
530  if (OptionsCont::getOptions().getBool("duration-log.statistics")) {
532  }
533  std::string result = msg.str();
534  result.erase(result.end() - 1);
535  return result;
536 }
537 
538 
539 void
541  OutputDevice& od = OutputDevice::getDeviceByOption("collision-output");
542  for (const auto& item : myCollisions) {
543  for (const auto& c : item.second) {
544  od.openTag("collision");
546  od.writeAttr("type", c.type);
547  od.writeAttr("lane", c.lane->getID());
548  od.writeAttr("pos", c.pos);
549  od.writeAttr("collider", item.first);
550  od.writeAttr("victim", c.victim);
551  od.writeAttr("colliderType", c.colliderType);
552  od.writeAttr("victimType", c.victimType);
553  od.writeAttr("colliderSpeed", c.colliderSpeed);
554  od.writeAttr("victimSpeed", c.victimSpeed);
555  od.closeTag();
556  }
557  }
558 }
559 
560 
561 void
562 MSNet::writeStatistics(const SUMOTime start, const long now) const {
563  const long duration = now - mySimBeginMillis;
564  OutputDevice& od = OutputDevice::getDeviceByOption("statistic-output");
565  od.openTag("performance");
566  od.writeAttr("clockBegin", time2string(mySimBeginMillis));
567  od.writeAttr("clockEnd", time2string(now));
568  od.writeAttr("clockDuration", time2string(duration));
569  od.writeAttr("traciDuration", time2string(myTraCIMillis));
570  od.writeAttr("realTimeFactor", duration != 0 ? (double)(myStep - start) / (double)duration : -1);
571  od.writeAttr("vehicleUpdatesPerSecond", duration != 0 ? (double)myVehiclesMoved / ((double)duration / 1000) : -1);
572  od.writeAttr("personUpdatesPerSecond", duration != 0 ? (double)myPersonsMoved / ((double)duration / 1000) : -1);
573  od.writeAttr("begin", time2string(start));
574  od.writeAttr("end", time2string(myStep));
575  od.writeAttr("duration", time2string(myStep - start));
576  od.closeTag();
577  od.openTag("vehicles");
581  od.writeAttr("waiting", myInserter->getWaitingVehicleNo());
582  od.closeTag();
583  od.openTag("teleports");
588  od.closeTag();
589  od.openTag("safety");
590  od.writeAttr("collisions", myVehicleControl->getCollisionCount());
591  od.writeAttr("emergencyStops", myVehicleControl->getEmergencyStops());
592  od.writeAttr("emergencyBraking", myVehicleControl->getEmergencyBrakingCount());
593  od.closeTag();
594  od.openTag("persons");
595  od.writeAttr("loaded", myPersonControl != nullptr ? myPersonControl->getLoadedNumber() : 0);
596  od.writeAttr("running", myPersonControl != nullptr ? myPersonControl->getRunningNumber() : 0);
597  od.writeAttr("jammed", myPersonControl != nullptr ? myPersonControl->getJammedNumber() : 0);
598  od.closeTag();
599  od.openTag("personTeleports");
600  od.writeAttr("total", myPersonControl != nullptr ? myPersonControl->getTeleportCount() : 0);
601  od.writeAttr("abortWait", myPersonControl != nullptr ? myPersonControl->getTeleportsAbortWait() : 0);
602  od.writeAttr("wrongDest", myPersonControl != nullptr ? myPersonControl->getTeleportsWrongDest() : 0);
603  od.closeTag();
604  if (OptionsCont::getOptions().isSet("tripinfo-output") || OptionsCont::getOptions().getBool("duration-log.statistics")) {
606  }
607 
608 }
609 
610 
611 void
613  // summary output
614  const OptionsCont& oc = OptionsCont::getOptions();
615  const bool hasOutput = oc.isSet("summary-output");
616  const bool hasPersonOutput = oc.isSet("person-summary-output");
617  if (hasOutput || hasPersonOutput) {
618  const SUMOTime period = string2time(oc.getString("summary-output.period"));
619  const SUMOTime begin = string2time(oc.getString("begin"));
620  if (period > 0 && (myStep - begin) % period != 0) {
621  return;
622  }
623  }
624  if (hasOutput) {
625  OutputDevice& od = OutputDevice::getDeviceByOption("summary-output");
626  int departedVehiclesNumber = myVehicleControl->getDepartedVehicleNo();
627  const double meanWaitingTime = departedVehiclesNumber != 0 ? myVehicleControl->getTotalDepartureDelay() / (double) departedVehiclesNumber : -1.;
628  int endedVehicleNumber = myVehicleControl->getEndedVehicleNo();
629  const double meanTravelTime = endedVehicleNumber != 0 ? myVehicleControl->getTotalTravelTime() / (double) endedVehicleNumber : -1.;
630  od.openTag("step");
631  od.writeAttr("time", time2string(myStep));
635  od.writeAttr("waiting", myInserter->getWaitingVehicleNo());
638  od.writeAttr("collisions", myVehicleControl->getCollisionCount());
639  od.writeAttr("teleports", myVehicleControl->getTeleportCount());
642  od.writeAttr("meanWaitingTime", meanWaitingTime);
643  od.writeAttr("meanTravelTime", meanTravelTime);
644  std::pair<double, double> meanSpeed = myVehicleControl->getVehicleMeanSpeeds();
645  od.writeAttr("meanSpeed", meanSpeed.first);
646  od.writeAttr("meanSpeedRelative", meanSpeed.second);
647  if (myLogExecutionTime) {
648  od.writeAttr("duration", mySimStepDuration);
649  }
650  od.closeTag();
651  }
652  if (hasPersonOutput) {
653  OutputDevice& od = OutputDevice::getDeviceByOption("person-summary-output");
655  od.openTag("step");
656  od.writeAttr("time", time2string(myStep));
657  od.writeAttr("loaded", pc.getLoadedNumber());
658  od.writeAttr("inserted", pc.getDepartedNumber());
659  od.writeAttr("walking", pc.getMovingNumber());
660  od.writeAttr("waitingForRide", pc.getWaitingForVehicleNumber());
661  od.writeAttr("riding", pc.getRidingNumber());
662  od.writeAttr("stopping", pc.getWaitingUntilNumber());
663  od.writeAttr("jammed", pc.getJammedNumber());
664  od.writeAttr("ended", pc.getEndedNumber());
665  od.writeAttr("arrived", pc.getArrivedNumber());
666  od.writeAttr("teleports", pc.getTeleportCount());
667  if (myLogExecutionTime) {
668  od.writeAttr("duration", mySimStepDuration);
669  }
670  od.closeTag();
671  }
672 }
673 
674 
675 void
676 MSNet::closeSimulation(SUMOTime start, const std::string& reason) {
677  // report the end when wished
678  WRITE_MESSAGE(TLF("Simulation ended at time: %.", time2string(getCurrentTimeStep())));
679  if (reason != "") {
680  WRITE_MESSAGE(TL("Reason: ") + reason);
681  }
683  if (MSStopOut::active() && OptionsCont::getOptions().getBool("stop-output.write-unfinished")) {
685  }
686  MSDevice_Vehroutes::writePendingOutput(OptionsCont::getOptions().getBool("vehroute-output.write-unfinished"));
687  if (OptionsCont::getOptions().getBool("tripinfo-output.write-unfinished")) {
689  }
690  if (OptionsCont::getOptions().isSet("chargingstations-output") && !OptionsCont::getOptions().getBool("chargingstations-output.aggregated")) {
692  }
693  if (OptionsCont::getOptions().isSet("overheadwiresegments-output")) {
695  }
696  if (OptionsCont::getOptions().isSet("substations-output")) {
698  }
699  if (OptionsCont::getOptions().isSet("railsignal-block-output")) {
701  }
702  const long now = SysUtils::getCurrentMillis();
703  if (myLogExecutionTime || OptionsCont::getOptions().getBool("duration-log.statistics")) {
704  WRITE_MESSAGE(generateStatistics(start, now));
705  }
706  if (OptionsCont::getOptions().isSet("statistic-output")) {
707  writeStatistics(start, now);
708  }
709 }
710 
711 
712 void
713 MSNet::simulationStep(const bool onlyMove) {
715  postMoveStep();
716  myStepCompletionMissing = false;
717  return;
718  }
719 #ifdef DEBUG_SIMSTEP
720  std::cout << SIMTIME << ": MSNet::simulationStep() called"
721  << ", myStep = " << myStep
722  << std::endl;
723 #endif
725  int lastTraCICmd = 0;
726  if (t != nullptr) {
727  if (myLogExecutionTime) {
729  }
730  lastTraCICmd = t->processCommands(myStep);
731 #ifdef DEBUG_SIMSTEP
732  bool loadRequested = !TraCI::getLoadArgs().empty();
733  assert(t->getTargetTime() >= myStep || loadRequested || TraCIServer::wasClosed());
734 #endif
735  if (myLogExecutionTime) {
737  }
738  if (TraCIServer::wasClosed() || !t->getLoadArgs().empty()) {
739  return;
740  }
741  }
742 #ifdef DEBUG_SIMSTEP
743  std::cout << SIMTIME << ": TraCI target time: " << t->getTargetTime() << std::endl;
744 #endif
745  // execute beginOfTimestepEvents
746  if (myLogExecutionTime) {
748  }
749  // simulation state output
750  std::vector<SUMOTime>::iterator timeIt = std::find(myStateDumpTimes.begin(), myStateDumpTimes.end(), myStep);
751  if (timeIt != myStateDumpTimes.end()) {
752  const int dist = (int)distance(myStateDumpTimes.begin(), timeIt);
754  }
755  if (myStateDumpPeriod > 0 && myStep % myStateDumpPeriod == 0) {
756  std::string timeStamp = time2string(myStep);
757  std::replace(timeStamp.begin(), timeStamp.end(), ':', '-');
758  const std::string filename = myStateDumpPrefix + "_" + timeStamp + myStateDumpSuffix;
760  myPeriodicStateFiles.push_back(filename);
761  int keep = OptionsCont::getOptions().getInt("save-state.period.keep");
762  if (keep > 0 && (int)myPeriodicStateFiles.size() > keep) {
763  std::remove(myPeriodicStateFiles.front().c_str());
765  }
766  }
770  }
771 #ifdef HAVE_FOX
772  MSRoutingEngine::waitForAll();
773 #endif
776  }
777  // check whether the tls programs need to be switched
779 
782  } else {
783  // assure all lanes with vehicles are 'active'
785 
786  // compute safe velocities for all vehicles for the next few lanes
787  // also register ApproachingVehicleInformation for all links
789 
790  // register junction approaches based on planned velocities as basis for right-of-way decision
792 
793  // decide right-of-way and execute movements
797  }
798 
799  // vehicles may change lanes
801 
804  }
805  }
806  // flush arrived meso vehicles and micro vehicles that were removed due to collision
808  loadRoutes();
809 
810  // persons
811  if (myPersonControl != nullptr && myPersonControl->hasTransportables()) {
813  }
814  // containers
817  }
818  // insert vehicles
821 #ifdef HAVE_FOX
822  MSRoutingEngine::waitForAll();
823 #endif
826  //myEdges->patchActiveLanes(); // @note required to detect collisions on lanes that were empty before insertion. wasteful?
828  }
830 
831  // execute endOfTimestepEvents
833 
834  if (myLogExecutionTime) {
836  }
837  if (onlyMove) {
839  return;
840  }
841  if (t != nullptr && lastTraCICmd == libsumo::CMD_EXECUTEMOVE) {
842  t->processCommands(myStep, true);
843  }
844  postMoveStep();
845 }
846 
847 
848 void
850  const int numControlled = libsumo::Helper::postProcessRemoteControl();
851  if (numControlled > 0 && MSGlobals::gCheck4Accidents) {
853  }
854  if (myLogExecutionTime) {
857  }
859  // collisions from the previous step were kept to avoid duplicate
860  // warnings. we must remove them now to ensure correct output.
862  }
863  // update and write (if needed) detector values
865  writeOutput();
866 
867  if (myLogExecutionTime) {
869  if (myPersonControl != nullptr) {
871  }
872  }
873  myStep += DELTA_T;
874 }
875 
876 
879  if (TraCIServer::wasClosed()) {
881  }
882  if (TraCIServer::getInstance() != nullptr && !TraCIServer::getInstance()->getLoadArgs().empty()) {
883  return SIMSTATE_LOADING;
884  }
885  if ((stopTime < 0 || myStep > stopTime) && TraCIServer::getInstance() == nullptr && (stopTime > 0 || myStep > myEdgeDataEndTime)) {
887  && (myInserter->getPendingFlowCount() == 0)
888  && (myPersonControl == nullptr || !myPersonControl->hasNonWaiting())
892  }
893  }
894  if (stopTime >= 0 && myStep >= stopTime) {
896  }
899  }
900  if (myAmInterrupted) {
901  return SIMSTATE_INTERRUPTED;
902  }
903  return SIMSTATE_RUNNING;
904 }
905 
906 
908 MSNet::adaptToState(MSNet::SimulationState state, const bool isLibsumo) const {
909  if (state == SIMSTATE_LOADING) {
912  } else if (state != SIMSTATE_RUNNING && ((TraCIServer::getInstance() != nullptr && !TraCIServer::wasClosed()) || isLibsumo)) {
913  // overrides SIMSTATE_END_STEP_REACHED, e.g. (TraCI / Libsumo ignore SUMO's --end option)
914  return SIMSTATE_RUNNING;
915  } else if (state == SIMSTATE_NO_FURTHER_VEHICLES) {
916  if (myPersonControl != nullptr) {
918  }
919  if (myContainerControl != nullptr) {
921  }
923  }
924  return state;
925 }
926 
927 
928 std::string
930  switch (state) {
932  return "";
934  return TL("The final simulation step has been reached.");
936  return TL("All vehicles have left the simulation.");
938  return TL("TraCI requested termination.");
940  return TL("An error occurred (see log).");
942  return TL("Interrupted.");
944  return TL("Too many teleports.");
946  return TL("TraCI issued load command.");
947  default:
948  return TL("Unknown reason.");
949  }
950 }
951 
952 
953 void
955  // clear container
956  MSEdge::clear();
957  MSLane::clear();
958  MSRoute::clear();
962  while (!MSLaneSpeedTrigger::getInstances().empty()) {
963  delete MSLaneSpeedTrigger::getInstances().begin()->second;
964  }
965  while (!MSTriggeredRerouter::getInstances().empty()) {
966  delete MSTriggeredRerouter::getInstances().begin()->second;
967  }
975  if (t != nullptr) {
976  t->cleanup();
977  }
980 }
981 
982 
983 void
984 MSNet::clearState(const SUMOTime step, bool quickReload) {
985  MSGlobals::gClearState = true;
988  for (MSEdge* const edge : MSEdge::getAllEdges()) {
989  for (MESegment* s = MSGlobals::gMesoNet->getSegmentForEdge(*edge); s != nullptr; s = s->getNextSegment()) {
990  s->clearState();
991  }
992  }
993  } else {
994  for (MSEdge* const edge : MSEdge::getAllEdges()) {
995  for (MSLane* const lane : edge->getLanes()) {
996  lane->getVehiclesSecure();
997  lane->clearState();
998  lane->releaseVehicles();
999  }
1000  edge->clearState();
1001  }
1002  }
1004  // detectors may still reference persons/vehicles
1008 
1009  if (myPersonControl != nullptr) {
1011  }
1012  if (myContainerControl != nullptr) {
1014  }
1015  // delete vtypes after transportables have removed their types
1019  // delete all routes after vehicles and detector output is done
1021  for (auto& item : myStoppingPlaces) {
1022  for (auto& item2 : item.second) {
1023  item2.second->clearState();
1024  }
1025  }
1031  myStep = step;
1032  MSGlobals::gClearState = false;
1033 }
1034 
1035 
1036 void
1038  // update detector values
1040  const OptionsCont& oc = OptionsCont::getOptions();
1041 
1042  // check state dumps
1043  if (oc.isSet("netstate-dump")) {
1045  oc.getInt("netstate-dump.precision"));
1046  }
1047 
1048  // check fcd dumps
1049  if (OptionsCont::getOptions().isSet("fcd-output")) {
1051  }
1052 
1053  // check emission dumps
1054  if (OptionsCont::getOptions().isSet("emission-output")) {
1056  oc.getInt("emission-output.precision"));
1057  }
1058 
1059  // battery dumps
1060  if (OptionsCont::getOptions().isSet("battery-output")) {
1062  oc.getInt("battery-output.precision"));
1063  }
1064 
1065  // charging station aggregated dumps
1066  if (OptionsCont::getOptions().isSet("chargingstations-output") && OptionsCont::getOptions().getBool("chargingstations-output.aggregated")) {
1068  }
1069 
1070  // elecHybrid dumps
1071  if (OptionsCont::getOptions().isSet("elechybrid-output")) {
1072  std::string output = OptionsCont::getOptions().getString("elechybrid-output");
1073 
1074  if (oc.getBool("elechybrid-output.aggregated")) {
1075  // build a xml file with aggregated device.elechybrid output
1077  oc.getInt("elechybrid-output.precision"));
1078  } else {
1079  // build a separate xml file for each vehicle equipped with device.elechybrid
1080  // RICE_TODO: Does this have to be placed here in MSNet.cpp ?
1082  for (MSVehicleControl::constVehIt it = vc.loadedVehBegin(); it != vc.loadedVehEnd(); ++it) {
1083  const SUMOVehicle* veh = it->second;
1084  if (!veh->isOnRoad()) {
1085  continue;
1086  }
1087  if (static_cast<MSDevice_ElecHybrid*>(veh->getDevice(typeid(MSDevice_ElecHybrid))) != nullptr) {
1088  std::string vehID = veh->getID();
1089  std::string filename2 = output + "_" + vehID + ".xml";
1090  OutputDevice& dev = OutputDevice::getDevice(filename2);
1091  std::map<SumoXMLAttr, std::string> attrs;
1092  attrs[SUMO_ATTR_VEHICLE] = vehID;
1095  dev.writeXMLHeader("elecHybrid-export", "", attrs);
1096  MSElecHybridExport::write(OutputDevice::getDevice(filename2), veh, myStep, oc.getInt("elechybrid-output.precision"));
1097  }
1098  }
1099  }
1100  }
1101 
1102 
1103  // check full dumps
1104  if (OptionsCont::getOptions().isSet("full-output")) {
1107  }
1108 
1109  // check queue dumps
1110  if (OptionsCont::getOptions().isSet("queue-output")) {
1112  }
1113 
1114  // check amitran dumps
1115  if (OptionsCont::getOptions().isSet("amitran-output")) {
1117  }
1118 
1119  // check vtk dumps
1120  if (OptionsCont::getOptions().isSet("vtk-output")) {
1121 
1122  if (MSNet::getInstance()->getVehicleControl().getRunningVehicleNo() > 0) {
1123  std::string timestep = time2string(myStep);
1124  timestep = timestep.substr(0, timestep.length() - 3);
1125  std::string output = OptionsCont::getOptions().getString("vtk-output");
1126  std::string filename = output + "_" + timestep + ".vtp";
1127 
1128  OutputDevice_File dev(filename, false);
1129 
1130  //build a huge mass of xml files
1131  MSVTKExport::write(dev, myStep);
1132 
1133  }
1134 
1135  }
1136 
1138 
1139  // write detector values
1141 
1142  // write link states
1143  if (OptionsCont::getOptions().isSet("link-output")) {
1144  OutputDevice& od = OutputDevice::getDeviceByOption("link-output");
1145  od.openTag("timestep");
1147  for (const MSEdge* const edge : myEdges->getEdges()) {
1148  for (const MSLane* const lane : edge->getLanes()) {
1149  for (const MSLink* const link : lane->getLinkCont()) {
1150  link->writeApproaching(od, lane->getID());
1151  }
1152  }
1153  }
1154  od.closeTag();
1155  }
1156 
1157  // write SSM output
1158  for (MSDevice_SSM* dev : MSDevice_SSM::getInstances()) {
1159  dev->updateAndWriteOutput();
1160  }
1161 
1162  // write ToC output
1163  for (MSDevice_ToC* dev : MSDevice_ToC::getInstances()) {
1164  if (dev->generatesOutput()) {
1165  dev->writeOutput();
1166  }
1167  }
1168 
1169  if (OptionsCont::getOptions().isSet("collision-output")) {
1170  writeCollisions();
1171  }
1172 }
1173 
1174 
1175 bool
1177  return myLogExecutionTime;
1178 }
1179 
1180 
1183  if (myPersonControl == nullptr) {
1185  }
1186  return *myPersonControl;
1187 }
1188 
1189 
1192  if (myContainerControl == nullptr) {
1194  }
1195  return *myContainerControl;
1196 }
1197 
1200  myDynamicShapeUpdater = std::unique_ptr<MSDynamicShapeUpdater> (new MSDynamicShapeUpdater(*myShapeContainer));
1201  return myDynamicShapeUpdater.get();
1202 }
1203 
1206  if (myEdgeWeights == nullptr) {
1208  }
1209  return *myEdgeWeights;
1210 }
1211 
1212 
1213 void
1215  std::cout << "Step #" << time2string(myStep);
1216 }
1217 
1218 
1219 void
1221  if (myLogExecutionTime) {
1222  std::ostringstream oss;
1223  oss.setf(std::ios::fixed, std::ios::floatfield); // use decimal format
1224  oss.setf(std::ios::showpoint); // print decimal point
1225  oss << std::setprecision(gPrecision);
1226  if (mySimStepDuration != 0) {
1227  const double durationSec = (double)mySimStepDuration / 1000.;
1228  oss << " (" << mySimStepDuration << "ms ~= "
1229  << (TS / durationSec) << "*RT, ~"
1230  << ((double) myVehicleControl->getRunningVehicleNo() / durationSec);
1231  } else {
1232  oss << " (0ms ?*RT. ?";
1233  }
1234  oss << "UPS, ";
1235  if (TraCIServer::getInstance() != nullptr) {
1236  oss << "TraCI: " << myTraCIStepDuration << "ms, ";
1237  }
1238  oss << "vehicles TOT " << myVehicleControl->getDepartedVehicleNo()
1239  << " ACT " << myVehicleControl->getRunningVehicleNo()
1240  << " BUF " << myInserter->getWaitingVehicleNo()
1241  << ") ";
1242  std::string prev = "Step #" + time2string(myStep - DELTA_T);
1243  std::cout << oss.str().substr(0, 90 - prev.length());
1244  }
1245  std::cout << '\r';
1246 }
1247 
1248 
1249 void
1251  if (find(myVehicleStateListeners.begin(), myVehicleStateListeners.end(), listener) == myVehicleStateListeners.end()) {
1252  myVehicleStateListeners.push_back(listener);
1253  }
1254 }
1255 
1256 
1257 void
1259  std::vector<VehicleStateListener*>::iterator i = std::find(myVehicleStateListeners.begin(), myVehicleStateListeners.end(), listener);
1260  if (i != myVehicleStateListeners.end()) {
1261  myVehicleStateListeners.erase(i);
1262  }
1263 }
1264 
1265 
1266 void
1267 MSNet::informVehicleStateListener(const SUMOVehicle* const vehicle, VehicleState to, const std::string& info) {
1268 #ifdef HAVE_FOX
1269  ScopedLocker<> lock(myVehicleStateListenerMutex, MSGlobals::gNumThreads > 1);
1270 #endif
1271  for (VehicleStateListener* const listener : myVehicleStateListeners) {
1272  listener->vehicleStateChanged(vehicle, to, info);
1273  }
1274 }
1275 
1276 
1277 void
1280  myTransportableStateListeners.push_back(listener);
1281  }
1282 }
1283 
1284 
1285 void
1287  std::vector<TransportableStateListener*>::iterator i = std::find(myTransportableStateListeners.begin(), myTransportableStateListeners.end(), listener);
1288  if (i != myTransportableStateListeners.end()) {
1290  }
1291 }
1292 
1293 
1294 void
1295 MSNet::informTransportableStateListener(const MSTransportable* const transportable, TransportableState to, const std::string& info) {
1296 #ifdef HAVE_FOX
1297  ScopedLocker<> lock(myTransportableStateListenerMutex, MSGlobals::gNumThreads > 1);
1298 #endif
1300  listener->transportableStateChanged(transportable, to, info);
1301  }
1302 }
1303 
1304 
1305 bool
1306 MSNet::registerCollision(const SUMOTrafficObject* collider, const SUMOTrafficObject* victim, const std::string& collisionType, const MSLane* lane, double pos) {
1307  auto it = myCollisions.find(collider->getID());
1308  if (it != myCollisions.end()) {
1309  for (Collision& old : it->second) {
1310  if (old.victim == victim->getID()) {
1311  // collision from previous step continues
1312  old.colliderSpeed = collider->getSpeed();
1313  old.victimSpeed = victim->getSpeed();
1314  old.type = collisionType;
1315  old.lane = lane;
1316  old.pos = pos;
1317  old.time = myStep;
1318  return false;
1319  }
1320  }
1321  }
1322  Collision c;
1323  c.victim = victim->getID();
1324  c.colliderType = collider->getVehicleType().getID();
1325  c.victimType = victim->getVehicleType().getID();
1326  c.colliderSpeed = collider->getSpeed();
1327  c.victimSpeed = victim->getSpeed();
1328  c.type = collisionType;
1329  c.lane = lane;
1330  c.pos = pos;
1331  c.time = myStep;
1332  myCollisions[collider->getID()].push_back(c);
1333  return true;
1334 }
1335 
1336 
1337 void
1339  for (auto it = myCollisions.begin(); it != myCollisions.end();) {
1340  for (auto it2 = it->second.begin(); it2 != it->second.end();) {
1341  if (it2->time != myStep) {
1342  it2 = it->second.erase(it2);
1343  } else {
1344  it2++;
1345  }
1346  }
1347  if (it->second.size() == 0) {
1348  it = myCollisions.erase(it);
1349  } else {
1350  it++;
1351  }
1352  }
1353 }
1354 
1355 
1356 bool
1358  return myStoppingPlaces[category == SUMO_TAG_TRAIN_STOP ? SUMO_TAG_BUS_STOP : category].add(stop->getID(), stop);
1359 }
1360 
1361 
1362 bool
1364  if (find(myTractionSubstations.begin(), myTractionSubstations.end(), substation) == myTractionSubstations.end()) {
1365  myTractionSubstations.push_back(substation);
1366  return true;
1367  }
1368  return false;
1369 }
1370 
1371 
1373 MSNet::getStoppingPlace(const std::string& id, const SumoXMLTag category) const {
1374  if (myStoppingPlaces.count(category) > 0) {
1375  return myStoppingPlaces.find(category)->second.get(id);
1376  }
1377  return nullptr;
1378 }
1379 
1380 
1382 MSNet::getStoppingPlace(const std::string& id) const {
1384  MSStoppingPlace* result = getStoppingPlace(id, category);
1385  if (result != nullptr) {
1386  return result;
1387  }
1388  }
1389  return nullptr;
1390 }
1391 
1392 
1393 std::string
1394 MSNet::getStoppingPlaceID(const MSLane* lane, const double pos, const SumoXMLTag category) const {
1395  if (myStoppingPlaces.count(category) > 0) {
1396  for (const auto& it : myStoppingPlaces.find(category)->second) {
1397  MSStoppingPlace* stop = it.second;
1398  if (&stop->getLane() == lane && stop->getBeginLanePosition() - POSITION_EPS <= pos && stop->getEndLanePosition() + POSITION_EPS >= pos) {
1399  return stop->getID();
1400  }
1401  }
1402  }
1403  return "";
1404 }
1405 
1406 
1409  auto it = myStoppingPlaces.find(category);
1410  if (it != myStoppingPlaces.end()) {
1411  return it->second;
1412  } else {
1413  return myEmptyStoppingPlaceCont;
1414  }
1415 }
1416 
1417 
1418 void
1421  OutputDevice& output = OutputDevice::getDeviceByOption("chargingstations-output");
1422  for (const auto& it : myStoppingPlaces.find(SUMO_TAG_CHARGING_STATION)->second) {
1423  static_cast<MSChargingStation*>(it.second)->writeChargingStationOutput(output);
1424  }
1425  }
1426 }
1427 
1428 
1429 void
1431  OutputDevice& output = OutputDevice::getDeviceByOption("railsignal-block-output");
1432  for (auto tls : myLogics->getAllLogics()) {
1433  MSRailSignal* rs = dynamic_cast<MSRailSignal*>(tls);
1434  if (rs != nullptr) {
1435  rs->writeBlocks(output);
1436  }
1437  }
1438 }
1439 
1440 
1441 void
1444  OutputDevice& output = OutputDevice::getDeviceByOption("overheadwiresegments-output");
1445  for (const auto& it : myStoppingPlaces.find(SUMO_TAG_OVERHEAD_WIRE_SEGMENT)->second) {
1446  static_cast<MSOverheadWire*>(it.second)->writeOverheadWireSegmentOutput(output);
1447  }
1448  }
1449 }
1450 
1451 
1452 void
1454  if (myTractionSubstations.size() > 0) {
1455  OutputDevice& output = OutputDevice::getDeviceByOption("substations-output");
1456  output.setPrecision(OptionsCont::getOptions().getInt("substations-output.precision"));
1457  for (auto& it : myTractionSubstations) {
1458  it->writeTractionSubstationOutput(output);
1459  }
1460  }
1461 }
1462 
1463 
1465 MSNet::findTractionSubstation(const std::string& substationId) {
1466  for (std::vector<MSTractionSubstation*>::iterator it = myTractionSubstations.begin(); it != myTractionSubstations.end(); ++it) {
1467  if ((*it)->getID() == substationId) {
1468  return *it;
1469  }
1470  }
1471  return nullptr;
1472 }
1473 
1474 
1475 bool
1476 MSNet::existTractionSubstation(const std::string& substationId) {
1477  for (std::vector<MSTractionSubstation*>::iterator it = myTractionSubstations.begin(); it != myTractionSubstations.end(); ++it) {
1478  if ((*it)->getID() == substationId) {
1479  return true;
1480  }
1481  }
1482  return false;
1483 }
1484 
1485 
1487 MSNet::getRouterTT(const int rngIndex, const MSEdgeVector& prohibited) const {
1488  if (myRouterTT.count(rngIndex) == 0) {
1489  const std::string routingAlgorithm = OptionsCont::getOptions().getString("routing-algorithm");
1490  if (routingAlgorithm == "dijkstra") {
1491  myRouterTT[rngIndex] = new DijkstraRouter<MSEdge, SUMOVehicle>(MSEdge::getAllEdges(), true, &MSNet::getTravelTime, nullptr, false, nullptr, true);
1492  } else {
1493  if (routingAlgorithm != "astar") {
1494  WRITE_WARNINGF(TL("TraCI and Triggers cannot use routing algorithm '%'. using 'astar' instead."), routingAlgorithm);
1495  }
1496  myRouterTT[rngIndex] = new AStarRouter<MSEdge, SUMOVehicle>(MSEdge::getAllEdges(), true, &MSNet::getTravelTime, nullptr, true);
1497  }
1498  }
1499  myRouterTT[rngIndex]->prohibit(prohibited);
1500  return *myRouterTT[rngIndex];
1501 }
1502 
1503 
1505 MSNet::getRouterEffort(const int rngIndex, const MSEdgeVector& prohibited) const {
1506  if (myRouterEffort.count(rngIndex) == 0) {
1508  }
1509  myRouterEffort[rngIndex]->prohibit(prohibited);
1510  return *myRouterEffort[rngIndex];
1511 }
1512 
1513 
1515 MSNet::getPedestrianRouter(const int rngIndex, const MSEdgeVector& prohibited) const {
1516  if (myPedestrianRouter.count(rngIndex) == 0) {
1517  myPedestrianRouter[rngIndex] = new MSPedestrianRouter();
1518  }
1519  myPedestrianRouter[rngIndex]->prohibit(prohibited);
1520  return *myPedestrianRouter[rngIndex];
1521 }
1522 
1523 
1525 MSNet::getIntermodalRouter(const int rngIndex, const int routingMode, const MSEdgeVector& prohibited) const {
1526  const OptionsCont& oc = OptionsCont::getOptions();
1527  const int key = rngIndex * oc.getInt("thread-rngs") + routingMode;
1528  if (myIntermodalRouter.count(key) == 0) {
1529  const int carWalk = SUMOVehicleParserHelper::parseCarWalkTransfer(oc, MSDevice_Taxi::getTaxi() != nullptr);
1530  const std::string routingAlgorithm = OptionsCont::getOptions().getString("routing-algorithm");
1531  const double taxiWait = STEPS2TIME(string2time(OptionsCont::getOptions().getString("persontrip.taxi.waiting-time")));
1532  if (routingMode == libsumo::ROUTING_MODE_COMBINED) {
1533  myIntermodalRouter[key] = new MSTransportableRouter(MSNet::adaptIntermodalRouter, carWalk, taxiWait, routingAlgorithm, routingMode, new FareModul());
1534  } else {
1535  myIntermodalRouter[key] = new MSTransportableRouter(MSNet::adaptIntermodalRouter, carWalk, taxiWait, routingAlgorithm, routingMode);
1536  }
1537  }
1538  myIntermodalRouter[key]->prohibit(prohibited);
1539  return *myIntermodalRouter[key];
1540 }
1541 
1542 
1543 void
1545  double taxiWait = STEPS2TIME(string2time(OptionsCont::getOptions().getString("persontrip.taxi.waiting-time")));
1546  // add access to all parking areas
1547  EffortCalculator* const external = router.getExternalEffort();
1548  for (const auto& stopType : myInstance->myStoppingPlaces) {
1549  // add access to all stopping places
1550  const SumoXMLTag element = stopType.first;
1551  for (const auto& i : stopType.second) {
1552  const MSEdge* const edge = &i.second->getLane().getEdge();
1553  router.getNetwork()->addAccess(i.first, edge, i.second->getBeginLanePosition(), i.second->getEndLanePosition(),
1554  0., element, false, taxiWait);
1555  if (element == SUMO_TAG_BUS_STOP) {
1556  // add access to all public transport stops
1557  for (const auto& a : i.second->getAllAccessPos()) {
1558  router.getNetwork()->addAccess(i.first, &a.lane->getEdge(), a.startPos, a.endPos, a.length, element, true, taxiWait);
1559  }
1560  if (external != nullptr) {
1561  external->addStop(router.getNetwork()->getStopEdge(i.first)->getNumericalID(), *i.second);
1562  }
1563  }
1564  }
1565  }
1568  // add access to transfer from walking to taxi-use
1570  for (MSEdge* edge : myInstance->getEdgeControl().getEdges()) {
1571  if ((edge->getPermissions() & SVC_PEDESTRIAN) != 0 && (edge->getPermissions() & SVC_TAXI) != 0) {
1572  router.getNetwork()->addCarAccess(edge, SVC_TAXI, taxiWait);
1573  }
1574  }
1575  }
1576 }
1577 
1578 
1579 bool
1581  const MSEdgeVector& edges = myEdges->getEdges();
1582  for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
1583  for (std::vector<MSLane*>::const_iterator i = (*e)->getLanes().begin(); i != (*e)->getLanes().end(); ++i) {
1584  if ((*i)->getShape().hasElevation()) {
1585  return true;
1586  }
1587  }
1588  }
1589  return false;
1590 }
1591 
1592 
1593 bool
1595  for (const MSEdge* e : myEdges->getEdges()) {
1596  if (e->getFunction() == SumoXMLEdgeFunc::WALKINGAREA) {
1597  return true;
1598  }
1599  }
1600  return false;
1601 }
1602 
1603 
1604 bool
1606  for (const MSEdge* e : myEdges->getEdges()) {
1607  if (e->getBidiEdge() != nullptr) {
1608  return true;
1609  }
1610  }
1611  return false;
1612 }
1613 
1614 bool
1615 MSNet::warnOnce(const std::string& typeAndID) {
1616  if (myWarnedOnce.find(typeAndID) == myWarnedOnce.end()) {
1617  myWarnedOnce[typeAndID] = true;
1618  return true;
1619  }
1620  return false;
1621 }
1622 
1623 void
1625  const OptionsCont& oc = OptionsCont::getOptions();
1626  clearState(string2time(oc.getString("begin")), true);
1628  // load traffic from additional files
1629  for (std::string file : oc.getStringVector("additional-files")) {
1630  // ignore failure on parsing calibrator flow
1631  MSRouteHandler rh(file, true);
1632  const long before = PROGRESS_BEGIN_TIME_MESSAGE("Loading traffic from '" + file + "'");
1633  if (!XMLSubSys::runParser(rh, file, false)) {
1634  throw ProcessError(TLF("Loading of % failed.", file));
1635  }
1636  PROGRESS_TIME_MESSAGE(before);
1637  }
1638  delete myRouteLoaders;
1640  updateGUI();
1641 }
1642 
1643 
1644 SUMOTime
1645 MSNet::loadState(const std::string& fileName, const bool catchExceptions) {
1646  // load time only
1647  const SUMOTime newTime = MSStateHandler::MSStateTimeHandler::getTime(fileName);
1648  // clean up state
1649  clearState(newTime);
1650  // load state
1651  MSStateHandler h(fileName, 0);
1652  XMLSubSys::runParser(h, fileName, false, false, false, catchExceptions);
1653  if (MsgHandler::getErrorInstance()->wasInformed()) {
1654  throw ProcessError(TLF("Loading state from '%' failed.", fileName));
1655  }
1656  // reset route loaders
1657  delete myRouteLoaders;
1659  // prevent loading errors on rewound route file
1660  MSGlobals::gStateLoaded = true;
1661 
1662  updateGUI();
1663  return newTime;
1664 }
1665 
1666 
1667 /****************************************************************************/
long long int SUMOTime
Definition: GUI.h:35
@ TAXI_PICKUP_ANYWHERE
taxi customer may be picked up anywhere
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:73
IntermodalRouter< MSEdge, MSLane, MSJunction, SUMOVehicle > MSTransportableRouter
Definition: MSRouterDefs.h:41
PedestrianRouter< MSEdge, MSLane, MSJunction, SUMOVehicle > MSPedestrianRouter
Definition: MSRouterDefs.h:42
#define WRITE_WARNINGF(...)
Definition: MsgHandler.h:296
#define WRITE_MESSAGEF(...)
Definition: MsgHandler.h:298
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:297
#define PROGRESS_BEGIN_TIME_MESSAGE(msg)
Definition: MsgHandler.h:301
#define TL(string)
Definition: MsgHandler.h:315
#define PROGRESS_TIME_MESSAGE(before)
Definition: MsgHandler.h:302
#define TLF(string,...)
Definition: MsgHandler.h:317
std::string elapsedMs2string(long long int t)
convert ms to string for log output
Definition: SUMOTime.cpp:122
SUMOTime DELTA_T
Definition: SUMOTime.cpp:38
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition: SUMOTime.cpp:46
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition: SUMOTime.cpp:69
#define STEPS2TIME(x)
Definition: SUMOTime.h:55
#define TS
Definition: SUMOTime.h:42
#define SIMTIME
Definition: SUMOTime.h:62
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_TAXI
vehicle is a taxi
@ SVC_PEDESTRIAN
pedestrian
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_CHARGING_STATION
A Charging Station.
@ SUMO_TAG_CONTAINER_STOP
A container stop.
@ SUMO_TAG_BUS_STOP
A bus stop.
@ SUMO_TAG_PARKING_AREA
A parking area.
@ SUMO_TAG_TRAIN_STOP
A train stop (alias for bus stop)
@ SUMO_TAG_OVERHEAD_WIRE_SEGMENT
An overhead wire segment.
@ SUMO_ATTR_MAXIMUMBATTERYCAPACITY
Maxium battery capacity.
@ SUMO_ATTR_VEHICLE
@ SUMO_ATTR_RECUPERATIONENABLE
@ SUMO_ATTR_ID
int gPrecision
the precision for floating point outputs
Definition: StdDefs.cpp:26
std::pair< int, double > MMVersion
(M)ajor/(M)inor version for written networks and default version for loading
Definition: StdDefs.h:67
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:283
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
Computes the shortest path through a network using the A* algorithm.
Definition: AStarRouter.h:76
Computes the shortest path through a network using the Dijkstra algorithm.
the effort calculator interface
virtual void addStop(const int stopEdge, const Parameterised &params)=0
int getNumericalID() const
void addCarAccess(const E *edge, SUMOVehicleClass svc, double traveltime)
Adds access edges for transfering from walking to vehicle use.
void addAccess(const std::string &stopId, const E *stopEdge, const double startPos, const double endPos, const double length, const SumoXMLTag category, bool isAccess, double taxiWait)
Adds access edges for stopping places to the intermodal network.
_IntermodalEdge * getStopEdge(const std::string &stopId) const
Returns the associated stop edge.
EffortCalculator * getExternalEffort() const
Network * getNetwork() const
int getCarWalkTransfer() const
The main mesocopic simulation loop.
Definition: MELoop.h:47
void simulate(SUMOTime tMax)
Perform simulation up to the given time.
Definition: MELoop.cpp:61
void clearState()
Remove all vehicles before quick-loading state.
Definition: MELoop.cpp:238
A single mesoscopic segment (cell)
Definition: MESegment.h:49
static void write(OutputDevice &of, const SUMOTime timestep)
Writes the complete network state into the given device.
const MSEdgeWeightsStorage & getWeightsStorage() const
Returns the vehicle's internal edge travel times/efforts container.
int getRoutingMode() const
return routing mode (configures router choice but also handling of transient permission changes)
static void write(OutputDevice &of, SUMOTime timestep, int precision)
Writes the complete network state of the given edges into the given device.
static void cleanup()
cleanup remaining data structures
static void write(OutputDevice &of, SUMOTime timestep)
Writes the recently completed charging events.
Detectors container; responsible for string and output generation.
void writeOutput(SUMOTime step, bool closing)
Writes the output to be generated within the given time step.
void clearState(SUMOTime step)
Remove all vehicles before quick-loading state.
void updateDetectors(const SUMOTime step)
Computes detector values.
void close(SUMOTime step)
Closes the detector outputs.
static void cleanup()
removes remaining vehicleInformation in sVehicles
A device which collects info on the vehicle trip (mainly on departure and arrival)
double getMaximumBatteryCapacity() const
Get the total vehicle's Battery Capacity in kWh.
A device which collects info on the vehicle trip (mainly on departure and arrival)
Definition: MSDevice_SSM.h:55
static const std::set< MSDevice_SSM *, ComparatorNumericalIdLess > & getInstances()
returns all currently existing SSM devices
static void cleanup()
Clean up remaining devices instances.
static bool hasServableReservations()
check whether there are still (servable) reservations in the system
static SUMOVehicle * getTaxi()
returns a taxi if any exist or nullptr
The ToC Device controls transition of control between automated and manual driving.
Definition: MSDevice_ToC.h:52
static void cleanup()
Closes root tags of output files.
static const std::set< MSDevice_ToC *, ComparatorNumericalIdLess > & getInstances()
returns all currently existing ToC devices
Definition: MSDevice_ToC.h:91
static void writeStatistics(OutputDevice &od)
write statistic output to (xml) file
static std::string printStatistics()
get statistics for printing to stdout
static void generateOutputForUnfinished()
generate output for vehicles which are still in the network
static void writePendingOutput(const bool includeUnfinished)
generate vehroute output for pending vehicles at sim end, either due to sorting or because they are s...
static void cleanupAll()
perform cleanup for all devices
Definition: MSDevice.cpp:147
Stores edges and lanes, performs moving of vehicle.
Definition: MSEdgeControl.h:78
void patchActiveLanes()
Resets information whether a lane is active for all lanes.
void detectCollisions(SUMOTime timestep, const std::string &stage)
Detect collisions.
const MSEdgeVector & getEdges() const
Returns loaded edges.
void setJunctionApproaches(SUMOTime t)
Register junction approaches for all vehicles after velocities have been planned. This is a prerequis...
void executeMovements(SUMOTime t)
Executes planned vehicle movements with regards to right-of-way.
void planMovements(SUMOTime t)
Compute safe velocities for all vehicles based on positions and speeds from the last time step....
void changeLanes(const SUMOTime t)
Moves (precomputes) critical vehicles.
A road/street connecting two junctions.
Definition: MSEdge.h:77
static const MSEdgeVector & getAllEdges()
Returns all edges with a numerical id.
Definition: MSEdge.cpp:1034
static void clear()
Clears the dictionary.
Definition: MSEdge.cpp:1040
double getMinimumTravelTime(const SUMOVehicle *const veh) const
returns the minimum travel time for the given vehicle
Definition: MSEdge.h:476
A storage for edge travel times and efforts.
bool retrieveExistingTravelTime(const MSEdge *const e, const double t, double &value) const
Returns a travel time for an edge and time if stored.
bool retrieveExistingEffort(const MSEdge *const e, const double t, double &value) const
Returns an effort for an edge and time if stored.
static void writeAggregated(OutputDevice &of, SUMOTime timestep, int precision)
static void write(OutputDevice &of, const SUMOVehicle *veh, SUMOTime timestep, int precision)
Writes the complete network state of the given edges into the given device.
static void write(OutputDevice &of, SUMOTime timestep, int precision)
Writes the complete network state of the given edges into the given device.
Stores time-dependant events and executes them at the proper time.
virtual void execute(SUMOTime time)
Executes time-dependant commands.
void clearState(SUMOTime currentTime, SUMOTime newTime)
Remove all events before quick-loading state.
static void write(OutputDevice &of, SUMOTime timestep, bool elevation)
Writes the position and the angle of each vehicle into the given device.
Definition: MSFCDExport.cpp:50
static void write(OutputDevice &of, SUMOTime timestep)
Dumping a hugh List of Parameters available in the Simulation.
static bool gUseMesoSim
Definition: MSGlobals.h:103
static double gWeightsSeparateTurns
Whether turning specific weights are estimated (and how much)
Definition: MSGlobals.h:174
static bool gOverheadWireRecuperation
Definition: MSGlobals.h:121
static MELoop * gMesoNet
mesoscopic simulation infrastructure
Definition: MSGlobals.h:109
static bool gStateLoaded
Information whether a state has been loaded.
Definition: MSGlobals.h:100
static bool gCheck4Accidents
Definition: MSGlobals.h:85
static bool gClearState
whether the simulation is in the process of clearing state (MSNet::clearState)
Definition: MSGlobals.h:140
static bool gHaveEmissions
Whether emission output of some type is needed (files or GUI)
Definition: MSGlobals.h:180
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
Definition: MSGlobals.h:78
static int gNumThreads
how many threads to use
Definition: MSGlobals.h:146
Inserts vehicles into the network when their departure time is reached.
void adaptIntermodalRouter(MSTransportableRouter &router) const
int getWaitingVehicleNo() const
Returns the number of waiting vehicles.
int emitVehicles(SUMOTime time)
Emits vehicles that want to depart at the given time.
bool hasFlow(const std::string &id) const
checks whether the given flow still exists
void determineCandidates(SUMOTime time)
Checks for all vehicles whether they can be emitted.
int getPendingFlowCount() const
Returns the number of flows that are still active.
void clearState()
Remove all vehicles before quick-loading state.
Container for junctions; performs operations on all stored junctions.
Representation of a lane in the micro simulation.
Definition: MSLane.h:84
static void clear()
Clears the dictionary.
Definition: MSLane.cpp:2418
static const std::map< std::string, MSLaneSpeedTrigger * > & getInstances()
return all MSLaneSpeedTrigger instances
Interface for objects listening to transportable state changes.
Definition: MSNet.h:700
Interface for objects listening to vehicle state changes.
Definition: MSNet.h:641
The simulated network and simulation perfomer.
Definition: MSNet.h:89
std::map< SumoXMLTag, NamedObjectCont< MSStoppingPlace * > > myStoppingPlaces
Dictionary of bus / container stops.
Definition: MSNet.h:988
long myTraCIMillis
The overall time spent waiting for traci operations including.
Definition: MSNet.h:927
static double getEffort(const MSEdge *const e, const SUMOVehicle *const v, double t)
Returns the effort to pass an edge.
Definition: MSNet.cpp:150
bool warnOnce(const std::string &typeAndID)
return whether a warning regarding the given object shall be issued
Definition: MSNet.cpp:1615
SUMOTime loadState(const std::string &fileName, const bool catchExceptions)
load state from file and return new time
Definition: MSNet.cpp:1645
bool myLogExecutionTime
Information whether the simulation duration shall be logged.
Definition: MSNet.h:913
MSTransportableControl * myPersonControl
Controls person building and deletion;.
Definition: MSNet.h:882
void removeVehicleStateListener(VehicleStateListener *listener)
Removes a vehicle states listener.
Definition: MSNet.cpp:1258
SUMORouteLoaderControl * myRouteLoaders
Route loader for dynamic loading of routes.
Definition: MSNet.h:860
bool addStoppingPlace(const SumoXMLTag category, MSStoppingPlace *stop)
Adds a stopping place.
Definition: MSNet.cpp:1357
void informTransportableStateListener(const MSTransportable *const transportable, TransportableState to, const std::string &info="")
Informs all added listeners about a transportable's state change.
Definition: MSNet.cpp:1295
SUMOTime myStateDumpPeriod
The period for writing state.
Definition: MSNet.h:946
static const NamedObjectCont< MSStoppingPlace * > myEmptyStoppingPlaceCont
Definition: MSNet.h:1009
void writeOverheadWireSegmentOutput() const
write the output generated by an overhead wire segment
Definition: MSNet.cpp:1442
void writeChargingStationOutput() const
write charging station output
Definition: MSNet.cpp:1419
std::pair< bool, NamedRTree > myLanesRTree
An RTree structure holding lane IDs.
Definition: MSNet.h:1025
bool checkBidiEdges()
check wether bidirectional edges occur in the network
Definition: MSNet.cpp:1605
VehicleState
Definition of a vehicle state.
Definition: MSNet.h:608
int myLogStepPeriod
Period between successive step-log outputs.
Definition: MSNet.h:918
MSPedestrianRouter & getPedestrianRouter(const int rngIndex, const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:1515
SUMOTime myStep
Current time step.
Definition: MSNet.h:863
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:184
bool myHasBidiEdges
Whether the network contains bidirectional rail edges.
Definition: MSNet.h:976
MSEventControl * myBeginOfTimestepEvents
Controls events executed at the begin of a time step;.
Definition: MSNet.h:896
bool addTractionSubstation(MSTractionSubstation *substation)
Adds a traction substation.
Definition: MSNet.cpp:1363
std::map< std::string, bool > myWarnedOnce
container to record warnings that shall only be issued once
Definition: MSNet.h:1012
static void initStatic()
Place for static initializations of simulation components (called after successful net build)
Definition: MSNet.cpp:192
void removeOutdatedCollisions()
remove collisions from the previous simulation step
Definition: MSNet.cpp:1338
MSJunctionControl * myJunctions
Controls junctions, realizes right-of-way rules;.
Definition: MSNet.h:888
MSVehicleRouter & getRouterEffort(const int rngIndex, const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:1505
std::vector< std::string > myPeriodicStateFiles
The names of the last K periodic state files (only only K shall be kept)
Definition: MSNet.h:944
ShapeContainer * myShapeContainer
A container for geometrical shapes;.
Definition: MSNet.h:902
std::string myStateDumpSuffix
Definition: MSNet.h:949
bool checkElevation()
check all lanes for elevation data
Definition: MSNet.cpp:1580
bool existTractionSubstation(const std::string &substationId)
return whether given electrical substation exists in the network
Definition: MSNet.cpp:1476
void removeTransportableStateListener(TransportableStateListener *listener)
Removes a transportable states listener.
Definition: MSNet.cpp:1286
SimulationState adaptToState(const SimulationState state, const bool isLibsumo=false) const
Called after a simulation step, this method adapts the current simulation state if necessary.
Definition: MSNet.cpp:908
void closeBuilding(const OptionsCont &oc, MSEdgeControl *edges, MSJunctionControl *junctions, SUMORouteLoaderControl *routeLoaders, MSTLLogicControl *tlc, std::vector< SUMOTime > stateDumpTimes, std::vector< std::string > stateDumpFiles, bool hasInternalLinks, bool junctionHigherSpeeds, const MMVersion &version)
Closes the network's building process.
Definition: MSNet.cpp:257
bool myLogStepNumber
Information whether the number of the simulation step shall be logged.
Definition: MSNet.h:916
MMVersion myVersion
the network version
Definition: MSNet.h:982
MSEventControl * myInsertionEvents
Controls insertion events;.
Definition: MSNet.h:900
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition: MSNet.cpp:1191
SimulationState
Possible states of a simulation - running or stopped with different reasons.
Definition: MSNet.h:94
@ SIMSTATE_TOO_MANY_TELEPORTS
The simulation had too many teleports.
Definition: MSNet.h:110
@ SIMSTATE_NO_FURTHER_VEHICLES
The simulation does not contain further vehicles.
Definition: MSNet.h:102
@ SIMSTATE_LOADING
The simulation is loading.
Definition: MSNet.h:96
@ SIMSTATE_ERROR_IN_SIM
An error occurred during the simulation step.
Definition: MSNet.h:106
@ SIMSTATE_CONNECTION_CLOSED
The connection to a client was closed by the client.
Definition: MSNet.h:104
@ SIMSTATE_INTERRUPTED
An external interrupt occured.
Definition: MSNet.h:108
@ SIMSTATE_RUNNING
The simulation is running.
Definition: MSNet.h:98
@ SIMSTATE_END_STEP_REACHED
The final simulation step has been performed.
Definition: MSNet.h:100
std::map< int, MSPedestrianRouter * > myPedestrianRouter
Definition: MSNet.h:1021
static const std::string STAGE_MOVEMENTS
Definition: MSNet.h:833
bool hasFlow(const std::string &id) const
return whether the given flow is known
Definition: MSNet.cpp:389
int myMaxTeleports
Maximum number of teleports.
Definition: MSNet.h:869
long mySimStepDuration
Definition: MSNet.h:921
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:378
MSEventControl * myEndOfTimestepEvents
Controls events executed at the end of a time step;.
Definition: MSNet.h:898
static std::string getStateMessage(SimulationState state)
Returns the message to show if a certain state occurs.
Definition: MSNet.cpp:929
std::string getStoppingPlaceID(const MSLane *lane, const double pos, const SumoXMLTag category) const
Returns the stop of the given category close to the given position.
Definition: MSNet.cpp:1394
bool myHasInternalLinks
Whether the network contains internal links/lanes/edges.
Definition: MSNet.h:964
void writeSubstationOutput() const
write electrical substation output
Definition: MSNet.cpp:1453
static const std::string STAGE_INSERTIONS
Definition: MSNet.h:835
long long int myPersonsMoved
Definition: MSNet.h:931
void quickReload()
reset state to the beginning without reloading the network
Definition: MSNet.cpp:1624
MSVehicleControl * myVehicleControl
Controls vehicle building and deletion;.
Definition: MSNet.h:880
MSTransportableRouter & getIntermodalRouter(const int rngIndex, const int routingMode=0, const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:1525
static void clearAll()
Clears all dictionaries.
Definition: MSNet.cpp:954
static void cleanupStatic()
Place for static initializations of simulation components (called after successful net build)
Definition: MSNet.cpp:199
void writeStatistics(const SUMOTime start, const long now) const
write statistic output to (xml) file
Definition: MSNet.cpp:562
void writeSummaryOutput()
write summary-output to (xml) file
Definition: MSNet.cpp:612
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:320
MSEdgeControl * myEdges
Controls edges, performs vehicle movement;.
Definition: MSNet.h:886
std::unique_ptr< MSDynamicShapeUpdater > myDynamicShapeUpdater
Updater for dynamic shapes that are tracking traffic objects (ensures removal of shape dynamics when ...
Definition: MSNet.h:1030
const std::map< SUMOVehicleClass, double > * getRestrictions(const std::string &id) const
Returns the restrictions for an edge type If no restrictions are present, 0 is returned.
Definition: MSNet.cpp:353
void closeSimulation(SUMOTime start, const std::string &reason="")
Closes the simulation (all files, connections, etc.)
Definition: MSNet.cpp:676
MSStoppingPlace * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Returns the named stopping place of the given category.
Definition: MSNet.cpp:1373
bool myHasElevation
Whether the network contains elevation data.
Definition: MSNet.h:970
static double getTravelTime(const MSEdge *const e, const SUMOVehicle *const v, double t)
Returns the travel time to pass an edge.
Definition: MSNet.cpp:164
MSTransportableControl * myContainerControl
Controls container building and deletion;.
Definition: MSNet.h:884
std::vector< TransportableStateListener * > myTransportableStateListeners
Container for transportable state listener.
Definition: MSNet.h:997
void writeOutput()
Write netstate, summary and detector output.
Definition: MSNet.cpp:1037
virtual void updateGUI() const
update view after simulation.loadState
Definition: MSNet.h:596
bool myAmInterrupted
whether an interrupt occured
Definition: MSNet.h:872
void simulationStep(const bool onlyMove=false)
Performs a single simulation step.
Definition: MSNet.cpp:713
void addVehicleStateListener(VehicleStateListener *listener)
Adds a vehicle states listener.
Definition: MSNet.cpp:1250
void clearState(const SUMOTime step, bool quickReload=false)
Resets events when quick-loading state.
Definition: MSNet.cpp:984
void preSimStepOutput() const
Prints the current step number.
Definition: MSNet.cpp:1214
void writeCollisions() const
write collision output to (xml) file
Definition: MSNet.cpp:540
MSEdgeControl & getEdgeControl()
Returns the edge control.
Definition: MSNet.h:421
std::vector< SUMOTime > myStateDumpTimes
Times at which a state shall be written.
Definition: MSNet.h:940
void addTransportableStateListener(TransportableStateListener *listener)
Adds a transportable states listener.
Definition: MSNet.cpp:1278
std::vector< MSTractionSubstation * > myTractionSubstations
Dictionary of traction substations.
Definition: MSNet.h:991
SUMOTime myEdgeDataEndTime
end of loaded edgeData
Definition: MSNet.h:985
MSEdgeWeightsStorage & getWeightsStorage()
Returns the net's internal edge travel times/efforts container.
Definition: MSNet.cpp:1205
std::map< std::string, std::map< SUMOVehicleClass, double > > myRestrictions
The vehicle class specific speed restrictions.
Definition: MSNet.h:958
std::vector< std::string > myStateDumpFiles
The names for the state files.
Definition: MSNet.h:942
void addMesoType(const std::string &typeID, const MESegment::MesoEdgeType &edgeType)
Adds edge type specific meso parameters.
Definition: MSNet.cpp:362
void writeRailSignalBlocks() const
write rail signal block output
Definition: MSNet.cpp:1430
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition: MSNet.h:431
MSTLLogicControl * myLogics
Controls tls logics, realizes waiting on tls rules;.
Definition: MSNet.h:890
bool logSimulationDuration() const
Returns whether duration shall be logged.
Definition: MSNet.cpp:1176
long long int myVehiclesMoved
The overall number of vehicle movements.
Definition: MSNet.h:930
static const std::string STAGE_REMOTECONTROL
Definition: MSNet.h:836
void informVehicleStateListener(const SUMOVehicle *const vehicle, VehicleState to, const std::string &info="")
Informs all added listeners about a vehicle's state change.
Definition: MSNet.cpp:1267
std::map< int, MSTransportableRouter * > myIntermodalRouter
Definition: MSNet.h:1022
std::vector< VehicleStateListener * > myVehicleStateListeners
Container for vehicle state listener.
Definition: MSNet.h:994
SimulationState simulationState(SUMOTime stopTime) const
This method returns the current simulation state. It should not modify status.
Definition: MSNet.cpp:878
long myTraCIStepDuration
The last simulation step duration.
Definition: MSNet.h:921
TransportableState
Definition of a transportable state.
Definition: MSNet.h:685
MSDetectorControl * myDetectorControl
Controls detectors;.
Definition: MSNet.h:894
bool myStepCompletionMissing
whether libsumo triggered a partial step (executeMove)
Definition: MSNet.h:866
static const std::string STAGE_LANECHANGE
Definition: MSNet.h:834
MSNet(MSVehicleControl *vc, MSEventControl *beginOfTimestepEvents, MSEventControl *endOfTimestepEvents, MSEventControl *insertionEvents, ShapeContainer *shapeCont=0)
Constructor.
Definition: MSNet.cpp:206
void addRestriction(const std::string &id, const SUMOVehicleClass svc, const double speed)
Adds a restriction for an edge type.
Definition: MSNet.cpp:347
MSVehicleRouter & getRouterTT(const int rngIndex, const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:1487
std::map< std::string, MESegment::MesoEdgeType > myMesoEdgeTypes
The edge type specific meso parameters.
Definition: MSNet.h:961
MSEdgeWeightsStorage * myEdgeWeights
The net's knowledge about edge efforts/travel times;.
Definition: MSNet.h:904
MSDynamicShapeUpdater * makeDynamicShapeUpdater()
Creates and returns a dynamic shapes updater.
Definition: MSNet.cpp:1199
virtual ~MSNet()
Destructor.
Definition: MSNet.cpp:292
std::map< int, MSVehicleRouter * > myRouterEffort
Definition: MSNet.h:1020
MSTractionSubstation * findTractionSubstation(const std::string &substationId)
find electrical substation by its id
Definition: MSNet.cpp:1465
static MSNet * myInstance
Unique instance of MSNet.
Definition: MSNet.h:857
MSInsertionControl * myInserter
Controls vehicle insertion;.
Definition: MSNet.h:892
void postSimStepOutput() const
Prints the statistics of the step at its end.
Definition: MSNet.cpp:1220
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:1182
bool registerCollision(const SUMOTrafficObject *collider, const SUMOTrafficObject *victim, const std::string &collisionType, const MSLane *lane, double pos)
register collision and return whether it was the first one involving these vehicles
Definition: MSNet.cpp:1306
static const std::string STAGE_EVENTS
string constants for simstep stages
Definition: MSNet.h:832
void loadRoutes()
loads routes for the next few steps
Definition: MSNet.cpp:438
std::string myStateDumpPrefix
name components for periodic state
Definition: MSNet.h:948
bool myJunctionHigherSpeeds
Whether the network was built with higher speed on junctions.
Definition: MSNet.h:967
long mySimBeginMillis
The overall simulation duration.
Definition: MSNet.h:924
bool myHasPedestrianNetwork
Whether the network contains pedestrian network elements.
Definition: MSNet.h:973
std::map< int, MSVehicleRouter * > myRouterTT
Definition: MSNet.h:1019
const MESegment::MesoEdgeType & getMesoType(const std::string &typeID)
Returns edge type specific meso parameters if no type specific parameters have been loaded,...
Definition: MSNet.cpp:367
void postMoveStep()
Performs the parts of the simulation step which happen after the move.
Definition: MSNet.cpp:849
bool hasInternalLinks() const
return whether the network contains internal links
Definition: MSNet.h:780
const std::string generateStatistics(const SUMOTime start, const long now)
Writes performance output and running vehicle stats.
Definition: MSNet.cpp:444
bool checkWalkingarea()
check all lanes for type walkingArea
Definition: MSNet.cpp:1594
static void adaptIntermodalRouter(MSTransportableRouter &router)
Definition: MSNet.cpp:1544
CollisionMap myCollisions
collisions in the current time step
Definition: MSNet.h:1000
const NamedObjectCont< MSStoppingPlace * > & getStoppingPlaces(SumoXMLTag category) const
Definition: MSNet.cpp:1408
SimulationState simulate(SUMOTime start, SUMOTime stop)
Simulates from timestep start to stop.
Definition: MSNet.cpp:396
Definition of overhead wire segment.
static void write(OutputDevice &of, SUMOTime timestep)
Export the queueing length in front of a junction (very experimental!)
static void cleanup()
clean up state
void recheckGreen()
final check for driveway compatibility of signals that switched green in this step
static MSRailSignalControl & getInstance()
static void clearState()
Perform resets events when quick-loading state.
A signal for rails.
Definition: MSRailSignal.h:46
void writeBlocks(OutputDevice &od) const
write rail signal block output for all links and driveways
Parser and container for routes during their loading.
static void dict_clearState()
Decrement all route references before quick-loading state.
Definition: MSRoute.cpp:301
static void clear()
Clears the dictionary (delete all known routes, too)
Definition: MSRoute.cpp:174
static double getEffortExtra(const MSEdge *const e, const SUMOVehicle *const v, double t)
static SUMOTime getTime(const std::string &fileName)
parse time from state file
Parser and output filter for routes and vehicles state saving and loading.
static void saveState(const std::string &file, SUMOTime step, bool usePrefix=true)
Saves the current state.
static MSStopOut * getInstance()
Definition: MSStopOut.h:60
static bool active()
Definition: MSStopOut.h:54
static void cleanup()
Definition: MSStopOut.cpp:50
void generateOutputForUnfinished()
generate output for vehicles which are still stopped at simulation end
Definition: MSStopOut.cpp:194
A lane area vehicles can halt at.
double getBeginLanePosition() const
Returns the begin position of this stop.
const MSLane & getLane() const
Returns the lane this stop is located at.
A class that stores and controls tls and switching of their programs.
void clearState(SUMOTime time, bool quickReload=false)
Clear all tls states before quick-loading state.
std::vector< MSTrafficLightLogic * > getAllLogics() const
Returns a vector which contains all logics.
void check2Switch(SUMOTime step)
Checks whether any WAUT is trying to switch a tls into another program.
Traction substation powering one or more overhead wire sections.
int getRunningNumber() const
Returns the number of build and inserted, but not yet deleted transportables.
bool hasTransportables() const
checks whether any transportable waits to finish her plan
int getWaitingForVehicleNumber() const
Returns the number of transportables waiting for a ride.
int getEndedNumber() const
Returns the number of transportables that exited the simulation.
void checkWaiting(MSNet *net, const SUMOTime time)
checks whether any transportables waiting time is over
int getArrivedNumber() const
Returns the number of transportables that arrived at their destination.
int getTeleportCount() const
Returns the number of teleports transportables did.
int getLoadedNumber() const
Returns the number of build transportables.
int getWaitingUntilNumber() const
Returns the number of transportables waiting for a specified amount of time.
int getTeleportsWrongDest() const
return the number of teleports of transportables riding to the wrong destination
void abortAnyWaitingForVehicle()
aborts the plan for any transportable that is still waiting for a ride
bool hasNonWaiting() const
checks whether any transportable is still engaged in walking / stopping
int getMovingNumber() const
Returns the number of transportables moving by themselvs (i.e. walking)
int getJammedNumber() const
Returns the number of times a transportables was jammed.
void clearState()
Resets transportables when quick-loading state.
int getTeleportsAbortWait() const
return the number of teleports due to excessive waiting for a ride
int getRidingNumber() const
Returns the number of transportables riding a vehicle.
static const std::map< std::string, MSTriggeredRerouter * > & getInstances()
return all rerouter instances
static void write(OutputDevice &of, SUMOTime timestep)
Produce a VTK output to use with Tools like ParaView.
Definition: MSVTKExport.cpp:41
static void init()
Static initalization.
Definition: MSVehicle.cpp:389
static void cleanup()
Static cleanup.
Definition: MSVehicle.cpp:394
The class responsible for building and deletion of vehicles.
void adaptIntermodalRouter(MSTransportableRouter &router) const
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
int getRunningVehicleNo() const
Returns the number of build and inserted, but not yet deleted vehicles.
void removePending()
Removes a vehicle after it has ended.
double getTotalTravelTime() const
Returns the total travel time.
int getLoadedVehicleNo() const
Returns the number of build vehicles.
int getCollisionCount() const
return the number of collisions
int getTeleportsWrongLane() const
return the number of teleports due to vehicles stuck on the wrong lane
int getStoppedVehiclesCount() const
return the number of vehicles that are currently stopped
int getTeleportsYield() const
return the number of teleports due to vehicles stuck on a minor road
void clearState(const bool reinit)
Remove all vehicles before quick-loading state.
int getEmergencyBrakingCount() const
return the number of emergency stops
int getEmergencyStops() const
return the number of emergency stops
double getTotalDepartureDelay() const
Returns the total departure delay.
virtual std::pair< double, double > getVehicleMeanSpeeds() const
get current absolute and relative mean vehicle speed in the network
int getDepartedVehicleNo() const
Returns the number of inserted vehicles.
int getArrivedVehicleNo() const
Returns the number of arrived vehicles.
int getActiveVehicleCount() const
Returns the number of build vehicles that have not been removed or need to wait for a passenger or a ...
int getTeleportsJam() const
return the number of teleports due to jamming
int getEndedVehicleNo() const
Returns the number of removed vehicles.
virtual int getHaltingVehicleNo() const
Returns the number of halting vehicles.
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
int getTeleportCount() const
return the number of teleports (including collisions)
void abortWaiting()
informes about all waiting vehicles (deletion in destructor)
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
static MSVehicleTransfer * getInstance()
Returns the instance of this object.
void checkInsertions(SUMOTime time)
Checks "movement" of stored vehicles.
void clearState()
Remove all vehicles before quick-loading state.
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:91
static void write(OutputDevice &of, const MSEdgeControl &ec, SUMOTime timestep, int precision)
Writes the complete network state of the given edges into the given device.
Definition: MSXMLRawOut.cpp:47
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:92
static SUMORouteLoaderControl * buildRouteLoaderControl(const OptionsCont &oc)
Builds the route loader control.
Definition: NLBuilder.cpp:442
static void initRandomness()
initializes all RNGs
Definition: NLBuilder.cpp:363
const std::string & getID() const
Returns the id.
Definition: Named.h:74
A storage for options typed value containers)
Definition: OptionsCont.h:89
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:60
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
Definition: OptionsIO.cpp:58
An output device that encapsulates an ofstream.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:254
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
void setPrecision(int precision=gPrecision)
Sets the precision or resets it to default.
static void closeAll(bool keepErrorRetrievers=false)
static OutputDevice & getDevice(const std::string &name, bool usePrefix=true)
Returns the described OutputDevice.
bool writeXMLHeader(const std::string &rootElement, const std::string &schemaFile, std::map< SumoXMLAttr, std::string > attrs=std::map< SumoXMLAttr, std::string >(), bool includeConfig=true)
Writes an XML header with optional configuration.
void loadNext(SUMOTime step)
loads the next routes up to and including the given time step
Representation of a vehicle, person, or container.
virtual MSDevice * getDevice(const std::type_info &type) const =0
Returns a device of the given type if it exists or nullptr if not.
virtual double getSpeed() const =0
Returns the object's current speed.
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
Representation of a vehicle.
Definition: SUMOVehicle.h:62
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
static int parseCarWalkTransfer(const OptionsCont &oc, const bool hasTaxi=false)
A scoped lock which only triggers on condition.
Definition: ScopedLocker.h:40
Storage for geometrical objects.
void clearState()
Remove all dynamics before quick-loading state.
static long getCurrentMillis()
Returns the current time in milliseconds.
Definition: SysUtils.cpp:44
TraCI server used to control sumo by a remote TraCI client.
Definition: TraCIServer.h:59
static bool wasClosed()
check whether close was requested
SUMOTime getTargetTime() const
Definition: TraCIServer.h:64
std::vector< std::string > & getLoadArgs()
Definition: TraCIServer.h:258
void cleanup()
clean up subscriptions
static TraCIServer * getInstance()
Definition: TraCIServer.h:68
int processCommands(const SUMOTime step, const bool afterMove=false)
process all commands until the next SUMO simulation step. It is guaranteed that t->getTargetTime() >=...
static bool runParser(GenericSAXHandler &handler, const std::string &file, const bool isNet=false, const bool isRoute=false, const bool isExternal=false, const bool catchExceptions=true)
Runs the given handler on the given file; returns if everything's ok.
Definition: XMLSubSys.cpp:148
static void cleanup()
Definition: Helper.cpp:683
static int postProcessRemoteControl()
return number of remote-controlled entities
Definition: Helper.cpp:1398
TRACI_CONST int CMD_EXECUTEMOVE
TRACI_CONST int ROUTING_MODE_AGGREGATED_CUSTOM
TRACI_CONST int ROUTING_MODE_COMBINED
edge type specific meso parameters
Definition: MESegment.h:55
collision tracking
Definition: MSNet.h:114
double victimSpeed
Definition: MSNet.h:119
const MSLane * lane
Definition: MSNet.h:121
std::string victimType
Definition: MSNet.h:117
double pos
Definition: MSNet.h:122
std::string type
Definition: MSNet.h:120
std::string colliderType
Definition: MSNet.h:116
std::string victim
Definition: MSNet.h:115
double colliderSpeed
Definition: MSNet.h:118
SUMOTime time
Definition: MSNet.h:123