SUMO - Simulation of Urban MObility
MSNet.cpp
Go to the documentation of this file.
1 /****************************************************************************/
15 // The simulated network and simulation perfomer
16 /****************************************************************************/
17 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
18 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
19 /****************************************************************************/
20 //
21 // This file is part of SUMO.
22 // SUMO is free software: you can redistribute it and/or modify
23 // it under the terms of the GNU General Public License as published by
24 // the Free Software Foundation, either version 3 of the License, or
25 // (at your option) any later version.
26 //
27 /****************************************************************************/
28 
29 
30 // ===========================================================================
31 // included modules
32 // ===========================================================================
33 #ifdef _MSC_VER
34 #include <windows_config.h>
35 #else
36 #include <config.h>
37 #endif
38 
39 #include <string>
40 #include <iostream>
41 #include <sstream>
42 #include <typeinfo>
43 #include <algorithm>
44 #include <cassert>
45 #include <vector>
46 #include <ctime>
48 #include "MSNet.h"
49 #include "MSTransportableControl.h"
50 #include "MSEdgeControl.h"
51 #include "MSJunctionControl.h"
52 #include "MSInsertionControl.h"
53 #include "MSEventControl.h"
54 #include "MSEdge.h"
55 #include "MSJunction.h"
56 #include "MSJunctionLogic.h"
57 #include "MSLane.h"
58 #include "MSVehicleTransfer.h"
59 #include "MSRoute.h"
61 #include "trigger/MSTrigger.h"
62 #include "trigger/MSCalibrator.h"
64 #include "MSVehicleControl.h"
66 #include <utils/common/ToString.h>
74 #include <utils/shapes/Polygon.h>
76 
78 #include "output/MSFCDExport.h"
80 
81 #include "output/MSBatteryExport.h"
82 
83 #include "output/MSFullExport.h"
84 #include "output/MSQueueExport.h"
85 #include "output/MSVTKExport.h"
86 #include "output/MSXMLRawOut.h"
89 #include <utils/common/SysUtils.h>
93 #include "MSGlobals.h"
98 #include "MSContainer.h"
99 #include "MSEdgeWeightsStorage.h"
100 #include "MSStateHandler.h"
101 
102 #include <mesosim/MELoop.h>
103 
104 #ifndef NO_TRACI
106 #endif
107 
108 #ifdef CHECK_MEMORY_LEAKS
109 #include <foreign/nvwa/debug_new.h>
110 #endif // CHECK_MEMORY_LEAKS
111 
112 
113 // ===========================================================================
114 // static member definitions
115 // ===========================================================================
117 
118 const std::string MSNet::STAGE_EVENTS("events");
119 const std::string MSNet::STAGE_MOVEMENTS("move");
120 const std::string MSNet::STAGE_LANECHANGE("laneChange");
121 const std::string MSNet::STAGE_INSERTIONS("insertion");
122 
123 // ===========================================================================
124 // member method definitions
125 // ===========================================================================
126 SUMOReal
127 MSNet::getEffort(const MSEdge* const e, const SUMOVehicle* const v, SUMOReal t) {
128  SUMOReal value;
129  const MSVehicle* const veh = dynamic_cast<const MSVehicle* const>(v);
130  if (veh != 0 && veh->getWeightsStorage().retrieveExistingEffort(e, t, value)) {
131  return value;
132  }
133  if (getInstance()->getWeightsStorage().retrieveExistingEffort(e, t, value)) {
134  return value;
135  }
136  return 0;
137 }
138 
139 
140 SUMOReal
141 MSNet::getTravelTime(const MSEdge* const e, const SUMOVehicle* const v, SUMOReal t) {
142  SUMOReal value;
143  const MSVehicle* const veh = dynamic_cast<const MSVehicle* const>(v);
144  if (veh != 0 && veh->getWeightsStorage().retrieveExistingTravelTime(e, t, value)) {
145  return value;
146  }
148  return value;
149  }
150  return e->getMinimumTravelTime(v);
151 }
152 
153 
154 
155 // ---------------------------------------------------------------------------
156 // MSNet - methods
157 // ---------------------------------------------------------------------------
158 MSNet*
160  if (myInstance != 0) {
161  return myInstance;
162  }
163  throw ProcessError("A network was not yet constructed.");
164 }
165 
166 
167 MSNet::MSNet(MSVehicleControl* vc, MSEventControl* beginOfTimestepEvents,
168  MSEventControl* endOfTimestepEvents, MSEventControl* insertionEvents,
169  ShapeContainer* shapeCont):
170  myVehiclesMoved(0),
171  myHavePermissions(false),
172  myHasInternalLinks(false),
173  myHasElevation(false),
174  myRouterTTInitialized(false),
176  myRouterTTAStar(0),
177  myRouterEffort(0),
178  myPedestrianRouter(0) {
179  if (myInstance != 0) {
180  throw ProcessError("A network was already constructed.");
181  }
183  myStep = string2time(oc.getString("begin"));
184  myLogExecutionTime = !oc.getBool("no-duration-log");
185  myLogStepNumber = !oc.getBool("no-step-log");
186  myInserter = new MSInsertionControl(*vc, string2time(oc.getString("max-depart-delay")), !oc.getBool("eager-insert"), oc.getInt("max-num-vehicles"));
187  myVehicleControl = vc;
189  myEdges = 0;
190  myJunctions = 0;
191  myRouteLoaders = 0;
192  myLogics = 0;
193  myPersonControl = 0;
194  myContainerControl = 0;
195  myEdgeWeights = 0;
196  myShapeContainer = shapeCont == 0 ? new ShapeContainer() : shapeCont;
197 
198  myBeginOfTimestepEvents = beginOfTimestepEvents;
199  myEndOfTimestepEvents = endOfTimestepEvents;
200  myInsertionEvents = insertionEvents;
201  myLanesRTree.first = false;
202 
204  MSGlobals::gMesoNet = new MELoop(string2time(oc.getString("meso-recheck")));
205  }
206  myInstance = this;
207 }
208 
209 
210 
211 
212 void
214  SUMORouteLoaderControl* routeLoaders,
215  MSTLLogicControl* tlc,
216  std::vector<SUMOTime> stateDumpTimes,
217  std::vector<std::string> stateDumpFiles,
218  bool hasInternalLinks,
219  bool hasNeighs,
220  bool lefthand,
221  SUMOReal version) {
222  myEdges = edges;
223  myJunctions = junctions;
224  myRouteLoaders = routeLoaders;
225  myLogics = tlc;
226  // save the time the network state shall be saved at
227  myStateDumpTimes = stateDumpTimes;
228  myStateDumpFiles = stateDumpFiles;
229  myStateDumpPeriod = string2time(oc.getString("save-state.period"));
230  myStateDumpPrefix = oc.getString("save-state.prefix");
231  myStateDumpSuffix = oc.getString("save-state.suffix");
232 
233  // set requests/responses
235 
236  // initialise performance computation
237  if (myLogExecutionTime) {
239  }
244  myVersion = version;
245 }
246 
247 
249  // delete events first maybe they do some cleanup
252  delete myEndOfTimestepEvents;
254  delete myInsertionEvents;
255  myInsertionEvents = 0;
256  // delete controls
257  delete myJunctions;
258  delete myDetectorControl;
259  // delete mean data
260  delete myEdges;
261  delete myInserter;
262  delete myLogics;
263  delete myRouteLoaders;
264  delete myVehicleControl;
265  if (myPersonControl != 0) {
266  delete myPersonControl;
267  }
268  if (myContainerControl != 0) {
269  delete myContainerControl;
270  }
271  delete myShapeContainer;
272  delete myEdgeWeights;
273  delete myRouterTTDijkstra;
274  delete myRouterTTAStar;
275  delete myRouterEffort;
276  if (myPedestrianRouter != 0) {
277  delete myPedestrianRouter;
278  }
279  myLanesRTree.second.RemoveAll();
280  clearAll();
282  delete MSGlobals::gMesoNet;
283  }
284 // delete myPedestrianRouter;
285  myInstance = 0;
286 }
287 
288 
289 void
290 MSNet::addRestriction(const std::string& id, const SUMOVehicleClass svc, const SUMOReal speed) {
291  myRestrictions[id][svc] = speed;
292 }
293 
294 
295 const std::map<SUMOVehicleClass, SUMOReal>*
296 MSNet::getRestrictions(const std::string& id) const {
297  std::map<std::string, std::map<SUMOVehicleClass, SUMOReal> >::const_iterator i = myRestrictions.find(id);
298  if (i == myRestrictions.end()) {
299  return 0;
300  }
301  return &i->second;
302 }
303 
304 
305 int
307  // report the begin when wished
308  WRITE_MESSAGE("Simulation started with time: " + time2string(start));
309  // the simulation loop
311  myStep = start;
312  // preload the routes especially for TraCI
313  loadRoutes();
314 #ifndef NO_TRACI
315 #ifdef HAVE_PYTHON
316  if (OptionsCont::getOptions().isSet("python-script")) {
317  TraCIServer::runEmbedded(OptionsCont::getOptions().getString("python-script"));
318  closeSimulation(start);
319  WRITE_MESSAGE("Simulation ended at time: " + time2string(getCurrentTimeStep()));
320  WRITE_MESSAGE("Reason: Script ended");
321  return 0;
322  }
323 #endif
324 #endif
325  while (state == SIMSTATE_RUNNING) {
326  if (myLogStepNumber) {
328  }
329  simulationStep();
330  if (myLogStepNumber) {
332  }
333  state = simulationState(stop);
334 #ifndef NO_TRACI
335  if (state != SIMSTATE_RUNNING) {
336  if (OptionsCont::getOptions().getInt("remote-port") != 0 && !TraCIServer::wasClosed()) {
337  state = SIMSTATE_RUNNING;
338  }
339  }
340 #endif
341  }
342  // report the end when wished
343  WRITE_MESSAGE("Simulation ended at time: " + time2string(getCurrentTimeStep()));
344  WRITE_MESSAGE("Reason: " + getStateMessage(state));
345  // exit simulation loop
346  closeSimulation(start);
347  return 0;
348 }
349 
350 void
353 }
354 
355 
356 void
358  if (myLogExecutionTime) {
359  long duration = SysUtils::getCurrentMillis() - mySimBeginMillis;
360  std::ostringstream msg;
361  // print performance notice
362  msg << "Performance: " << "\n" << " Duration: " << duration << "ms" << "\n";
363  if (duration != 0) {
364  msg << " Real time factor: " << (STEPS2TIME(myStep - start) * 1000. / (SUMOReal)duration) << "\n";
365  msg.setf(std::ios::fixed , std::ios::floatfield); // use decimal format
366  msg.setf(std::ios::showpoint); // print decimal point
367  msg << " UPS: " << ((SUMOReal)myVehiclesMoved / ((SUMOReal)duration / 1000)) << "\n";
368  }
369  // print vehicle statistics
370  const std::string discardNotice = ((myVehicleControl->getLoadedVehicleNo() != myVehicleControl->getDepartedVehicleNo()) ?
371  " (Loaded: " + toString(myVehicleControl->getLoadedVehicleNo()) + ")" : "");
372  msg << "Vehicles: " << "\n"
373  << " Inserted: " << myVehicleControl->getDepartedVehicleNo() << discardNotice << "\n"
374  << " Running: " << myVehicleControl->getRunningVehicleNo() << "\n"
375  << " Waiting: " << myInserter->getWaitingVehicleNo() << "\n";
376 
378  // print optional teleport statistics
379  std::vector<std::string> reasons;
380  if (myVehicleControl->getCollisionCount() > 0) {
381  reasons.push_back("Collisions: " + toString(myVehicleControl->getCollisionCount()));
382  }
383  if (myVehicleControl->getTeleportsJam() > 0) {
384  reasons.push_back("Jam: " + toString(myVehicleControl->getTeleportsJam()));
385  }
386  if (myVehicleControl->getTeleportsYield() > 0) {
387  reasons.push_back("Yield: " + toString(myVehicleControl->getTeleportsYield()));
388  }
390  reasons.push_back("Wrong Lane: " + toString(myVehicleControl->getTeleportsWrongLane()));
391  }
392  msg << "Teleports: " << myVehicleControl->getTeleportCount() << " (" << joinToString(reasons, ", ") << ")\n";
393  }
394  if (myVehicleControl->getEmergencyStops() > 0) {
395  msg << "Emergency Stops: " << myVehicleControl->getEmergencyStops() << "\n";
396  }
397  if (myPersonControl != 0 && myPersonControl->getLoadedNumber() > 0) {
398  msg << "Persons: " << "\n"
399  << " Inserted: " << myPersonControl->getLoadedNumber() << "\n"
400  << " Running: " << myPersonControl->getRunningNumber() << "\n";
401  if (myPersonControl->getJammedNumber() > 0) {
402  msg << " Jammed: " << myPersonControl->getJammedNumber() << "\n";
403  }
404  }
405  if (OptionsCont::getOptions().getBool("duration-log.statistics")) {
407  }
408  WRITE_MESSAGE(msg.str());
409  }
411  if (OptionsCont::getOptions().getBool("vehroute-output.write-unfinished")) {
413  }
414  if (OptionsCont::getOptions().getBool("tripinfo-output.write-unfinished")) {
416  }
417 #ifndef NO_TRACI
419 #endif
420 }
421 
422 
423 void
425 #ifndef NO_TRACI
428  if (t != 0 && t->getTargetTime() != 0 && t->getTargetTime() < myStep) {
429  return;
430  }
431 #endif
432  // execute beginOfTimestepEvents
433  if (myLogExecutionTime) {
435  }
436  // simulation state output
437  std::vector<SUMOTime>::iterator timeIt = find(myStateDumpTimes.begin(), myStateDumpTimes.end(), myStep);
438  if (timeIt != myStateDumpTimes.end()) {
439  const int dist = (int)distance(myStateDumpTimes.begin(), timeIt);
441  }
442  if (myStateDumpPeriod > 0 && myStep % myStateDumpPeriod == 0) {
444  }
446 #ifdef HAVE_FOX
447  MSDevice_Routing::waitForAll();
448 #endif
451  }
452  // check whether the tls programs need to be switched
454 
457  } else {
458  // assure all lanes with vehicles are 'active'
460 
461  // compute safe velocities for all vehicles for the next few lanes
462  // also register ApproachingVehicleInformation for all links
464 
465  // decide right-of-way and execute movements
469  }
470 
471  // vehicles may change lanes
473 
476  }
477  }
478  loadRoutes();
479 
480  // persons
483  }
484  // containers
487  }
488  // insert vehicles
491 #ifdef HAVE_FOX
492  MSDevice_Routing::waitForAll();
493 #endif
496  //myEdges->patchActiveLanes(); // @note required to detect collisions on lanes that were empty before insertion. wasteful?
498  }
500 
501  // execute endOfTimestepEvents
503 
504 #ifndef NO_TRACI
505  if (TraCIServer::getInstance() != 0) {
507  }
508 #endif
509  // update and write (if needed) detector values
510  writeOutput();
511 
512  if (myLogExecutionTime) {
516  }
517  myStep += DELTA_T;
518 }
519 
520 
523 #ifndef NO_TRACI
524  if (TraCIServer::wasClosed()) {
526  }
527  if (stopTime < 0 && OptionsCont::getOptions().getInt("remote-port") == 0) {
528 #else
529  if (stopTime < 0) {
530 #endif
533  && (myInserter->getPendingFlowCount() == 0)
536  if (myPersonControl) {
538  }
539  if (myContainerControl) {
541  }
544  }
545  }
546  if (stopTime >= 0 && myStep >= stopTime) {
548  }
549  return SIMSTATE_RUNNING;
550 }
551 
552 
553 std::string
555  switch (state) {
557  return "";
559  return "The final simulation step has been reached.";
561  return "All vehicles have left the simulation.";
563  return "TraCI requested termination.";
565  return "An error occured (see log).";
567  return "Too many vehicles.";
568  default:
569  return "Unknown reason.";
570  }
571 }
572 
573 
574 void
576  // clear container
577  MSEdge::clear();
578  MSLane::clear();
579  MSRoute::clear();
587 }
588 
589 
590 void
592  // update detector values
594  const OptionsCont& oc = OptionsCont::getOptions();
595 
596  // check state dumps
597  if (oc.isSet("netstate-dump")) {
599  oc.getInt("netstate-dump.precision"));
600  }
601 
602  // check fcd dumps
603  if (OptionsCont::getOptions().isSet("fcd-output")) {
605  }
606 
607  // check emission dumps
608  if (OptionsCont::getOptions().isSet("emission-output")) {
610  oc.getInt("emission-output.precision"));
611  }
612 
613  // battery dumps
614  if (OptionsCont::getOptions().isSet("battery-output")) {
616  oc.getInt("battery-output.precision"));
617  }
618 
619  // check full dumps
620  if (OptionsCont::getOptions().isSet("full-output")) {
622  }
623 
624  // check queue dumps
625  if (OptionsCont::getOptions().isSet("queue-output")) {
627  }
628 
629  // check amitran dumps
630  if (OptionsCont::getOptions().isSet("amitran-output")) {
632  }
633 
634  // check vtk dumps
635  if (OptionsCont::getOptions().isSet("vtk-output")) {
636 
637  if (MSNet::getInstance()->getVehicleControl().getRunningVehicleNo() > 0) {
638  std::string timestep = time2string(myStep);
639  timestep = timestep.substr(0, timestep.length() - 3);
640  std::string output = OptionsCont::getOptions().getString("vtk-output");
641  std::string filename = output + "_" + timestep + ".vtp";
642 
643  OutputDevice_File dev = OutputDevice_File(filename, false);
644 
645  //build a huge mass of xml files
647 
648  }
649 
650  }
651 
652  // summary output
653  if (OptionsCont::getOptions().isSet("summary-output")) {
654  OutputDevice& od = OutputDevice::getDeviceByOption("summary-output");
655  int departedVehiclesNumber = myVehicleControl->getDepartedVehicleNo();
656  const SUMOReal meanWaitingTime = departedVehiclesNumber != 0 ? myVehicleControl->getTotalDepartureDelay() / (SUMOReal) departedVehiclesNumber : -1.;
657  int endedVehicleNumber = myVehicleControl->getEndedVehicleNo();
658  const SUMOReal meanTravelTime = endedVehicleNumber != 0 ? myVehicleControl->getTotalTravelTime() / (SUMOReal) endedVehicleNumber : -1.;
660  .writeAttr("inserted", myVehicleControl->getDepartedVehicleNo()).writeAttr("running", myVehicleControl->getRunningVehicleNo())
661  .writeAttr("waiting", myInserter->getWaitingVehicleNo()).writeAttr("ended", myVehicleControl->getEndedVehicleNo())
662  .writeAttr("meanWaitingTime", meanWaitingTime).writeAttr("meanTravelTime", meanTravelTime);
663  if (myLogExecutionTime) {
664  od.writeAttr("duration", mySimStepDuration);
665  }
666  od.closeTag();
667  }
668 
669  // write detector values
671 
672  // write link states
673  if (OptionsCont::getOptions().isSet("link-output")) {
674  OutputDevice& od = OutputDevice::getDeviceByOption("link-output");
675  od.openTag("timestep");
677  const MSEdgeVector& edges = myEdges->getEdges();
678  for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
679  const std::vector<MSLane*>& lanes = (*i)->getLanes();
680  for (std::vector<MSLane*>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
681  const std::vector<MSLink*>& links = (*j)->getLinkCont();
682  for (std::vector<MSLink*>::const_iterator k = links.begin(); k != links.end(); ++k) {
683  (*k)->writeApproaching(od, (*j)->getID());
684  }
685  }
686  }
687  od.closeTag();
688  }
689 }
690 
691 
692 bool
694  return myLogExecutionTime;
695 }
696 
697 
700  if (myPersonControl == 0) {
702  }
703  return *myPersonControl;
704 }
705 
708  if (myContainerControl == 0) {
710  }
711  return *myContainerControl;
712 }
713 
714 
717  if (myEdgeWeights == 0) {
719  }
720  return *myEdgeWeights;
721 }
722 
723 
724 void
726  std::cout << "Step #" << time2string(myStep);
727 }
728 
729 
730 void
732  if (myLogExecutionTime) {
733  std::ostringstream oss;
734  oss.setf(std::ios::fixed , std::ios::floatfield); // use decimal format
735  oss.setf(std::ios::showpoint); // print decimal point
736  oss << std::setprecision(OUTPUT_ACCURACY);
737  if (mySimStepDuration != 0) {
738  oss << " (" << mySimStepDuration << "ms ~= "
739  << (1000. / (SUMOReal) mySimStepDuration) << "*RT, ~"
741  } else {
742  oss << " (0ms ?*RT. ?";
743  }
744  oss << "UPS, vehicles"
745  << " TOT " << myVehicleControl->getDepartedVehicleNo()
746  << " ACT " << myVehicleControl->getRunningVehicleNo()
747  << ") ";
748  std::string prev = "Step #" + time2string(myStep - DELTA_T);
749  std::cout << oss.str().substr(0, 78 - prev.length());
750  }
751  std::cout << '\r';
752 }
753 
754 
755 void
757  if (find(myVehicleStateListeners.begin(), myVehicleStateListeners.end(), listener) == myVehicleStateListeners.end()) {
758  myVehicleStateListeners.push_back(listener);
759  }
760 }
761 
762 
763 void
765  std::vector<VehicleStateListener*>::iterator i = find(myVehicleStateListeners.begin(), myVehicleStateListeners.end(), listener);
766  if (i != myVehicleStateListeners.end()) {
767  myVehicleStateListeners.erase(i);
768  }
769 }
770 
771 
772 void
774  for (std::vector<VehicleStateListener*>::iterator i = myVehicleStateListeners.begin(); i != myVehicleStateListeners.end(); ++i) {
775  (*i)->vehicleStateChanged(vehicle, to);
776  }
777 }
778 
779 
780 
781 // ------ Insertion and retrieval of bus stops ------
782 bool
784  return myBusStopDict.add(busStop->getID(), busStop);
785 }
786 
787 
789 MSNet::getBusStop(const std::string& id) const {
790  return myBusStopDict.get(id);
791 }
792 
793 
794 std::string
795 MSNet::getBusStopID(const MSLane* lane, const SUMOReal pos) const {
796  const std::map<std::string, MSStoppingPlace*>& vals = myBusStopDict.getMyMap();
797  for (std::map<std::string, MSStoppingPlace*>::const_iterator it = vals.begin(); it != vals.end(); ++it) {
798  MSStoppingPlace* stop = it->second;
799  if (&stop->getLane() == lane && fabs(stop->getEndLanePosition() - pos) < POSITION_EPS) {
800  return stop->getID();
801  }
802  }
803  return "";
804 }
805 
806 // ------ Insertion and retrieval of container stops ------
807 bool
809  return myContainerStopDict.add(containerStop->getID(), containerStop);
810 }
811 
813 MSNet::getContainerStop(const std::string& id) const {
814  return myContainerStopDict.get(id);
815 }
816 
817 std::string
818 MSNet::getContainerStopID(const MSLane* lane, const SUMOReal pos) const {
819  const std::map<std::string, MSStoppingPlace*>& vals = myContainerStopDict.getMyMap();
820  for (std::map<std::string, MSStoppingPlace*>::const_iterator it = vals.begin(); it != vals.end(); ++it) {
821  MSStoppingPlace* stop = it->second;
822  if (&stop->getLane() == lane && fabs(stop->getEndLanePosition() - pos) < POSITION_EPS) {
823  return stop->getID();
824  }
825  }
826  return "";
827 }
828 
829 
830 bool
832  return myChargingStationDict.add(chargingStation->getID(), chargingStation);
833 }
834 
835 
837 MSNet::getChargingStation(const std::string& id) const {
838  return myChargingStationDict.get(id);
839 }
840 
841 
842 std::string
843 MSNet::getChargingStationID(const MSLane* lane, const SUMOReal pos) const {
844  const std::map<std::string, MSChargingStation*>& vals = myChargingStationDict.getMyMap();
845  for (std::map<std::string, MSChargingStation*>::const_iterator it = vals.begin(); it != vals.end(); ++it) {
846  MSChargingStation* chargingStation = it->second;
847  if (&chargingStation->getLane() == lane && chargingStation->getBeginLanePosition() <= pos && chargingStation->getEndLanePosition() >= pos) {
848  return chargingStation->getID();
849  }
850  }
851  return "";
852 }
853 
854 
856 MSNet::getRouterTT(const MSEdgeVector& prohibited) const {
857  if (!myRouterTTInitialized) {
858  myRouterTTInitialized = true;
859  const std::string routingAlgorithm = OptionsCont::getOptions().getString("routing-algorithm");
860  if (routingAlgorithm == "dijkstra") {
863  } else {
864  if (routingAlgorithm != "astar") {
865  WRITE_WARNING("TraCI and Triggers cannot use routing algorithm '" + routingAlgorithm + "'. using 'astar' instead.");
866  }
869  }
870  }
871  if (myRouterTTDijkstra != 0) {
872  myRouterTTDijkstra->prohibit(prohibited);
873  return *myRouterTTDijkstra;
874  } else {
875  assert(myRouterTTAStar != 0);
876  myRouterTTAStar->prohibit(prohibited);
877  return *myRouterTTAStar;
878  }
879 }
880 
881 
883 MSNet::getRouterEffort(const MSEdgeVector& prohibited) const {
884  if (myRouterEffort == 0) {
887  }
888  myRouterEffort->prohibit(prohibited);
889  return *myRouterEffort;
890 }
891 
892 
894 MSNet::getPedestrianRouter(const MSEdgeVector& prohibited) const {
895  if (myPedestrianRouter == 0) {
897  }
898  myPedestrianRouter->prohibit(prohibited);
899  return *myPedestrianRouter;
900 }
901 
902 
903 const NamedRTree&
905  if (!myLanesRTree.first) {
906  MSLane::fill(myLanesRTree.second);
907  myLanesRTree.first = true;
908  }
909  return myLanesRTree.second;
910 }
911 
912 
913 bool
915  const MSEdgeVector& edges = myEdges->getEdges();
916  for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
917  for (std::vector<MSLane*>::const_iterator i = (*e)->getLanes().begin(); i != (*e)->getLanes().end(); ++i) {
918  if ((*i)->getShape().hasElevation()) {
919  return true;
920  }
921  }
922  }
923  return false;
924 }
925 
926 /****************************************************************************/
std::string myStateDumpSuffix
Definition: MSNet.h:744
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:59
AStarRouter< MSEdge, SUMOVehicle, prohibited_withPermissions< MSEdge, SUMOVehicle > > * myRouterTTAStar
Definition: MSNet.h:789
bool hasNonWaiting() const
checks whether any transportable is still engaged in walking / stopping
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:257
Computes the shortest path through a network using the Dijkstra algorithm.
void prohibit(const std::vector< E *> &toProhibit)
int getEndedVehicleNo() const
Returns the number of removed vehicles.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:82
long long int SUMOTime
Definition: SUMOTime.h:43
Interface for objects listening to vehicle state changes.
Definition: MSNet.h:564
long mySimStepEnd
Definition: MSNet.h:722
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
void loadNext(SUMOTime step)
loads the next routes up to and including the given time step
void removeVehicleStateListener(VehicleStateListener *listener)
Removes a vehicle states listener.
Definition: MSNet.cpp:764
MSEventControl * myEndOfTimestepEvents
Controls events executed at the end of a time step;.
Definition: MSNet.h:701
static SUMOReal getEffort(const MSEdge *const e, const SUMOVehicle *const v, SUMOReal t)
Returns the effort to pass an edge.
Definition: MSNet.cpp:127
int getRunningVehicleNo() const
Returns the number of build and inserted, but not yet deleted vehicles.
SUMOReal version() const
return the network version
Definition: MSNet.h:659
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
SUMOReal getTotalDepartureDelay() const
Returns the total departure delay.
int getLoadedVehicleNo() const
Returns the number of build vehicles.
A lane area vehicles can halt at.
The simulation contains too many vehicles (.
Definition: MSNet.h:110
const NamedRTree & getLanesRTree() const
Returns an RTree that contains lane IDs.
Definition: MSNet.cpp:904
virtual bool add(const std::string &id, T item)
Adds an item.
void patchActiveLanes()
Resets information whether a lane is active for all lanes.
int getLoadedNumber() const
Returns the number of build transportables.
static void fill(RTREE &into)
Fills the given RTree with lane instances.
Definition: MSLane.cpp:1326
MSVehicleControl * myVehicleControl
Controls vehicle building and deletion;.
Definition: MSNet.h:683
void updateDetectors(const SUMOTime step)
Computes detector values.
std::vector< SUMOTime > myStateDumpTimes
Times at which a state shall be written.
Definition: MSNet.h:737
virtual void execute(SUMOTime time)
Executes time-dependant commands.
DijkstraRouterEffort< MSEdge, SUMOVehicle, prohibited_withPermissions< MSEdge, SUMOVehicle > > * myRouterEffort
Definition: MSNet.h:790
T get(const std::string &id) const
Retrieves an item.
int simulate(SUMOTime start, SUMOTime stop)
Simulates from timestep start to stop.
Definition: MSNet.cpp:306
bool logSimulationDuration() const
Returns whether duration shall be logged.
Definition: MSNet.cpp:693
void changeLanes(SUMOTime t)
Moves (precomputes) critical vehicles.
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:59
A RT-tree for efficient storing of SUMO&#39;s Named objects.
Definition: NamedRTree.h:72
Computes the shortest path through a network using the A* algorithm.
Definition: AStarRouter.h:71
SUMOReal getEndLanePosition() const
Returns the end position of this stop.
bool addBusStop(MSStoppingPlace *busStop)
Adds a bus stop.
Definition: MSNet.cpp:783
bool hasNeighs() const
return whether the network contains explicit neighbor lanes
Definition: MSNet.h:644
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:159
MSPedestrianRouterDijkstra & getPedestrianRouter(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:894
bool myHavePermissions
Whether the network contains edges which not all vehicles may pass.
Definition: MSNet.h:750
SUMOTime DELTA_T
Definition: SUMOTime.cpp:39
MSEdgeControl * myEdges
Controls edges, performs vehicle movement;.
Definition: MSNet.h:689
The final simulation step has been performed.
Definition: MSNet.h:102
void writeOutput(SUMOTime step, bool closing)
Writes the output to be generated within the given time step.
std::vector< std::string > myStateDumpFiles
The names for the state files.
Definition: MSNet.h:739
bool myLogExecutionTime
Information whether the simulation duration shall be logged.
Definition: MSNet.h:716
int getActiveVehicleCount() const
Returns the number of build vehicles that have not been removed or need to wait for a passenger or a ...
Storage for geometrical objects.
static const std::string STAGE_LANECHANGE
Definition: MSNet.h:801
static void write(OutputDevice &of, SUMOTime timestep)
Dumping a hugh List of Parameters available in the Simulation.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
NamedObjectCont< MSStoppingPlace * > myContainerStopDict
Dictionary of container stops.
Definition: MSNet.h:774
const std::string & getID() const
Returns the id.
Definition: Named.h:66
Detectors container; responsible for string and output generation.
bool myLefthand
Whether the network was built for left-hand traffic.
Definition: MSNet.h:765
A storage for edge travel times and efforts.
MSChargingStation * getChargingStation(const std::string &id) const
Returns the named charging station.
Definition: MSNet.cpp:837
void detectCollisions(SUMOTime timestep, const std::string &stage)
Detect collisions.
SUMOReal getMinimumTravelTime(const SUMOVehicle *const veh) const
returns the minimum travel time for the given vehicle
Definition: MSEdge.h:448
void addVehicleStateListener(VehicleStateListener *listener)
Adds a vehicle states listener.
Definition: MSNet.cpp:756
SimulationState
Possible states of a simulation - running or stopped with different reasons.
Definition: MSNet.h:98
MSPedestrianRouterDijkstra * myPedestrianRouter
Definition: MSNet.h:791
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
The simulated network and simulation perfomer.
Definition: MSNet.h:93
bool retrieveExistingEffort(const MSEdge *const e, const SUMOReal t, SUMOReal &value) const
Returns an effort for an edge and time if stored.
Computes the shortest path through a network using the Dijkstra algorithm.
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:69
ShapeContainer * myShapeContainer
A container for geometrical shapes;.
Definition: MSNet.h:705
std::pair< bool, NamedRTree > myLanesRTree
An RTree structure holding lane IDs.
Definition: MSNet.h:795
Container for junctions; performs operations on all stored junctions.
DijkstraRouterTT< MSEdge, SUMOVehicle, prohibited_withPermissions< MSEdge, SUMOVehicle > > * myRouterTTDijkstra
Definition: MSNet.h:788
static bool gCheck4Accidents
Definition: MSGlobals.h:80
#define OUTPUT_ACCURACY
Definition: config.h:163
static void write(OutputDevice &of, SUMOTime timestep)
Export the queueing length in front of a junction (very experimental!)
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition: MSNet.cpp:707
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:57
void postProcessVTD()
A class that stores and controls tls and switching of their programs.
A road/street connecting two junctions.
Definition: MSEdge.h:80
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
std::string getBusStopID(const MSLane *lane, const SUMOReal pos) const
Returns the bus stop close to the given position.
Definition: MSNet.cpp:795
long long int myVehiclesMoved
The overall number of vehicle movements.
Definition: MSNet.h:728
long mySimStepBegin
The last simulation step begin, end and duration.
Definition: MSNet.h:722
static void close()
request termination of connection
The simulation does not contain further vehicles.
Definition: MSNet.h:104
SUMOReal getBeginLanePosition() const
Returns the begin position of this stop.
static void generateOutputForUnfinished()
generate output for vehicles which are still in the network
An error occured during the simulation step.
Definition: MSNet.h:108
static void clear()
Clears the dictionary (delete all known routes, too)
Definition: MSRoute.cpp:178
The main mesocopic simulation loop.
Definition: MELoop.h:56
void writeOutput()
Write netstate, summary and detector output.
Definition: MSNet.cpp:591
SimulationState simulationState(SUMOTime stopTime) const
Called after a simulation step, this method returns the current simulation state. ...
Definition: MSNet.cpp:522
static std::string printStatistics()
get statistics for printing to stdout
MSInsertionControl * myInserter
Controls vehicle insertion;.
Definition: MSNet.h:695
Representation of a vehicle.
Definition: SUMOVehicle.h:66
bool myHasNeighs
Whether the network contains explicit neighbor lanes.
Definition: MSNet.h:759
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 hasNeighs, bool lefthand, SUMOReal version)
Closes the network&#39;s building process.
Definition: MSNet.cpp:213
void checkInsertions(SUMOTime time)
Checks "movement" of stored vehicles.
int emitVehicles(SUMOTime time)
Emits vehicles that want to depart at the given time.
SUMORouteLoaderControl * myRouteLoaders
Route loader for dynamic loading of routes.
Definition: MSNet.h:672
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:699
void prohibit(const std::vector< E *> &toProhibit)
void closeSimulation(SUMOTime start)
Closes the simulation (all files, connections, etc.)
Definition: MSNet.cpp:357
bool myLogStepNumber
Information whether the number of the simulation step shall be logged.
Definition: MSNet.h:719
int getTeleportsYield() const
return the number of teleports due to vehicles stuck on a minor road
An output device that encapsulates an ofstream.
static void clear()
Clears the dictionary.
Definition: MSEdge.cpp:712
std::string getContainerStopID(const MSLane *lane, const SUMOReal pos) const
Returns the container stop close to the given position.
Definition: MSNet.cpp:818
SUMOTime getTargetTime()
Definition: TraCIServer.h:79
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:307
const IDMap & getMyMap() const
static SUMOReal getTravelTime(const MSEdge *const e, const SUMOVehicle *const v, SUMOReal t)
Returns the travel time to pass an edge.
Definition: MSNet.cpp:141
MSDetectorControl * myDetectorControl
Controls detectors;.
Definition: MSNet.h:697
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
void postSimStepOutput() const
Prints the statistics of the step at its end.
Definition: MSNet.cpp:731
Stores edges and lanes, performs moving of vehicle.
Definition: MSEdgeControl.h:74
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
MSTLLogicControl * myLogics
Controls tls logics, realizes waiting on tls rules;.
Definition: MSNet.h:693
static void write(OutputDevice &of, SUMOTime timestep)
Produce a VTK output to use with Tools like ParaView.
Definition: MSVTKExport.cpp:60
The connection to a client was closed by the client.
Definition: MSNet.h:106
The simulation is running.
Definition: MSNet.h:100
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:254
int getEmergencyStops() const
return the number of emergency stops
SUMOTime string2time(const std::string &r)
Definition: SUMOTime.cpp:46
void check2Switch(SUMOTime step)
Checks whether any WAUT is trying to switch a tls into another program.
#define POSITION_EPS
Definition: config.h:187
bool hasInternalLinks() const
return whether the network contains internal links
Definition: MSNet.h:639
bool hasTransportables() const
checks whether any transportable waits to finish her plan
int getTeleportsJam() const
return the number of teleports due to jamming
std::map< std::string, std::map< SUMOVehicleClass, SUMOReal > > myRestrictions
The vehicle class specific speed restrictions.
Definition: MSNet.h:753
static void cleanup()
properly deletes all trigger instances
Definition: MSTrigger.cpp:47
PedestrianRouterDijkstra< MSEdge, MSLane, MSJunction, MSVehicle > MSPedestrianRouterDijkstra
Definition: MSNet.h:114
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
SUMOReal myVersion
the network version
Definition: MSNet.h:768
TraCI server used to control sumo by a remote TraCI client.
Definition: TraCIServer.h:73
static void generateOutputForUnfinished()
generate vehroute output for vehicles which are still in the network
bool lefthand() const
return whether the network was built for lefthand traffic
Definition: MSNet.h:654
SUMOTime myStateDumpPeriod
The period for writing state.
Definition: MSNet.h:741
int getTeleportsWrongLane() const
return the number of teleports due to vehicles stuck on the wrong lane
Inserts vehicles into the network when their departure time is reached.
void postloadInitContainer()
Closes building of junctions.
void abortWaiting()
informes about all waiting vehicles (deletion in destructor)
VehicleState
Definition of a vehicle state.
Definition: MSNet.h:537
static MSVehicleTransfer * getInstance()
Returns the instance of this object.
static const std::string STAGE_MOVEMENTS
Definition: MSNet.h:800
static void processCommandsUntilSimStep(SUMOTime step)
process all commands until a simulation step is wanted
std::vector< VehicleStateListener * > myVehicleStateListeners
Container for vehicle state listener.
Definition: MSNet.h:780
static MSNet * myInstance
Unique instance of MSNet.
Definition: MSNet.h:669
MSStoppingPlace * getContainerStop(const std::string &id) const
Returns the named container stop.
Definition: MSNet.cpp:813
bool isEmpty()
Returns whether events are in the que.
static void clearAll()
Clears all dictionaries.
Definition: MSNet.cpp:575
bool myRouterTTInitialized
Definition: MSNet.h:787
void planMovements(SUMOTime t)
Compute safe velocities for all vehicles based on positions and speeds from the last time step...
void executeMovements(SUMOTime t)
Executes planned vehicle movements with regards to right-of-way.
bool addContainerStop(MSStoppingPlace *containerStop)
Adds a container stop.
Definition: MSNet.cpp:808
bool addChargingStation(MSChargingStation *chargingStation)
Adds a chargingg station.
Definition: MSNet.cpp:831
void close(SUMOTime step)
Closes the detector outputs.
MSTransportableControl * myContainerControl
Controls container building and deletion;.
Definition: MSNet.h:687
MSJunctionControl * myJunctions
Controls junctions, realizes right-of-way rules;.
Definition: MSNet.h:691
int getWaitingVehicleNo() const
Returns the number of waiting vehicles.
void abortWaiting()
aborts the plan for any transportable that is still waiting for a ride
static void clear()
Clears the dictionary.
Definition: MSLane.cpp:1309
static void write(OutputDevice &of, SUMOTime timestep, int precision)
Writes the complete network state of the given edges into the given device.
MSTransportableControl * myPersonControl
Controls person building and deletion;.
Definition: MSNet.h:685
static const MSEdgeVector & getAllEdges()
Returns all edges with a numerical id.
Definition: MSEdge.cpp:706
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
bool checkElevation()
check all lanes for elevation data
Definition: MSNet.cpp:914
int getPendingFlowCount() const
Returns the number of flows that are still active.
static void cleanup()
remove state at simulation end
Definition: MSPModel.cpp:81
void preSimStepOutput() const
Prints the current step number.
Definition: MSNet.cpp:725
static TraCIServer * getInstance()
Definition: TraCIServer.h:82
MSEventControl * myBeginOfTimestepEvents
Controls events executed at the begin of a time step;.
Definition: MSNet.h:699
A storage for options typed value containers)
Definition: OptionsCont.h:99
static void cleanup()
removes remaining vehicleInformation in sVehicles
MSEdgeWeightsStorage * myEdgeWeights
The net&#39;s knowledge about edge efforts/travel times;.
Definition: MSNet.h:707
MSNet(MSVehicleControl *vc, MSEventControl *beginOfTimestepEvents, MSEventControl *endOfTimestepEvents, MSEventControl *insertionEvents, ShapeContainer *shapeCont=0)
Constructor.
Definition: MSNet.cpp:167
void checkWaiting(MSNet *net, const SUMOTime time)
checks whether any transportables waiting time is over
static void write(OutputDevice &of, const SUMOTime timestep)
Writes the complete network state into the given device.
void addRestriction(const std::string &id, const SUMOVehicleClass svc, const SUMOReal speed)
Adds a restriction for an edge type.
Definition: MSNet.cpp:290
static MELoop * gMesoNet
mesoscopic simulation infrastructure
Definition: MSGlobals.h:107
void informVehicleStateListener(const SUMOVehicle *const vehicle, VehicleState to)
Informs all added listeners about a vehicle&#39;s state change.
Definition: MSNet.cpp:773
SUMOReal getTotalTravelTime() const
Returns the total travel time.
static void cleanup()
cleanup remaining data structures
const MSEdgeVector & getEdges() const
Returns loaded edges.
const MSEdgeWeightsStorage & getWeightsStorage() const
Returns the vehicle&#39;s internal edge travel times/efforts container.
Definition: MSVehicle.cpp:694
long mySimBeginMillis
The overall simulation duration.
Definition: MSNet.h:725
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:188
virtual ~MSNet()
Destructor.
Definition: MSNet.cpp:248
bool myHasElevation
Whether the network contains elevation data.
Definition: MSNet.h:762
static void write(OutputDevice &of, SUMOTime timestep, int precision)
Writes the complete network state of the given edges into the given device.
std::string myStateDumpPrefix
name components for periodic state
Definition: MSNet.h:743
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
static void cleanup()
deletes the router instance
bool closeTag()
Closes the most recently opened tag.
#define SUMOReal
Definition: config.h:213
static std::string getStateMessage(SimulationState state)
Returns the message to show if a certain state occurs.
Definition: MSNet.cpp:554
NamedObjectCont< MSChargingStation * > myChargingStationDict
Dictionary of charging Stations.
Definition: MSNet.h:777
SUMOTime myStep
Current time step.
Definition: MSNet.h:675
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:856
The class responsible for building and deletion of vehicles.
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:77
int getDepartedVehicleNo() const
Returns the number of inserted vehicles.
void simulationStep()
Performs a single simulation step.
Definition: MSNet.cpp:424
static long getCurrentMillis()
Returns the current time in milliseconds.
Definition: SysUtils.cpp:50
int getRunningNumber() const
Returns the number of build and inserted, but not yet deleted transportables.
const MSLane & getLane() const
Returns the lane this stop is located at.
void simulate(SUMOTime tMax)
Perform simulation up to the given time.
Definition: MELoop.cpp:73
void loadRoutes()
loads routes for the next few steps
Definition: MSNet.cpp:351
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:201
static const std::string STAGE_INSERTIONS
Definition: MSNet.h:802
MSEventControl * myInsertionEvents
Controls insertion events;.
Definition: MSNet.h:703
static bool gUseMesoSim
Definition: MSGlobals.h:95
int getCollisionCount() const
return the number of collisions
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
long mySimStepDuration
Definition: MSNet.h:722
MSStoppingPlace * getBusStop(const std::string &id) const
Returns the named bus stop.
Definition: MSNet.cpp:789
NamedObjectCont< MSStoppingPlace * > myBusStopDict
Dictionary of bus stops.
Definition: MSNet.h:771
static bool wasClosed()
check whether close was requested
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterEffort(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:883
int getTeleportCount() const
return the number of teleports (including collisions)
Stores time-dependant events and executes them at the proper time.
bool retrieveExistingTravelTime(const MSEdge *const e, const SUMOReal t, SUMOReal &value) const
Returns a travel time for an edge and time if stored.
bool myHasInternalLinks
Whether the network contains internal links/lanes/edges.
Definition: MSNet.h:756
std::string getChargingStationID(const MSLane *lane, const SUMOReal pos) const
Returns the charging station close to the given position.
Definition: MSNet.cpp:843
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
static void cleanup()
remove state at simulation end
void determineCandidates(SUMOTime time)
Checks for all vehicles whether they can be emitted.
static void saveState(const std::string &file, SUMOTime step)
Saves the current state.
const std::map< SUMOVehicleClass, SUMOReal > * getRestrictions(const std::string &id) const
Returns the restrictions for an edge type If no restrictions are present, 0 is returned.
Definition: MSNet.cpp:296
MSEdgeWeightsStorage & getWeightsStorage()
Returns the net&#39;s internal edge travel times/efforts container.
Definition: MSNet.cpp:716
static const std::string STAGE_EVENTS
string constants for simstep stages
Definition: MSNet.h:799
int getJammedNumber() const
Returns the number of times a transportables was jammed.