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>
62 #include <utils/xml/XMLSubSys.h>
64 #include <libsumo/Helper.h>
65 #include <libsumo/Simulation.h>
66 #include <mesosim/MELoop.h>
67 #include <mesosim/MESegment.h>
101 #include <utils/router/FareModul.h>
102 #include <netload/NLBuilder.h>
103 
104 #include "MSEdgeControl.h"
105 #include "MSJunctionControl.h"
106 #include "MSInsertionControl.h"
107 #include "MSDynamicShapeUpdater.h"
108 #include "MSEventControl.h"
109 #include "MSEdge.h"
110 #include "MSJunction.h"
111 #include "MSJunctionLogic.h"
112 #include "MSLane.h"
113 #include "MSVehicleControl.h"
114 #include "MSVehicleTransfer.h"
115 #include "MSRoute.h"
116 #include "MSGlobals.h"
117 #include "MSEdgeWeightsStorage.h"
118 #include "MSStateHandler.h"
119 #include "MSFrame.h"
120 #include "MSParkingArea.h"
121 #include "MSStoppingPlace.h"
122 #include "MSNet.h"
123 
124 
125 // ===========================================================================
126 // debug constants
127 // ===========================================================================
128 //#define DEBUG_SIMSTEP
129 
130 
131 // ===========================================================================
132 // static member definitions
133 // ===========================================================================
134 MSNet* MSNet::myInstance = nullptr;
135 
136 const std::string MSNet::STAGE_EVENTS("events");
137 const std::string MSNet::STAGE_MOVEMENTS("move");
138 const std::string MSNet::STAGE_LANECHANGE("laneChange");
139 const std::string MSNet::STAGE_INSERTIONS("insertion");
140 const std::string MSNet::STAGE_REMOTECONTROL("remoteControl");
141 
143 
144 // ===========================================================================
145 // static member method definitions
146 // ===========================================================================
147 double
148 MSNet::getEffort(const MSEdge* const e, const SUMOVehicle* const v, double t) {
149  double value;
150  const MSVehicle* const veh = dynamic_cast<const MSVehicle* const>(v);
151  if (veh != nullptr && veh->getWeightsStorage().retrieveExistingEffort(e, t, value)) {
152  return value;
153  }
154  if (getInstance()->getWeightsStorage().retrieveExistingEffort(e, t, value)) {
155  return value;
156  }
157  return 0;
158 }
159 
160 
161 double
162 MSNet::getTravelTime(const MSEdge* const e, const SUMOVehicle* const v, double t) {
163  double value;
164  const MSVehicle* const veh = dynamic_cast<const MSVehicle* const>(v);
165  if (veh != nullptr && veh->getWeightsStorage().retrieveExistingTravelTime(e, t, value)) {
166  return value;
167  }
169  return value;
170  }
171  if (veh != nullptr && veh->getRoutingMode() == libsumo::ROUTING_MODE_AGGREGATED_CUSTOM) {
172  return MSRoutingEngine::getEffortExtra(e, v, t);
173  }
174  return e->getMinimumTravelTime(v);
175 }
176 
177 
178 // ---------------------------------------------------------------------------
179 // MSNet - methods
180 // ---------------------------------------------------------------------------
181 MSNet*
183  if (myInstance != nullptr) {
184  return myInstance;
185  }
186  throw ProcessError(TL("A network was not yet constructed."));
187 }
188 
189 void
191  if (!MSGlobals::gUseMesoSim) {
193  }
194 }
195 
196 void
198  if (!MSGlobals::gUseMesoSim) {
200  }
201 }
202 
203 
204 MSNet::MSNet(MSVehicleControl* vc, MSEventControl* beginOfTimestepEvents,
205  MSEventControl* endOfTimestepEvents,
206  MSEventControl* insertionEvents,
207  ShapeContainer* shapeCont):
208  myAmInterrupted(false),
209  myVehiclesMoved(0),
210  myPersonsMoved(0),
211  myHavePermissions(false),
212  myHasInternalLinks(false),
213  myJunctionHigherSpeeds(false),
214  myHasElevation(false),
215  myHasPedestrianNetwork(false),
216  myHasBidiEdges(false),
217  myEdgeDataEndTime(-1),
218  myDynamicShapeUpdater(nullptr) {
219  if (myInstance != nullptr) {
220  throw ProcessError(TL("A network was already constructed."));
221  }
223  myStep = string2time(oc.getString("begin"));
224  myMaxTeleports = oc.getInt("max-num-teleports");
225  myLogExecutionTime = !oc.getBool("no-duration-log");
226  myLogStepNumber = !oc.getBool("no-step-log");
227  myLogStepPeriod = oc.getInt("step-log.period");
228  myInserter = new MSInsertionControl(*vc, string2time(oc.getString("max-depart-delay")), oc.getBool("eager-insert"), oc.getInt("max-num-vehicles"),
229  string2time(oc.getString("random-depart-offset")));
230  myVehicleControl = vc;
232  myEdges = nullptr;
233  myJunctions = nullptr;
234  myRouteLoaders = nullptr;
235  myLogics = nullptr;
236  myPersonControl = nullptr;
237  myContainerControl = nullptr;
238  myEdgeWeights = nullptr;
239  myShapeContainer = shapeCont == nullptr ? new ShapeContainer() : shapeCont;
240 
241  myBeginOfTimestepEvents = beginOfTimestepEvents;
242  myEndOfTimestepEvents = endOfTimestepEvents;
243  myInsertionEvents = insertionEvents;
244  myLanesRTree.first = false;
245 
247  MSGlobals::gMesoNet = new MELoop(string2time(oc.getString("meso-recheck")));
248  }
249  myInstance = this;
250  initStatic();
251 }
252 
253 
254 void
256  SUMORouteLoaderControl* routeLoaders,
257  MSTLLogicControl* tlc,
258  std::vector<SUMOTime> stateDumpTimes,
259  std::vector<std::string> stateDumpFiles,
260  bool hasInternalLinks,
261  bool junctionHigherSpeeds,
262  const MMVersion& version) {
263  myEdges = edges;
264  myJunctions = junctions;
265  myRouteLoaders = routeLoaders;
266  myLogics = tlc;
267  // save the time the network state shall be saved at
268  myStateDumpTimes = stateDumpTimes;
269  myStateDumpFiles = stateDumpFiles;
270  myStateDumpPeriod = string2time(oc.getString("save-state.period"));
271  myStateDumpPrefix = oc.getString("save-state.prefix");
272  myStateDumpSuffix = oc.getString("save-state.suffix");
273 
274  // initialise performance computation
276  myTraCIMillis = 0;
278  myJunctionHigherSpeeds = junctionHigherSpeeds;
282  myVersion = version;
285  throw ProcessError(TL("Option weights.separate-turns is only supported when simulating with internal lanes"));
286  }
287 }
288 
289 
291  cleanupStatic();
292  // delete controls
293  delete myJunctions;
294  delete myDetectorControl;
295  // delete mean data
296  delete myEdges;
297  delete myInserter;
298  myInserter = nullptr;
299  delete myLogics;
300  delete myRouteLoaders;
301  if (myPersonControl != nullptr) {
302  delete myPersonControl;
303  myPersonControl = nullptr; // just to have that clear for later cleanups
304  }
305  if (myContainerControl != nullptr) {
306  delete myContainerControl;
307  myContainerControl = nullptr; // just to have that clear for later cleanups
308  }
309  delete myVehicleControl; // must happen after deleting transportables
310  // delete events late so that vehicles can get rid of references first
312  myBeginOfTimestepEvents = nullptr;
313  delete myEndOfTimestepEvents;
314  myEndOfTimestepEvents = nullptr;
315  delete myInsertionEvents;
316  myInsertionEvents = nullptr;
317  delete myShapeContainer;
318  delete myEdgeWeights;
319  for (auto& router : myRouterTT) {
320  delete router.second;
321  }
322  myRouterTT.clear();
323  for (auto& router : myRouterEffort) {
324  delete router.second;
325  }
326  myRouterEffort.clear();
327  for (auto& router : myPedestrianRouter) {
328  delete router.second;
329  }
330  myPedestrianRouter.clear();
331  for (auto& router : myIntermodalRouter) {
332  delete router.second;
333  }
334  myIntermodalRouter.clear();
335  myLanesRTree.second.RemoveAll();
336  clearAll();
338  delete MSGlobals::gMesoNet;
339  }
340  myInstance = nullptr;
341 }
342 
343 
344 void
345 MSNet::addRestriction(const std::string& id, const SUMOVehicleClass svc, const double speed) {
346  myRestrictions[id][svc] = speed;
347 }
348 
349 
350 const std::map<SUMOVehicleClass, double>*
351 MSNet::getRestrictions(const std::string& id) const {
352  std::map<std::string, std::map<SUMOVehicleClass, double> >::const_iterator i = myRestrictions.find(id);
353  if (i == myRestrictions.end()) {
354  return nullptr;
355  }
356  return &i->second;
357 }
358 
359 void
360 MSNet::addMesoType(const std::string& typeID, const MESegment::MesoEdgeType& edgeType) {
361  myMesoEdgeTypes[typeID] = edgeType;
362 }
363 
365 MSNet::getMesoType(const std::string& typeID) {
366  if (myMesoEdgeTypes.count(typeID) == 0) {
367  // init defaults
368  const OptionsCont& oc = OptionsCont::getOptions();
369  MESegment::MesoEdgeType edgeType;
370  edgeType.tauff = string2time(oc.getString("meso-tauff"));
371  edgeType.taufj = string2time(oc.getString("meso-taufj"));
372  edgeType.taujf = string2time(oc.getString("meso-taujf"));
373  edgeType.taujj = string2time(oc.getString("meso-taujj"));
374  edgeType.jamThreshold = oc.getFloat("meso-jam-threshold");
375  edgeType.junctionControl = oc.getBool("meso-junction-control");
376  edgeType.tlsPenalty = oc.getFloat("meso-tls-penalty");
377  edgeType.tlsFlowPenalty = oc.getFloat("meso-tls-flow-penalty");
378  edgeType.minorPenalty = string2time(oc.getString("meso-minor-penalty"));
379  edgeType.overtaking = oc.getBool("meso-overtaking");
380  myMesoEdgeTypes[typeID] = edgeType;
381  }
382  return myMesoEdgeTypes[typeID];
383 }
384 
385 
386 bool
387 MSNet::hasFlow(const std::string& id) const {
388  // inserter is deleted at the end of the simulation
389  return myInserter != nullptr && myInserter->hasFlow(id);
390 }
391 
392 
395  // report the begin when wished
396  WRITE_MESSAGEF(TL("Simulation version % started with time: %."), VERSION_STRING, time2string(start));
397  // the simulation loop
399  // state loading may have changed the start time so we need to reinit it
400  myStep = start;
401  int numSteps = 0;
402  bool doStepLog = false;
403  while (state == SIMSTATE_RUNNING) {
404  doStepLog = myLogStepNumber && (numSteps % myLogStepPeriod == 0);
405  if (doStepLog) {
407  }
408  simulationStep();
409  if (doStepLog) {
411  }
412  state = adaptToState(simulationState(stop));
413 #ifdef DEBUG_SIMSTEP
414  std::cout << SIMTIME << " MSNet::simulate(" << start << ", " << stop << ")"
415  << "\n simulation state: " << getStateMessage(state)
416  << std::endl;
417 #endif
418  numSteps++;
419  }
420  if (myLogStepNumber && !doStepLog) {
421  // ensure some output on the last step
424  }
425  // exit simulation loop
426  if (myLogStepNumber) {
427  // start new line for final verbose output
428  std::cout << "\n";
429  }
430  closeSimulation(start, getStateMessage(state));
431  return state;
432 }
433 
434 
435 void
438 }
439 
440 
441 const std::string
442 MSNet::generateStatistics(const SUMOTime start, const long now) {
443  std::ostringstream msg;
444  if (myLogExecutionTime) {
445  const long duration = now - mySimBeginMillis;
446  // print performance notice
447  msg << "Performance: " << "\n" << " Duration: " << elapsedMs2string(duration) << "\n";
448  if (duration != 0) {
449  if (TraCIServer::getInstance() != nullptr) {
450  msg << " TraCI-Duration: " << elapsedMs2string(myTraCIMillis) << "\n";
451  }
452  msg << " Real time factor: " << (STEPS2TIME(myStep - start) * 1000. / (double)duration) << "\n";
453  msg.setf(std::ios::fixed, std::ios::floatfield); // use decimal format
454  msg.setf(std::ios::showpoint); // print decimal point
455  msg << " UPS: " << ((double)myVehiclesMoved / ((double)duration / 1000)) << "\n";
456  if (myPersonsMoved > 0) {
457  msg << " UPS-Persons: " << ((double)myPersonsMoved / ((double)duration / 1000)) << "\n";
458  }
459  }
460  // print vehicle statistics
461  const std::string discardNotice = ((myVehicleControl->getLoadedVehicleNo() != myVehicleControl->getDepartedVehicleNo()) ?
462  " (Loaded: " + toString(myVehicleControl->getLoadedVehicleNo()) + ")" : "");
463  msg << "Vehicles: " << "\n"
464  << " Inserted: " << myVehicleControl->getDepartedVehicleNo() << discardNotice << "\n"
465  << " Running: " << myVehicleControl->getRunningVehicleNo() << "\n"
466  << " Waiting: " << myInserter->getWaitingVehicleNo() << "\n";
467 
469  // print optional teleport statistics
470  std::vector<std::string> reasons;
471  if (myVehicleControl->getCollisionCount() > 0) {
472  reasons.push_back("Collisions: " + toString(myVehicleControl->getCollisionCount()));
473  }
474  if (myVehicleControl->getTeleportsJam() > 0) {
475  reasons.push_back("Jam: " + toString(myVehicleControl->getTeleportsJam()));
476  }
477  if (myVehicleControl->getTeleportsYield() > 0) {
478  reasons.push_back("Yield: " + toString(myVehicleControl->getTeleportsYield()));
479  }
481  reasons.push_back("Wrong Lane: " + toString(myVehicleControl->getTeleportsWrongLane()));
482  }
483  msg << " Teleports: " << myVehicleControl->getTeleportCount() << " (" << joinToString(reasons, ", ") << ")\n";
484  }
485  if (myVehicleControl->getEmergencyStops() > 0) {
486  msg << " Emergency Stops: " << myVehicleControl->getEmergencyStops() << "\n";
487  }
489  msg << " Emergency Braking: " << myVehicleControl->getEmergencyBrakingCount() << "\n";
490  }
491  if (myPersonControl != nullptr && myPersonControl->getLoadedNumber() > 0) {
492  msg << "Persons: " << "\n"
493  << " Inserted: " << myPersonControl->getLoadedNumber() << "\n"
494  << " Running: " << myPersonControl->getRunningNumber() << "\n";
495  if (myPersonControl->getJammedNumber() > 0) {
496  msg << " Jammed: " << myPersonControl->getJammedNumber() << "\n";
497  }
498  if (myPersonControl->getTeleportCount() > 0) {
499  std::vector<std::string> reasons;
501  reasons.push_back("Abort Wait: " + toString(myPersonControl->getTeleportsAbortWait()));
502  }
504  reasons.push_back("Wrong Dest: " + toString(myPersonControl->getTeleportsWrongDest()));
505  }
506  msg << " Teleports: " << myPersonControl->getTeleportCount() << " (" << joinToString(reasons, ", ") << ")\n";
507  }
508  }
509  if (myContainerControl != nullptr && myContainerControl->getLoadedNumber() > 0) {
510  msg << "Containers: " << "\n"
511  << " Inserted: " << myContainerControl->getLoadedNumber() << "\n"
512  << " Running: " << myContainerControl->getRunningNumber() << "\n";
513  if (myContainerControl->getJammedNumber() > 0) {
514  msg << " Jammed: " << myContainerControl->getJammedNumber() << "\n";
515  }
517  std::vector<std::string> reasons;
519  reasons.push_back("Abort Wait: " + toString(myContainerControl->getTeleportsAbortWait()));
520  }
522  reasons.push_back("Wrong Dest: " + toString(myContainerControl->getTeleportsWrongDest()));
523  }
524  msg << " Teleports: " << myContainerControl->getTeleportCount() << " (" << joinToString(reasons, ", ") << ")\n";
525  }
526  }
527  }
528  if (OptionsCont::getOptions().getBool("duration-log.statistics")) {
530  }
531  return msg.str();
532 }
533 
534 
535 void
537  OutputDevice& od = OutputDevice::getDeviceByOption("collision-output");
538  for (const auto& item : myCollisions) {
539  for (const auto& c : item.second) {
540  od.openTag("collision");
542  od.writeAttr("type", c.type);
543  od.writeAttr("lane", c.lane->getID());
544  od.writeAttr("pos", c.pos);
545  od.writeAttr("collider", item.first);
546  od.writeAttr("victim", c.victim);
547  od.writeAttr("colliderType", c.colliderType);
548  od.writeAttr("victimType", c.victimType);
549  od.writeAttr("colliderSpeed", c.colliderSpeed);
550  od.writeAttr("victimSpeed", c.victimSpeed);
551  od.closeTag();
552  }
553  }
554 }
555 
556 
557 void
558 MSNet::writeStatistics(const SUMOTime start, const long now) const {
559  const long duration = now - mySimBeginMillis;
560  OutputDevice& od = OutputDevice::getDeviceByOption("statistic-output");
561  od.openTag("performance");
562  od.writeAttr("clockBegin", time2string(mySimBeginMillis));
563  od.writeAttr("clockEnd", time2string(now));
564  od.writeAttr("clockDuration", time2string(duration));
565  od.writeAttr("traciDuration", time2string(myTraCIMillis));
566  od.writeAttr("realTimeFactor", duration != 0 ? (double)(myStep - start) / (double)duration : -1);
567  od.writeAttr("vehicleUpdatesPerSecond", duration != 0 ? (double)myVehiclesMoved / ((double)duration / 1000) : -1);
568  od.writeAttr("personUpdatesPerSecond", duration != 0 ? (double)myPersonsMoved / ((double)duration / 1000) : -1);
569  od.writeAttr("begin", time2string(start));
570  od.writeAttr("end", time2string(myStep));
571  od.writeAttr("duration", time2string(myStep - start));
572  od.closeTag();
573  od.openTag("vehicles");
577  od.writeAttr("waiting", myInserter->getWaitingVehicleNo());
578  od.closeTag();
579  od.openTag("teleports");
584  od.closeTag();
585  od.openTag("safety");
586  od.writeAttr("collisions", myVehicleControl->getCollisionCount());
587  od.writeAttr("emergencyStops", myVehicleControl->getEmergencyStops());
588  od.writeAttr("emergencyBraking", myVehicleControl->getEmergencyBrakingCount());
589  od.closeTag();
590  od.openTag("persons");
591  od.writeAttr("loaded", myPersonControl != nullptr ? myPersonControl->getLoadedNumber() : 0);
592  od.writeAttr("running", myPersonControl != nullptr ? myPersonControl->getRunningNumber() : 0);
593  od.writeAttr("jammed", myPersonControl != nullptr ? myPersonControl->getJammedNumber() : 0);
594  od.closeTag();
595  od.openTag("personTeleports");
596  od.writeAttr("total", myPersonControl != nullptr ? myPersonControl->getTeleportCount() : 0);
597  od.writeAttr("abortWait", myPersonControl != nullptr ? myPersonControl->getTeleportsAbortWait() : 0);
598  od.writeAttr("wrongDest", myPersonControl != nullptr ? myPersonControl->getTeleportsWrongDest() : 0);
599  od.closeTag();
600  if (OptionsCont::getOptions().isSet("tripinfo-output") || OptionsCont::getOptions().getBool("duration-log.statistics")) {
602  }
603 
604 }
605 
606 
607 void
609  // summary output
610  const OptionsCont& oc = OptionsCont::getOptions();
611  const bool hasOutput = oc.isSet("summary-output");
612  const bool hasPersonOutput = oc.isSet("person-summary-output");
613  if (hasOutput || hasPersonOutput) {
614  const SUMOTime period = string2time(oc.getString("summary-output.period"));
615  const SUMOTime begin = string2time(oc.getString("begin"));
616  if (period > 0 && (myStep - begin) % period != 0) {
617  return;
618  }
619  }
620  if (hasOutput) {
621  OutputDevice& od = OutputDevice::getDeviceByOption("summary-output");
622  int departedVehiclesNumber = myVehicleControl->getDepartedVehicleNo();
623  const double meanWaitingTime = departedVehiclesNumber != 0 ? myVehicleControl->getTotalDepartureDelay() / (double) departedVehiclesNumber : -1.;
624  int endedVehicleNumber = myVehicleControl->getEndedVehicleNo();
625  const double meanTravelTime = endedVehicleNumber != 0 ? myVehicleControl->getTotalTravelTime() / (double) endedVehicleNumber : -1.;
626  od.openTag("step");
627  od.writeAttr("time", time2string(myStep));
631  od.writeAttr("waiting", myInserter->getWaitingVehicleNo());
634  od.writeAttr("collisions", myVehicleControl->getCollisionCount());
635  od.writeAttr("teleports", myVehicleControl->getTeleportCount());
638  od.writeAttr("meanWaitingTime", meanWaitingTime);
639  od.writeAttr("meanTravelTime", meanTravelTime);
640  std::pair<double, double> meanSpeed = myVehicleControl->getVehicleMeanSpeeds();
641  od.writeAttr("meanSpeed", meanSpeed.first);
642  od.writeAttr("meanSpeedRelative", meanSpeed.second);
643  if (myLogExecutionTime) {
644  od.writeAttr("duration", mySimStepDuration);
645  }
646  od.closeTag();
647  }
648  if (hasPersonOutput) {
649  OutputDevice& od = OutputDevice::getDeviceByOption("person-summary-output");
651  od.openTag("step");
652  od.writeAttr("time", time2string(myStep));
653  od.writeAttr("loaded", pc.getLoadedNumber());
654  od.writeAttr("inserted", pc.getDepartedNumber());
655  od.writeAttr("walking", pc.getMovingNumber());
656  od.writeAttr("waitingForRide", pc.getWaitingForVehicleNumber());
657  od.writeAttr("riding", pc.getRidingNumber());
658  od.writeAttr("stopping", pc.getWaitingUntilNumber());
659  od.writeAttr("jammed", pc.getJammedNumber());
660  od.writeAttr("ended", pc.getEndedNumber());
661  od.writeAttr("arrived", pc.getArrivedNumber());
662  od.writeAttr("teleports", pc.getTeleportCount());
663  if (myLogExecutionTime) {
664  od.writeAttr("duration", mySimStepDuration);
665  }
666  od.closeTag();
667  }
668 }
669 
670 
671 void
672 MSNet::closeSimulation(SUMOTime start, const std::string& reason) {
673  // report the end when wished
674  WRITE_MESSAGE("Simulation ended at time: " + time2string(getCurrentTimeStep()));
675  if (reason != "") {
676  WRITE_MESSAGE("Reason: " + reason);
677  }
679  if (MSStopOut::active() && OptionsCont::getOptions().getBool("stop-output.write-unfinished")) {
681  }
682  MSDevice_Vehroutes::writePendingOutput(OptionsCont::getOptions().getBool("vehroute-output.write-unfinished"));
683  if (OptionsCont::getOptions().getBool("tripinfo-output.write-unfinished")) {
685  }
686  if (OptionsCont::getOptions().isSet("chargingstations-output")) {
688  }
689  if (OptionsCont::getOptions().isSet("overheadwiresegments-output")) {
691  }
692  if (OptionsCont::getOptions().isSet("substations-output")) {
694  }
695  if (OptionsCont::getOptions().isSet("railsignal-block-output")) {
697  }
698  const long now = SysUtils::getCurrentMillis();
699  if (myLogExecutionTime || OptionsCont::getOptions().getBool("duration-log.statistics")) {
700  WRITE_MESSAGE(generateStatistics(start, now));
701  }
702  if (OptionsCont::getOptions().isSet("statistic-output")) {
703  writeStatistics(start, now);
704  }
705 }
706 
707 
708 void
709 MSNet::simulationStep(const bool onlyMove) {
711  postMoveStep();
712  myStepCompletionMissing = false;
713  return;
714  }
715 #ifdef DEBUG_SIMSTEP
716  std::cout << SIMTIME << ": MSNet::simulationStep() called"
717  << ", myStep = " << myStep
718  << std::endl;
719 #endif
721  int lastTraCICmd = 0;
722  if (t != nullptr) {
723  if (myLogExecutionTime) {
725  }
726  lastTraCICmd = t->processCommands(myStep);
727 #ifdef DEBUG_SIMSTEP
728  bool loadRequested = !TraCI::getLoadArgs().empty();
729  assert(t->getTargetTime() >= myStep || loadRequested || TraCIServer::wasClosed());
730 #endif
731  if (myLogExecutionTime) {
733  }
734  if (TraCIServer::wasClosed() || !t->getLoadArgs().empty()) {
735  return;
736  }
737  }
738 #ifdef DEBUG_SIMSTEP
739  std::cout << SIMTIME << ": TraCI target time: " << t->getTargetTime() << std::endl;
740 #endif
741  // execute beginOfTimestepEvents
742  if (myLogExecutionTime) {
744  }
745  // simulation state output
746  std::vector<SUMOTime>::iterator timeIt = std::find(myStateDumpTimes.begin(), myStateDumpTimes.end(), myStep);
747  if (timeIt != myStateDumpTimes.end()) {
748  const int dist = (int)distance(myStateDumpTimes.begin(), timeIt);
750  }
751  if (myStateDumpPeriod > 0 && myStep % myStateDumpPeriod == 0) {
752  std::string timeStamp = time2string(myStep);
753  std::replace(timeStamp.begin(), timeStamp.end(), ':', '-');
754  const std::string filename = myStateDumpPrefix + "_" + timeStamp + myStateDumpSuffix;
756  myPeriodicStateFiles.push_back(filename);
757  int keep = OptionsCont::getOptions().getInt("save-state.period.keep");
758  if (keep > 0 && (int)myPeriodicStateFiles.size() > keep) {
759  std::remove(myPeriodicStateFiles.front().c_str());
761  }
762  }
766  }
767 #ifdef HAVE_FOX
768  MSRoutingEngine::waitForAll();
769 #endif
772  }
773  // check whether the tls programs need to be switched
775 
778  } else {
779  // assure all lanes with vehicles are 'active'
781 
782  // compute safe velocities for all vehicles for the next few lanes
783  // also register ApproachingVehicleInformation for all links
785 
786  // register junction approaches based on planned velocities as basis for right-of-way decision
788 
789  // decide right-of-way and execute movements
793  }
794 
795  // vehicles may change lanes
797 
800  }
801  }
802  // flush arrived meso vehicles and micro vehicles that were removed due to collision
804  loadRoutes();
805 
806  // persons
807  if (myPersonControl != nullptr && myPersonControl->hasTransportables()) {
809  }
810  // containers
813  }
814  // insert vehicles
817 #ifdef HAVE_FOX
818  MSRoutingEngine::waitForAll();
819 #endif
822  //myEdges->patchActiveLanes(); // @note required to detect collisions on lanes that were empty before insertion. wasteful?
824  }
826 
827  // execute endOfTimestepEvents
829 
830  if (myLogExecutionTime) {
832  }
833  if (onlyMove) {
835  return;
836  }
837  if (t != nullptr && lastTraCICmd == libsumo::CMD_EXECUTEMOVE) {
838  t->processCommands(myStep, true);
839  }
840  postMoveStep();
841 }
842 
843 
844 void
846  const int numControlled = libsumo::Helper::postProcessRemoteControl();
847  if (numControlled > 0 && MSGlobals::gCheck4Accidents) {
849  }
850  if (myLogExecutionTime) {
853  }
855  // collisions from the previous step were kept to avoid duplicate
856  // warnings. we must remove them now to ensure correct output.
858  }
859  // update and write (if needed) detector values
861  writeOutput();
862 
863  if (myLogExecutionTime) {
865  if (myPersonControl != nullptr) {
867  }
868  }
869  myStep += DELTA_T;
870 }
871 
872 
875  if (TraCIServer::wasClosed()) {
877  }
878  if (TraCIServer::getInstance() != nullptr && !TraCIServer::getInstance()->getLoadArgs().empty()) {
879  return SIMSTATE_LOADING;
880  }
881  if ((stopTime < 0 || myStep > stopTime) && TraCIServer::getInstance() == nullptr && (stopTime > 0 || myStep > myEdgeDataEndTime)) {
883  && (myInserter->getPendingFlowCount() == 0)
884  && (myPersonControl == nullptr || !myPersonControl->hasNonWaiting())
888  }
889  }
890  if (stopTime >= 0 && myStep >= stopTime) {
892  }
895  }
896  if (myAmInterrupted) {
897  return SIMSTATE_INTERRUPTED;
898  }
899  return SIMSTATE_RUNNING;
900 }
901 
902 
904 MSNet::adaptToState(MSNet::SimulationState state, const bool isLibsumo) const {
905  if (state == SIMSTATE_LOADING) {
908  } else if (state != SIMSTATE_RUNNING && ((TraCIServer::getInstance() != nullptr && !TraCIServer::wasClosed()) || isLibsumo)) {
909  // overrides SIMSTATE_END_STEP_REACHED, e.g. (TraCI / Libsumo ignore SUMO's --end option)
910  return SIMSTATE_RUNNING;
911  } else if (state == SIMSTATE_NO_FURTHER_VEHICLES) {
912  if (myPersonControl != nullptr) {
914  }
915  if (myContainerControl != nullptr) {
917  }
919  }
920  return state;
921 }
922 
923 
924 std::string
926  switch (state) {
928  return "";
930  return "The final simulation step has been reached.";
932  return "All vehicles have left the simulation.";
934  return "TraCI requested termination.";
936  return "An error occurred (see log).";
938  return "Interrupted.";
940  return "Too many teleports.";
942  return "TraCI issued load command.";
943  default:
944  return "Unknown reason.";
945  }
946 }
947 
948 
949 void
951  // clear container
952  MSEdge::clear();
953  MSLane::clear();
954  MSRoute::clear();
958  while (!MSLaneSpeedTrigger::getInstances().empty()) {
959  delete MSLaneSpeedTrigger::getInstances().begin()->second;
960  }
961  while (!MSTriggeredRerouter::getInstances().empty()) {
962  delete MSTriggeredRerouter::getInstances().begin()->second;
963  }
971  if (t != nullptr) {
972  t->cleanup();
973  }
976 }
977 
978 
979 void
980 MSNet::clearState(const SUMOTime step, bool quickReload) {
981  MSGlobals::gClearState = true;
984  for (MSEdge* const edge : MSEdge::getAllEdges()) {
985  for (MESegment* s = MSGlobals::gMesoNet->getSegmentForEdge(*edge); s != nullptr; s = s->getNextSegment()) {
986  s->clearState();
987  }
988  }
989  } else {
990  for (MSEdge* const edge : MSEdge::getAllEdges()) {
991  for (MSLane* const lane : edge->getLanes()) {
992  lane->getVehiclesSecure();
993  lane->clearState();
994  lane->releaseVehicles();
995  }
996  edge->clearState();
997  }
998  }
1000  // detectors may still reference persons/vehicles
1004 
1005  if (myPersonControl != nullptr) {
1007  }
1008  if (myContainerControl != nullptr) {
1010  }
1011  // delete vtypes after transportables have removed their types
1015  // delete all routes after vehicles and detector output is done
1017  for (auto& item : myStoppingPlaces) {
1018  for (auto& item2 : item.second) {
1019  item2.second->clearState();
1020  }
1021  }
1027  myStep = step;
1028  MSGlobals::gClearState = false;
1029 }
1030 
1031 
1032 void
1034  // update detector values
1036  const OptionsCont& oc = OptionsCont::getOptions();
1037 
1038  // check state dumps
1039  if (oc.isSet("netstate-dump")) {
1041  oc.getInt("netstate-dump.precision"));
1042  }
1043 
1044  // check fcd dumps
1045  if (OptionsCont::getOptions().isSet("fcd-output")) {
1047  }
1048 
1049  // check emission dumps
1050  if (OptionsCont::getOptions().isSet("emission-output")) {
1052  oc.getInt("emission-output.precision"));
1053  }
1054 
1055  // battery dumps
1056  if (OptionsCont::getOptions().isSet("battery-output")) {
1058  oc.getInt("battery-output.precision"));
1059  }
1060 
1061  // elecHybrid dumps
1062  if (OptionsCont::getOptions().isSet("elechybrid-output")) {
1063  std::string output = OptionsCont::getOptions().getString("elechybrid-output");
1064 
1065  if (oc.getBool("elechybrid-output.aggregated")) {
1066  // build a xml file with aggregated device.elechybrid output
1068  oc.getInt("elechybrid-output.precision"));
1069  } else {
1070  // build a separate xml file for each vehicle equipped with device.elechybrid
1071  // RICE_TODO: Does this have to be placed here in MSNet.cpp ?
1073  for (MSVehicleControl::constVehIt it = vc.loadedVehBegin(); it != vc.loadedVehEnd(); ++it) {
1074  const SUMOVehicle* veh = it->second;
1075  if (!veh->isOnRoad()) {
1076  continue;
1077  }
1078  if (static_cast<MSDevice_ElecHybrid*>(veh->getDevice(typeid(MSDevice_ElecHybrid))) != nullptr) {
1079  std::string vehID = veh->getID();
1080  std::string filename2 = output + "_" + vehID + ".xml";
1081  OutputDevice& dev = OutputDevice::getDevice(filename2);
1082  std::map<SumoXMLAttr, std::string> attrs;
1083  attrs[SUMO_ATTR_VEHICLE] = vehID;
1086  dev.writeXMLHeader("elecHybrid-export", "", attrs);
1087  MSElecHybridExport::write(OutputDevice::getDevice(filename2), veh, myStep, oc.getInt("elechybrid-output.precision"));
1088  }
1089  }
1090  }
1091  }
1092 
1093 
1094  // check full dumps
1095  if (OptionsCont::getOptions().isSet("full-output")) {
1098  }
1099 
1100  // check queue dumps
1101  if (OptionsCont::getOptions().isSet("queue-output")) {
1103  }
1104 
1105  // check amitran dumps
1106  if (OptionsCont::getOptions().isSet("amitran-output")) {
1108  }
1109 
1110  // check vtk dumps
1111  if (OptionsCont::getOptions().isSet("vtk-output")) {
1112 
1113  if (MSNet::getInstance()->getVehicleControl().getRunningVehicleNo() > 0) {
1114  std::string timestep = time2string(myStep);
1115  timestep = timestep.substr(0, timestep.length() - 3);
1116  std::string output = OptionsCont::getOptions().getString("vtk-output");
1117  std::string filename = output + "_" + timestep + ".vtp";
1118 
1119  OutputDevice_File dev(filename, false);
1120 
1121  //build a huge mass of xml files
1122  MSVTKExport::write(dev, myStep);
1123 
1124  }
1125 
1126  }
1127 
1129 
1130  // write detector values
1132 
1133  // write link states
1134  if (OptionsCont::getOptions().isSet("link-output")) {
1135  OutputDevice& od = OutputDevice::getDeviceByOption("link-output");
1136  od.openTag("timestep");
1138  for (const MSEdge* const edge : myEdges->getEdges()) {
1139  for (const MSLane* const lane : edge->getLanes()) {
1140  for (const MSLink* const link : lane->getLinkCont()) {
1141  link->writeApproaching(od, lane->getID());
1142  }
1143  }
1144  }
1145  od.closeTag();
1146  }
1147 
1148  // write SSM output
1149  for (MSDevice_SSM* dev : MSDevice_SSM::getInstances()) {
1150  dev->updateAndWriteOutput();
1151  }
1152 
1153  // write ToC output
1154  for (MSDevice_ToC* dev : MSDevice_ToC::getInstances()) {
1155  if (dev->generatesOutput()) {
1156  dev->writeOutput();
1157  }
1158  }
1159 
1160  if (OptionsCont::getOptions().isSet("collision-output")) {
1161  writeCollisions();
1162  }
1163 }
1164 
1165 
1166 bool
1168  return myLogExecutionTime;
1169 }
1170 
1171 
1174  if (myPersonControl == nullptr) {
1176  }
1177  return *myPersonControl;
1178 }
1179 
1180 
1183  if (myContainerControl == nullptr) {
1185  }
1186  return *myContainerControl;
1187 }
1188 
1191  myDynamicShapeUpdater = std::unique_ptr<MSDynamicShapeUpdater> (new MSDynamicShapeUpdater(*myShapeContainer));
1192  return myDynamicShapeUpdater.get();
1193 }
1194 
1197  if (myEdgeWeights == nullptr) {
1199  }
1200  return *myEdgeWeights;
1201 }
1202 
1203 
1204 void
1206  std::cout << "Step #" << time2string(myStep);
1207 }
1208 
1209 
1210 void
1212  if (myLogExecutionTime) {
1213  std::ostringstream oss;
1214  oss.setf(std::ios::fixed, std::ios::floatfield); // use decimal format
1215  oss.setf(std::ios::showpoint); // print decimal point
1216  oss << std::setprecision(gPrecision);
1217  if (mySimStepDuration != 0) {
1218  const double durationSec = (double)mySimStepDuration / 1000.;
1219  oss << " (" << mySimStepDuration << "ms ~= "
1220  << (TS / durationSec) << "*RT, ~"
1221  << ((double) myVehicleControl->getRunningVehicleNo() / durationSec);
1222  } else {
1223  oss << " (0ms ?*RT. ?";
1224  }
1225  oss << "UPS, ";
1226  if (TraCIServer::getInstance() != nullptr) {
1227  oss << "TraCI: " << myTraCIStepDuration << "ms, ";
1228  }
1229  oss << "vehicles TOT " << myVehicleControl->getDepartedVehicleNo()
1230  << " ACT " << myVehicleControl->getRunningVehicleNo()
1231  << " BUF " << myInserter->getWaitingVehicleNo()
1232  << ") ";
1233  std::string prev = "Step #" + time2string(myStep - DELTA_T);
1234  std::cout << oss.str().substr(0, 90 - prev.length());
1235  }
1236  std::cout << '\r';
1237 }
1238 
1239 
1240 void
1242  if (find(myVehicleStateListeners.begin(), myVehicleStateListeners.end(), listener) == myVehicleStateListeners.end()) {
1243  myVehicleStateListeners.push_back(listener);
1244  }
1245 }
1246 
1247 
1248 void
1250  std::vector<VehicleStateListener*>::iterator i = std::find(myVehicleStateListeners.begin(), myVehicleStateListeners.end(), listener);
1251  if (i != myVehicleStateListeners.end()) {
1252  myVehicleStateListeners.erase(i);
1253  }
1254 }
1255 
1256 
1257 void
1258 MSNet::informVehicleStateListener(const SUMOVehicle* const vehicle, VehicleState to, const std::string& info) {
1259 #ifdef HAVE_FOX
1260  ScopedLocker<> lock(myVehicleStateListenerMutex, MSGlobals::gNumThreads > 1);
1261 #endif
1262  for (VehicleStateListener* const listener : myVehicleStateListeners) {
1263  listener->vehicleStateChanged(vehicle, to, info);
1264  }
1265 }
1266 
1267 
1268 void
1271  myTransportableStateListeners.push_back(listener);
1272  }
1273 }
1274 
1275 
1276 void
1278  std::vector<TransportableStateListener*>::iterator i = std::find(myTransportableStateListeners.begin(), myTransportableStateListeners.end(), listener);
1279  if (i != myTransportableStateListeners.end()) {
1281  }
1282 }
1283 
1284 
1285 void
1286 MSNet::informTransportableStateListener(const MSTransportable* const transportable, TransportableState to, const std::string& info) {
1287 #ifdef HAVE_FOX
1288  ScopedLocker<> lock(myTransportableStateListenerMutex, MSGlobals::gNumThreads > 1);
1289 #endif
1291  listener->transportableStateChanged(transportable, to, info);
1292  }
1293 }
1294 
1295 
1296 bool
1297 MSNet::registerCollision(const SUMOTrafficObject* collider, const SUMOTrafficObject* victim, const std::string& collisionType, const MSLane* lane, double pos) {
1298  auto it = myCollisions.find(collider->getID());
1299  if (it != myCollisions.end()) {
1300  for (Collision& old : it->second) {
1301  if (old.victim == victim->getID()) {
1302  // collision from previous step continues
1303  old.colliderSpeed = collider->getSpeed();
1304  old.victimSpeed = victim->getSpeed();
1305  old.type = collisionType;
1306  old.lane = lane;
1307  old.pos = pos;
1308  old.time = myStep;
1309  return false;
1310  }
1311  }
1312  }
1313  Collision c;
1314  c.victim = victim->getID();
1315  c.colliderType = collider->getVehicleType().getID();
1316  c.victimType = victim->getVehicleType().getID();
1317  c.colliderSpeed = collider->getSpeed();
1318  c.victimSpeed = victim->getSpeed();
1319  c.type = collisionType;
1320  c.lane = lane;
1321  c.pos = pos;
1322  c.time = myStep;
1323  myCollisions[collider->getID()].push_back(c);
1324  return true;
1325 }
1326 
1327 
1328 void
1330  for (auto it = myCollisions.begin(); it != myCollisions.end();) {
1331  for (auto it2 = it->second.begin(); it2 != it->second.end();) {
1332  if (it2->time != myStep) {
1333  it2 = it->second.erase(it2);
1334  } else {
1335  it2++;
1336  }
1337  }
1338  if (it->second.size() == 0) {
1339  it = myCollisions.erase(it);
1340  } else {
1341  it++;
1342  }
1343  }
1344 }
1345 
1346 
1347 bool
1349  return myStoppingPlaces[category == SUMO_TAG_TRAIN_STOP ? SUMO_TAG_BUS_STOP : category].add(stop->getID(), stop);
1350 }
1351 
1352 
1353 bool
1355  if (find(myTractionSubstations.begin(), myTractionSubstations.end(), substation) == myTractionSubstations.end()) {
1356  myTractionSubstations.push_back(substation);
1357  return true;
1358  }
1359  return false;
1360 }
1361 
1362 
1364 MSNet::getStoppingPlace(const std::string& id, const SumoXMLTag category) const {
1365  if (myStoppingPlaces.count(category) > 0) {
1366  return myStoppingPlaces.find(category)->second.get(id);
1367  }
1368  return nullptr;
1369 }
1370 
1371 
1372 std::string
1373 MSNet::getStoppingPlaceID(const MSLane* lane, const double pos, const SumoXMLTag category) const {
1374  if (myStoppingPlaces.count(category) > 0) {
1375  for (const auto& it : myStoppingPlaces.find(category)->second) {
1376  MSStoppingPlace* stop = it.second;
1377  if (&stop->getLane() == lane && stop->getBeginLanePosition() - POSITION_EPS <= pos && stop->getEndLanePosition() + POSITION_EPS >= pos) {
1378  return stop->getID();
1379  }
1380  }
1381  }
1382  return "";
1383 }
1384 
1385 
1388  auto it = myStoppingPlaces.find(category);
1389  if (it != myStoppingPlaces.end()) {
1390  return it->second;
1391  } else {
1392  return myEmptyStoppingPlaceCont;
1393  }
1394 }
1395 
1396 
1397 void
1400  OutputDevice& output = OutputDevice::getDeviceByOption("chargingstations-output");
1401  for (const auto& it : myStoppingPlaces.find(SUMO_TAG_CHARGING_STATION)->second) {
1402  static_cast<MSChargingStation*>(it.second)->writeChargingStationOutput(output);
1403  }
1404  }
1405 }
1406 
1407 
1408 void
1410  OutputDevice& output = OutputDevice::getDeviceByOption("railsignal-block-output");
1411  for (auto tls : myLogics->getAllLogics()) {
1412  MSRailSignal* rs = dynamic_cast<MSRailSignal*>(tls);
1413  if (rs != nullptr) {
1414  rs->writeBlocks(output);
1415  }
1416  }
1417 }
1418 
1419 
1420 void
1423  OutputDevice& output = OutputDevice::getDeviceByOption("overheadwiresegments-output");
1424  for (const auto& it : myStoppingPlaces.find(SUMO_TAG_OVERHEAD_WIRE_SEGMENT)->second) {
1425  static_cast<MSOverheadWire*>(it.second)->writeOverheadWireSegmentOutput(output);
1426  }
1427  }
1428 }
1429 
1430 
1431 void
1433  if (myTractionSubstations.size() > 0) {
1434  OutputDevice& output = OutputDevice::getDeviceByOption("substations-output");
1435  output.setPrecision(OptionsCont::getOptions().getInt("substations-output.precision"));
1436  for (auto& it : myTractionSubstations) {
1437  it->writeTractionSubstationOutput(output);
1438  }
1439  }
1440 }
1441 
1442 
1444 MSNet::findTractionSubstation(const std::string& substationId) {
1445  for (std::vector<MSTractionSubstation*>::iterator it = myTractionSubstations.begin(); it != myTractionSubstations.end(); ++it) {
1446  if ((*it)->getID() == substationId) {
1447  return *it;
1448  }
1449  }
1450  return nullptr;
1451 }
1452 
1453 
1454 bool
1455 MSNet::existTractionSubstation(const std::string& substationId) {
1456  for (std::vector<MSTractionSubstation*>::iterator it = myTractionSubstations.begin(); it != myTractionSubstations.end(); ++it) {
1457  if ((*it)->getID() == substationId) {
1458  return true;
1459  }
1460  }
1461  return false;
1462 }
1463 
1464 
1466 MSNet::getRouterTT(const int rngIndex, const MSEdgeVector& prohibited) const {
1467  if (myRouterTT.count(rngIndex) == 0) {
1468  const std::string routingAlgorithm = OptionsCont::getOptions().getString("routing-algorithm");
1469  if (routingAlgorithm == "dijkstra") {
1470  myRouterTT[rngIndex] = new DijkstraRouter<MSEdge, SUMOVehicle>(MSEdge::getAllEdges(), true, &MSNet::getTravelTime, nullptr, false, nullptr, true);
1471  } else {
1472  if (routingAlgorithm != "astar") {
1473  WRITE_WARNINGF(TL("TraCI and Triggers cannot use routing algorithm '%'. using 'astar' instead."), routingAlgorithm);
1474  }
1475  myRouterTT[rngIndex] = new AStarRouter<MSEdge, SUMOVehicle>(MSEdge::getAllEdges(), true, &MSNet::getTravelTime, nullptr, true);
1476  }
1477  }
1478  myRouterTT[rngIndex]->prohibit(prohibited);
1479  return *myRouterTT[rngIndex];
1480 }
1481 
1482 
1484 MSNet::getRouterEffort(const int rngIndex, const MSEdgeVector& prohibited) const {
1485  if (myRouterEffort.count(rngIndex) == 0) {
1487  }
1488  myRouterEffort[rngIndex]->prohibit(prohibited);
1489  return *myRouterEffort[rngIndex];
1490 }
1491 
1492 
1494 MSNet::getPedestrianRouter(const int rngIndex, const MSEdgeVector& prohibited) const {
1495  if (myPedestrianRouter.count(rngIndex) == 0) {
1496  myPedestrianRouter[rngIndex] = new MSPedestrianRouter();
1497  }
1498  myPedestrianRouter[rngIndex]->prohibit(prohibited);
1499  return *myPedestrianRouter[rngIndex];
1500 }
1501 
1502 
1504 MSNet::getIntermodalRouter(const int rngIndex, const int routingMode, const MSEdgeVector& prohibited) const {
1505  const OptionsCont& oc = OptionsCont::getOptions();
1506  const int key = rngIndex * oc.getInt("thread-rngs") + routingMode;
1507  if (myIntermodalRouter.count(key) == 0) {
1508  int carWalk = 0;
1509  for (const std::string& opt : oc.getStringVector("persontrip.transfer.car-walk")) {
1510  if (opt == "parkingAreas") {
1512  } else if (opt == "ptStops") {
1514  } else if (opt == "allJunctions") {
1516  }
1517  }
1518  // XXX there is currently no reason to combine multiple values, thus getValueString rather than getStringVector
1519  const std::string& taxiDropoff = oc.getValueString("persontrip.transfer.taxi-walk");
1520  const std::string& taxiPickup = oc.getValueString("persontrip.transfer.walk-taxi");
1521  if (taxiDropoff == "") {
1522  if (MSDevice_Taxi::getTaxi() != nullptr) {
1524  }
1525  } else if (taxiDropoff == "ptStops") {
1527  } else if (taxiDropoff == "allJunctions") {
1529  }
1530  if (taxiPickup == "") {
1531  if (MSDevice_Taxi::getTaxi() != nullptr) {
1533  }
1534  } else if (taxiPickup == "ptStops") {
1536  } else if (taxiPickup == "allJunctions") {
1538  }
1539  const std::string routingAlgorithm = OptionsCont::getOptions().getString("routing-algorithm");
1540  double taxiWait = STEPS2TIME(string2time(OptionsCont::getOptions().getString("persontrip.taxi.waiting-time")));
1541  if (routingMode == libsumo::ROUTING_MODE_COMBINED) {
1542  myIntermodalRouter[key] = new MSTransportableRouter(MSNet::adaptIntermodalRouter, carWalk, taxiWait, routingAlgorithm, routingMode, new FareModul());
1543  } else {
1544  myIntermodalRouter[key] = new MSTransportableRouter(MSNet::adaptIntermodalRouter, carWalk, taxiWait, routingAlgorithm, routingMode);
1545  }
1546  }
1547  myIntermodalRouter[key]->prohibit(prohibited);
1548  return *myIntermodalRouter[key];
1549 }
1550 
1551 
1552 void
1554  double taxiWait = STEPS2TIME(string2time(OptionsCont::getOptions().getString("persontrip.taxi.waiting-time")));
1555  // add access to all parking areas
1556  EffortCalculator* const external = router.getExternalEffort();
1557  for (const auto& stopType : myInstance->myStoppingPlaces) {
1558  // add access to all stopping places
1559  const SumoXMLTag element = stopType.first;
1560  for (const auto& i : stopType.second) {
1561  const MSEdge* const edge = &i.second->getLane().getEdge();
1562  router.getNetwork()->addAccess(i.first, edge, i.second->getBeginLanePosition(), i.second->getEndLanePosition(),
1563  0., element, false, taxiWait);
1564  if (element == SUMO_TAG_BUS_STOP) {
1565  // add access to all public transport stops
1566  for (const auto& a : i.second->getAllAccessPos()) {
1567  router.getNetwork()->addAccess(i.first, &a.lane->getEdge(), a.startPos, a.endPos, a.length, element, true, taxiWait);
1568  }
1569  if (external != nullptr) {
1570  external->addStop(router.getNetwork()->getStopEdge(i.first)->getNumericalID(), *i.second);
1571  }
1572  }
1573  }
1574  }
1577  // add access to transfer from walking to taxi-use
1579  for (MSEdge* edge : myInstance->getEdgeControl().getEdges()) {
1580  if ((edge->getPermissions() & SVC_PEDESTRIAN) != 0 && (edge->getPermissions() & SVC_TAXI) != 0) {
1581  router.getNetwork()->addCarAccess(edge, SVC_TAXI, taxiWait);
1582  }
1583  }
1584  }
1585 }
1586 
1587 
1588 bool
1590  const MSEdgeVector& edges = myEdges->getEdges();
1591  for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
1592  for (std::vector<MSLane*>::const_iterator i = (*e)->getLanes().begin(); i != (*e)->getLanes().end(); ++i) {
1593  if ((*i)->getShape().hasElevation()) {
1594  return true;
1595  }
1596  }
1597  }
1598  return false;
1599 }
1600 
1601 
1602 bool
1604  for (const MSEdge* e : myEdges->getEdges()) {
1605  if (e->getFunction() == SumoXMLEdgeFunc::WALKINGAREA) {
1606  return true;
1607  }
1608  }
1609  return false;
1610 }
1611 
1612 
1613 bool
1615  for (const MSEdge* e : myEdges->getEdges()) {
1616  if (e->getBidiEdge() != nullptr) {
1617  return true;
1618  }
1619  }
1620  return false;
1621 }
1622 
1623 bool
1624 MSNet::warnOnce(const std::string& typeAndID) {
1625  if (myWarnedOnce.find(typeAndID) == myWarnedOnce.end()) {
1626  myWarnedOnce[typeAndID] = true;
1627  return true;
1628  }
1629  return false;
1630 }
1631 
1632 void
1634  const OptionsCont& oc = OptionsCont::getOptions();
1635  clearState(string2time(oc.getString("begin")), true);
1637  // load traffic from additional files
1638  for (std::string file : oc.getStringVector("additional-files")) {
1639  // ignore failure on parsing calibrator flow
1640  MSRouteHandler rh(file, true);
1641  const long before = PROGRESS_BEGIN_TIME_MESSAGE("Loading traffic from '" + file + "'");
1642  if (!XMLSubSys::runParser(rh, file, false)) {
1643  throw ProcessError(TLF("Loading of % failed.", file));
1644  }
1645  PROGRESS_TIME_MESSAGE(before);
1646  }
1647  delete myRouteLoaders;
1649  updateGUI();
1650 }
1651 
1652 
1653 SUMOTime
1654 MSNet::loadState(const std::string& fileName, const bool catchExceptions) {
1655  // load time only
1656  const SUMOTime newTime = MSStateHandler::MSStateTimeHandler::getTime(fileName);
1657  // clean up state
1658  clearState(newTime);
1659  // load state
1660  MSStateHandler h(fileName, 0);
1661  XMLSubSys::runParser(h, fileName, false, false, false, catchExceptions);
1662  if (MsgHandler::getErrorInstance()->wasInformed()) {
1663  throw ProcessError(TLF("Loading state from '%' failed.", fileName));
1664  }
1665  // reset route loaders
1666  delete myRouteLoaders;
1668  // prevent loading errors on rewound route file
1669  MSGlobals::gStateLoaded = true;
1670 
1671  updateGUI();
1672  return newTime;
1673 }
1674 
1675 
1676 /****************************************************************************/
long long int SUMOTime
Definition: GUI.h:35
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:118
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_BUS_STOP
A bus stop.
@ 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.
@ TAXI_PICKUP_ANYWHERE
taxi customer may be picked up anywhere
@ TAXI_DROPOFF_ANYWHERE
taxi customer may exit anywhere
@ PARKING_AREAS
parking areas
@ ALL_JUNCTIONS
junctions with edges allowing the additional mode
@ TAXI_PICKUP_PT
taxi customer may be picked up at public transport stop
@ PT_STOPS
public transport stops and access
@ TAXI_DROPOFF_PT
taxi customer may be picked up at public transport stop
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:230
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
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:1022
static void clear()
Clears the dictionary.
Definition: MSEdge.cpp:1028
double getMinimumTravelTime(const SUMOVehicle *const veh) const
returns the minimum travel time for the given vehicle
Definition: MSEdge.h:473
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:172
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:178
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:2391
static const std::map< std::string, MSLaneSpeedTrigger * > & getInstances()
return all MSLaneSpeedTrigger instances
Interface for objects listening to transportable state changes.
Definition: MSNet.h:694
Interface for objects listening to vehicle state changes.
Definition: MSNet.h:635
The simulated network and simulation perfomer.
Definition: MSNet.h:89
std::map< SumoXMLTag, NamedObjectCont< MSStoppingPlace * > > myStoppingPlaces
Dictionary of bus / container stops.
Definition: MSNet.h:982
long myTraCIMillis
The overall time spent waiting for traci operations including.
Definition: MSNet.h:921
static double getEffort(const MSEdge *const e, const SUMOVehicle *const v, double t)
Returns the effort to pass an edge.
Definition: MSNet.cpp:148
bool warnOnce(const std::string &typeAndID)
return whether a warning regarding the given object shall be issued
Definition: MSNet.cpp:1624
SUMOTime loadState(const std::string &fileName, const bool catchExceptions)
load state from file and return new time
Definition: MSNet.cpp:1654
bool myLogExecutionTime
Information whether the simulation duration shall be logged.
Definition: MSNet.h:907
MSTransportableControl * myPersonControl
Controls person building and deletion;.
Definition: MSNet.h:876
void removeVehicleStateListener(VehicleStateListener *listener)
Removes a vehicle states listener.
Definition: MSNet.cpp:1249
SUMORouteLoaderControl * myRouteLoaders
Route loader for dynamic loading of routes.
Definition: MSNet.h:854
bool addStoppingPlace(const SumoXMLTag category, MSStoppingPlace *stop)
Adds a stopping place.
Definition: MSNet.cpp:1348
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:1286
SUMOTime myStateDumpPeriod
The period for writing state.
Definition: MSNet.h:940
static const NamedObjectCont< MSStoppingPlace * > myEmptyStoppingPlaceCont
Definition: MSNet.h:1003
void writeOverheadWireSegmentOutput() const
write the output generated by an overhead wire segment
Definition: MSNet.cpp:1421
void writeChargingStationOutput() const
write charging station output
Definition: MSNet.cpp:1398
std::pair< bool, NamedRTree > myLanesRTree
An RTree structure holding lane IDs.
Definition: MSNet.h:1019
bool checkBidiEdges()
check wether bidirectional edges occur in the network
Definition: MSNet.cpp:1614
VehicleState
Definition of a vehicle state.
Definition: MSNet.h:602
int myLogStepPeriod
Period between successive step-log outputs.
Definition: MSNet.h:912
MSPedestrianRouter & getPedestrianRouter(const int rngIndex, const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:1494
SUMOTime myStep
Current time step.
Definition: MSNet.h:857
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:182
bool myHasBidiEdges
Whether the network contains bidirectional rail edges.
Definition: MSNet.h:970
MSEventControl * myBeginOfTimestepEvents
Controls events executed at the begin of a time step;.
Definition: MSNet.h:890
bool addTractionSubstation(MSTractionSubstation *substation)
Adds a traction substation.
Definition: MSNet.cpp:1354
std::map< std::string, bool > myWarnedOnce
container to record warnings that shall only be issued once
Definition: MSNet.h:1006
static void initStatic()
Place for static initializations of simulation components (called after successful net build)
Definition: MSNet.cpp:190
void removeOutdatedCollisions()
remove collisions from the previous simulation step
Definition: MSNet.cpp:1329
MSJunctionControl * myJunctions
Controls junctions, realizes right-of-way rules;.
Definition: MSNet.h:882
MSVehicleRouter & getRouterEffort(const int rngIndex, const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:1484
std::vector< std::string > myPeriodicStateFiles
The names of the last K periodic state files (only only K shall be kept)
Definition: MSNet.h:938
ShapeContainer * myShapeContainer
A container for geometrical shapes;.
Definition: MSNet.h:896
std::string myStateDumpSuffix
Definition: MSNet.h:943
bool checkElevation()
check all lanes for elevation data
Definition: MSNet.cpp:1589
bool existTractionSubstation(const std::string &substationId)
return whether given electrical substation exists in the network
Definition: MSNet.cpp:1455
void removeTransportableStateListener(TransportableStateListener *listener)
Removes a transportable states listener.
Definition: MSNet.cpp:1277
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:904
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:255
bool myLogStepNumber
Information whether the number of the simulation step shall be logged.
Definition: MSNet.h:910
MMVersion myVersion
the network version
Definition: MSNet.h:976
MSEventControl * myInsertionEvents
Controls insertion events;.
Definition: MSNet.h:894
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition: MSNet.cpp:1182
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:1015
static const std::string STAGE_MOVEMENTS
Definition: MSNet.h:827
bool hasFlow(const std::string &id) const
return whether the given flow is known
Definition: MSNet.cpp:387
int myMaxTeleports
Maximum number of teleports.
Definition: MSNet.h:863
long mySimStepDuration
Definition: MSNet.h:915
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:892
static std::string getStateMessage(SimulationState state)
Returns the message to show if a certain state occurs.
Definition: MSNet.cpp:925
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:1373
bool myHasInternalLinks
Whether the network contains internal links/lanes/edges.
Definition: MSNet.h:958
void writeSubstationOutput() const
write electrical substation output
Definition: MSNet.cpp:1432
static const std::string STAGE_INSERTIONS
Definition: MSNet.h:829
long long int myPersonsMoved
Definition: MSNet.h:925
void quickReload()
reset state to the beginning without reloading the network
Definition: MSNet.cpp:1633
MSVehicleControl * myVehicleControl
Controls vehicle building and deletion;.
Definition: MSNet.h:874
MSTransportableRouter & getIntermodalRouter(const int rngIndex, const int routingMode=0, const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:1504
static void clearAll()
Clears all dictionaries.
Definition: MSNet.cpp:950
static void cleanupStatic()
Place for static initializations of simulation components (called after successful net build)
Definition: MSNet.cpp:197
void writeStatistics(const SUMOTime start, const long now) const
write statistic output to (xml) file
Definition: MSNet.cpp:558
void writeSummaryOutput()
write summary-output to (xml) file
Definition: MSNet.cpp:608
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:320
MSEdgeControl * myEdges
Controls edges, performs vehicle movement;.
Definition: MSNet.h:880
std::unique_ptr< MSDynamicShapeUpdater > myDynamicShapeUpdater
Updater for dynamic shapes that are tracking traffic objects (ensures removal of shape dynamics when ...
Definition: MSNet.h:1024
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:351
void closeSimulation(SUMOTime start, const std::string &reason="")
Closes the simulation (all files, connections, etc.)
Definition: MSNet.cpp:672
MSStoppingPlace * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Returns the named stopping place of the given category.
Definition: MSNet.cpp:1364
bool myHasElevation
Whether the network contains elevation data.
Definition: MSNet.h:964
static double getTravelTime(const MSEdge *const e, const SUMOVehicle *const v, double t)
Returns the travel time to pass an edge.
Definition: MSNet.cpp:162
MSTransportableControl * myContainerControl
Controls container building and deletion;.
Definition: MSNet.h:878
std::vector< TransportableStateListener * > myTransportableStateListeners
Container for transportable state listener.
Definition: MSNet.h:991
void writeOutput()
Write netstate, summary and detector output.
Definition: MSNet.cpp:1033
virtual void updateGUI() const
update view after simulation.loadState
Definition: MSNet.h:590
bool myAmInterrupted
whether an interrupt occured
Definition: MSNet.h:866
void simulationStep(const bool onlyMove=false)
Performs a single simulation step.
Definition: MSNet.cpp:709
void addVehicleStateListener(VehicleStateListener *listener)
Adds a vehicle states listener.
Definition: MSNet.cpp:1241
void clearState(const SUMOTime step, bool quickReload=false)
Resets events when quick-loading state.
Definition: MSNet.cpp:980
void preSimStepOutput() const
Prints the current step number.
Definition: MSNet.cpp:1205
void writeCollisions() const
write collision output to (xml) file
Definition: MSNet.cpp:536
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:934
void addTransportableStateListener(TransportableStateListener *listener)
Adds a transportable states listener.
Definition: MSNet.cpp:1269
std::vector< MSTractionSubstation * > myTractionSubstations
Dictionary of traction substations.
Definition: MSNet.h:985
SUMOTime myEdgeDataEndTime
end of loaded edgeData
Definition: MSNet.h:979
MSEdgeWeightsStorage & getWeightsStorage()
Returns the net's internal edge travel times/efforts container.
Definition: MSNet.cpp:1196
std::map< std::string, std::map< SUMOVehicleClass, double > > myRestrictions
The vehicle class specific speed restrictions.
Definition: MSNet.h:952
std::vector< std::string > myStateDumpFiles
The names for the state files.
Definition: MSNet.h:936
void addMesoType(const std::string &typeID, const MESegment::MesoEdgeType &edgeType)
Adds edge type specific meso parameters.
Definition: MSNet.cpp:360
void writeRailSignalBlocks() const
write rail signal block output
Definition: MSNet.cpp:1409
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition: MSNet.h:431
MSTLLogicControl * myLogics
Controls tls logics, realizes waiting on tls rules;.
Definition: MSNet.h:884
bool logSimulationDuration() const
Returns whether duration shall be logged.
Definition: MSNet.cpp:1167
long long int myVehiclesMoved
The overall number of vehicle movements.
Definition: MSNet.h:924
static const std::string STAGE_REMOTECONTROL
Definition: MSNet.h:830
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:1258
std::map< int, MSTransportableRouter * > myIntermodalRouter
Definition: MSNet.h:1016
std::vector< VehicleStateListener * > myVehicleStateListeners
Container for vehicle state listener.
Definition: MSNet.h:988
SimulationState simulationState(SUMOTime stopTime) const
This method returns the current simulation state. It should not modify status.
Definition: MSNet.cpp:874
long myTraCIStepDuration
The last simulation step duration.
Definition: MSNet.h:915
TransportableState
Definition of a transportable state.
Definition: MSNet.h:679
MSDetectorControl * myDetectorControl
Controls detectors;.
Definition: MSNet.h:888
bool myStepCompletionMissing
whether libsumo triggered a partial step (executeMove)
Definition: MSNet.h:860
static const std::string STAGE_LANECHANGE
Definition: MSNet.h:828
MSNet(MSVehicleControl *vc, MSEventControl *beginOfTimestepEvents, MSEventControl *endOfTimestepEvents, MSEventControl *insertionEvents, ShapeContainer *shapeCont=0)
Constructor.
Definition: MSNet.cpp:204
void addRestriction(const std::string &id, const SUMOVehicleClass svc, const double speed)
Adds a restriction for an edge type.
Definition: MSNet.cpp:345
MSVehicleRouter & getRouterTT(const int rngIndex, const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:1466
std::map< std::string, MESegment::MesoEdgeType > myMesoEdgeTypes
The edge type specific meso parameters.
Definition: MSNet.h:955
MSEdgeWeightsStorage * myEdgeWeights
The net's knowledge about edge efforts/travel times;.
Definition: MSNet.h:898
MSDynamicShapeUpdater * makeDynamicShapeUpdater()
Creates and returns a dynamic shapes updater.
Definition: MSNet.cpp:1190
virtual ~MSNet()
Destructor.
Definition: MSNet.cpp:290
std::map< int, MSVehicleRouter * > myRouterEffort
Definition: MSNet.h:1014
MSTractionSubstation * findTractionSubstation(const std::string &substationId)
find electrical substation by its id
Definition: MSNet.cpp:1444
static MSNet * myInstance
Unique instance of MSNet.
Definition: MSNet.h:851
MSInsertionControl * myInserter
Controls vehicle insertion;.
Definition: MSNet.h:886
void postSimStepOutput() const
Prints the statistics of the step at its end.
Definition: MSNet.cpp:1211
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:1173
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:1297
static const std::string STAGE_EVENTS
string constants for simstep stages
Definition: MSNet.h:826
void loadRoutes()
loads routes for the next few steps
Definition: MSNet.cpp:436
std::string myStateDumpPrefix
name components for periodic state
Definition: MSNet.h:942
bool myJunctionHigherSpeeds
Whether the network was built with higher speed on junctions.
Definition: MSNet.h:961
long mySimBeginMillis
The overall simulation duration.
Definition: MSNet.h:918
bool myHasPedestrianNetwork
Whether the network contains pedestrian network elements.
Definition: MSNet.h:967
std::map< int, MSVehicleRouter * > myRouterTT
Definition: MSNet.h:1013
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:365
void postMoveStep()
Performs the parts of the simulation step which happen after the move.
Definition: MSNet.cpp:845
bool hasInternalLinks() const
return whether the network contains internal links
Definition: MSNet.h:774
const std::string generateStatistics(const SUMOTime start, const long now)
Writes performance output and running vehicle stats.
Definition: MSNet.cpp:442
bool checkWalkingarea()
check all lanes for type walkingArea
Definition: MSNet.cpp:1603
static void adaptIntermodalRouter(MSTransportableRouter &router)
Definition: MSNet.cpp:1553
CollisionMap myCollisions
collisions in the current time step
Definition: MSNet.h:994
const NamedObjectCont< MSStoppingPlace * > & getStoppingPlaces(SumoXMLTag category) const
Definition: MSNet.cpp:1387
SimulationState simulate(SUMOTime start, SUMOTime stop)
Simulates from timestep start to stop.
Definition: MSNet.cpp:394
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:174
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 substaction 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:388
static void cleanup()
Static cleanup.
Definition: MSVehicle.cpp:393
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)
std::string getValueString(const std::string &name) const
Returns the string-value of the named option (all options)
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:60
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
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:157
static void cleanup()
Definition: Helper.cpp:677
static int postProcessRemoteControl()
return number of remote-controlled entities
Definition: Helper.cpp:1392
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