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-2015 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 "MSPersonControl.h"
50 #include "MSContainerControl.h"
51 #include "MSEdgeControl.h"
52 #include "MSJunctionControl.h"
53 #include "MSInsertionControl.h"
54 #include "MSEventControl.h"
55 #include "MSEdge.h"
56 #include "MSJunction.h"
57 #include "MSJunctionLogic.h"
58 #include "MSLane.h"
59 #include "MSVehicleTransfer.h"
60 #include "MSRoute.h"
62 #include "trigger/MSTrigger.h"
63 #include "trigger/MSCalibrator.h"
65 #include "MSVehicleControl.h"
67 #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 #ifdef HAVE_INTERNAL
103 #include <mesosim/MELoop.h>
105 #endif
106 
107 #ifndef NO_TRACI
109 #endif
110 
111 #ifdef CHECK_MEMORY_LEAKS
112 #include <foreign/nvwa/debug_new.h>
113 #endif // CHECK_MEMORY_LEAKS
114 
115 
116 // ===========================================================================
117 // static member definitions
118 // ===========================================================================
120 
121 const std::string MSNet::STAGE_EVENTS("events");
122 const std::string MSNet::STAGE_MOVEMENTS("move");
123 const std::string MSNet::STAGE_LANECHANGE("laneChange");
124 const std::string MSNet::STAGE_INSERTIONS("insertion");
125 
126 // ===========================================================================
127 // member method definitions
128 // ===========================================================================
129 SUMOReal
130 MSNet::getEffort(const MSEdge* const e, const SUMOVehicle* const v, SUMOReal t) {
131  SUMOReal value;
132  const MSVehicle* const veh = dynamic_cast<const MSVehicle* const>(v);
133  if (veh != 0 && veh->getWeightsStorage().retrieveExistingEffort(e, t, value)) {
134  return value;
135  }
136  if (getInstance()->getWeightsStorage().retrieveExistingEffort(e, t, value)) {
137  return value;
138  }
139  return 0;
140 }
141 
142 
143 SUMOReal
144 MSNet::getTravelTime(const MSEdge* const e, const SUMOVehicle* const v, SUMOReal t) {
145  SUMOReal value;
146  const MSVehicle* const veh = dynamic_cast<const MSVehicle* const>(v);
147  if (veh != 0 && veh->getWeightsStorage().retrieveExistingTravelTime(e, t, value)) {
148  return value;
149  }
151  return value;
152  }
153  return e->getMinimumTravelTime(v);
154 }
155 
156 
157 
158 // ---------------------------------------------------------------------------
159 // MSNet - methods
160 // ---------------------------------------------------------------------------
161 MSNet*
163  if (myInstance != 0) {
164  return myInstance;
165  }
166  throw ProcessError("A network was not yet constructed.");
167 }
168 
169 
170 MSNet::MSNet(MSVehicleControl* vc, MSEventControl* beginOfTimestepEvents,
171  MSEventControl* endOfTimestepEvents, MSEventControl* insertionEvents,
172  ShapeContainer* shapeCont):
173  myVehiclesMoved(0),
174  myHavePermissions(false),
175  myHasInternalLinks(false),
176  myHasElevation(false),
177  myRouterTTInitialized(false),
179  myRouterTTAStar(0),
180  myRouterEffort(0),
181  myPedestrianRouter(0) {
182  if (myInstance != 0) {
183  throw ProcessError("A network was already constructed.");
184  }
186  myStep = string2time(oc.getString("begin"));
187  myLogExecutionTime = !oc.getBool("no-duration-log");
188  myLogStepNumber = !oc.getBool("no-step-log");
189  myInserter = new MSInsertionControl(*vc, string2time(oc.getString("max-depart-delay")), !oc.getBool("eager-insert"), oc.getInt("max-num-vehicles"));
190  myVehicleControl = vc;
192  myEdges = 0;
193  myJunctions = 0;
194  myRouteLoaders = 0;
195  myLogics = 0;
196  myPersonControl = 0;
197  myContainerControl = 0;
198  myEdgeWeights = 0;
199  myShapeContainer = shapeCont == 0 ? new ShapeContainer() : shapeCont;
200 
201  myBeginOfTimestepEvents = beginOfTimestepEvents;
202  myEndOfTimestepEvents = endOfTimestepEvents;
203  myInsertionEvents = insertionEvents;
204  myLanesRTree.first = false;
205 
206 #ifdef HAVE_INTERNAL
208  MSGlobals::gMesoNet = new MELoop(string2time(oc.getString("meso-recheck")));
209  }
210 #endif
211  myInstance = this;
212 }
213 
214 
215 
216 
217 void
219  SUMORouteLoaderControl* routeLoaders,
220  MSTLLogicControl* tlc,
221  std::vector<SUMOTime> stateDumpTimes,
222  std::vector<std::string> stateDumpFiles,
223  bool hasInternalLinks,
224  bool lefthand,
225  SUMOReal version) {
226  myEdges = edges;
227  myJunctions = junctions;
228  myRouteLoaders = routeLoaders;
229  myLogics = tlc;
230  // save the time the network state shall be saved at
231  myStateDumpTimes = stateDumpTimes;
232  myStateDumpFiles = stateDumpFiles;
233 
234  // set requests/responses
236 
237  // initialise performance computation
238  if (myLogExecutionTime) {
240  }
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  myLanesRTree.second.RemoveAll();
277  clearAll();
278 #ifdef HAVE_INTERNAL
280  delete MSGlobals::gMesoNet;
281  }
282 #endif
283  myInstance = 0;
284 }
285 
286 
287 void
288 MSNet::addRestriction(const std::string& id, const SUMOVehicleClass svc, const SUMOReal speed) {
289  myRestrictions[id][svc] = speed;
290 }
291 
292 
293 const std::map<SUMOVehicleClass, SUMOReal>*
294 MSNet::getRestrictions(const std::string& id) const {
295  std::map<std::string, std::map<SUMOVehicleClass, SUMOReal> >::const_iterator i = myRestrictions.find(id);
296  if (i == myRestrictions.end()) {
297  return 0;
298  }
299  return &i->second;
300 }
301 
302 
303 int
305  // report the begin when wished
306  WRITE_MESSAGE("Simulation started with time: " + time2string(start));
307  // the simulation loop
309  myStep = start;
310  // preload the routes especially for TraCI
311  loadRoutes();
312 #ifndef NO_TRACI
313 #ifdef HAVE_PYTHON
314  if (OptionsCont::getOptions().isSet("python-script")) {
315  TraCIServer::runEmbedded(OptionsCont::getOptions().getString("python-script"));
316  closeSimulation(start);
317  WRITE_MESSAGE("Simulation ended at time: " + time2string(getCurrentTimeStep()));
318  WRITE_MESSAGE("Reason: Script ended");
319  return 0;
320  }
321 #endif
322 #endif
323  while (state == SIMSTATE_RUNNING) {
324  if (myLogStepNumber) {
326  }
327  simulationStep();
328  if (myLogStepNumber) {
330  }
331  state = simulationState(stop);
332 #ifndef NO_TRACI
333  if (state != SIMSTATE_RUNNING) {
334  if (OptionsCont::getOptions().getInt("remote-port") != 0 && !TraCIServer::wasClosed()) {
335  state = SIMSTATE_RUNNING;
336  }
337  }
338 #endif
339  }
340  // report the end when wished
341  WRITE_MESSAGE("Simulation ended at time: " + time2string(getCurrentTimeStep()));
342  WRITE_MESSAGE("Reason: " + getStateMessage(state));
343  // exit simulation loop
344  closeSimulation(start);
345  return 0;
346 }
347 
348 void
351 }
352 
353 
354 void
356  if (myLogExecutionTime) {
357  long duration = SysUtils::getCurrentMillis() - mySimBeginMillis;
358  std::ostringstream msg;
359  // print performance notice
360  msg << "Performance: " << "\n" << " Duration: " << duration << "ms" << "\n";
361  if (duration != 0) {
362  msg << " Real time factor: " << (STEPS2TIME(myStep - start) * 1000. / (SUMOReal)duration) << "\n";
363  msg.setf(std::ios::fixed , std::ios::floatfield); // use decimal format
364  msg.setf(std::ios::showpoint); // print decimal point
365  msg << " UPS: " << ((SUMOReal)myVehiclesMoved / ((SUMOReal)duration / 1000)) << "\n";
366  }
367  // print vehicle statistics
368  const std::string discardNotice = ((myVehicleControl->getLoadedVehicleNo() != myVehicleControl->getDepartedVehicleNo()) ?
369  " (Loaded: " + toString(myVehicleControl->getLoadedVehicleNo()) + ")" : "");
370  msg << "Vehicles: " << "\n"
371  << " Inserted: " << myVehicleControl->getDepartedVehicleNo() << discardNotice << "\n"
372  << " Running: " << myVehicleControl->getRunningVehicleNo() << "\n"
373  << " Waiting: " << myInserter->getWaitingVehicleNo() << "\n";
374 
375  if (myVehicleControl->getTeleportCount() > 0) {
376  // print optional teleport statistics
377  std::vector<std::string> reasons;
378  if (myVehicleControl->getCollisionCount() > 0) {
379  reasons.push_back("Collisions: " + toString(myVehicleControl->getCollisionCount()));
380  }
381  if (myVehicleControl->getTeleportsJam() > 0) {
382  reasons.push_back("Jam: " + toString(myVehicleControl->getTeleportsJam()));
383  }
384  if (myVehicleControl->getTeleportsYield() > 0) {
385  reasons.push_back("Yield: " + toString(myVehicleControl->getTeleportsYield()));
386  }
388  reasons.push_back("Wrong Lane: " + toString(myVehicleControl->getTeleportsWrongLane()));
389  }
390  msg << "Teleports: " << myVehicleControl->getTeleportCount() << " (" << joinToString(reasons, ", ") << ")\n";
391  }
392  if (myVehicleControl->getEmergencyStops() > 0) {
393  msg << "Emergency Stops: " << myVehicleControl->getEmergencyStops() << "\n";
394  }
396  msg << "Persons: " << "\n"
397  << " Inserted: " << myPersonControl->getLoadedPersonNumber() << "\n"
398  << " Running: " << myPersonControl->getRunningPersonNumber() << "\n";
400  msg << " Jammed: " << myPersonControl->getJammedPersonNumber() << "\n";
401  }
402  }
403  if (OptionsCont::getOptions().getBool("duration-log.statistics")) {
405  }
406  WRITE_MESSAGE(msg.str());
407  }
409  if (OptionsCont::getOptions().getBool("vehroute-output.write-unfinished")) {
411  }
412  if (OptionsCont::getOptions().getBool("tripinfo-output.write-unfinished")) {
414  }
415 #ifndef NO_TRACI
417 #endif
418 }
419 
420 
421 void
423 #ifndef NO_TRACI
426  if (t != 0 && t->getTargetTime() != 0 && t->getTargetTime() < myStep) {
427  return;
428  }
429 #endif
430  // execute beginOfTimestepEvents
431  if (myLogExecutionTime) {
433  }
434  // simulation state output
435  std::vector<SUMOTime>::iterator timeIt = find(myStateDumpTimes.begin(), myStateDumpTimes.end(), myStep);
436  if (timeIt != myStateDumpTimes.end()) {
437  const int dist = (int)distance(myStateDumpTimes.begin(), timeIt);
439  }
441 #ifdef HAVE_FOX
442  MSDevice_Routing::waitForAll();
443 #endif
446  }
447  // check whether the tls programs need to be switched
449 
450 #ifdef HAVE_INTERNAL
452  MSGlobals::gMesoNet->simulate(myStep);
453  } else {
454 #endif
455 
456  // assure all lanes with vehicles are 'active'
458 
459  // compute safe velocities for all vehicles for the next few lanes
460  // also register ApproachingVehicleInformation for all links
462 
463  // decide right-of-way and execute movements
467  }
468 
469  // vehicles may change lanes
471 
474  }
475 #ifdef HAVE_INTERNAL
476  }
477 #endif
478  loadRoutes();
479 
480  // persons
481  if (myPersonControl != 0 && myPersonControl->hasPersons()) {
483  }
484  // insert vehicles
485  myInserter->determineCandidates(myStep); // containers
486  if (myContainerControl != 0) {
488  }
490 #ifdef HAVE_FOX
491  MSDevice_Routing::waitForAll();
492 #endif
496  }
498 
499  // execute endOfTimestepEvents
501 
502 #ifndef NO_TRACI
503  if (TraCIServer::getInstance() != 0) {
505  }
506 #endif
507  // update and write (if needed) detector values
508  writeOutput();
509 
510  if (myLogExecutionTime) {
514  }
515  myStep += DELTA_T;
516 }
517 
518 
521 #ifndef NO_TRACI
522  if (TraCIServer::wasClosed()) {
524  }
525  if (stopTime < 0 && OptionsCont::getOptions().getInt("remote-port") == 0) {
526 #else
527  if (stopTime < 0) {
528 #endif
531  && (myInserter->getPendingFlowCount() == 0)
534  if (myPersonControl) {
536  }
537  if (myContainerControl) {
539  }
542  }
543  }
544  if (stopTime >= 0 && myStep >= stopTime) {
546  }
547  return SIMSTATE_RUNNING;
548 }
549 
550 
551 std::string
553  switch (state) {
555  return "";
557  return "The final simulation step has been reached.";
559  return "All vehicles have left the simulation.";
561  return "TraCI requested termination.";
563  return "An error occured (see log).";
565  return "Too many vehicles.";
566  default:
567  return "Unknown reason.";
568  }
569 }
570 
571 
572 void
574  // clear container
575  MSEdge::clear();
576  MSLane::clear();
577  MSRoute::clear();
585 }
586 
587 
588 void
590  // update detector values
592  const OptionsCont& oc = OptionsCont::getOptions();
593 
594  // check state dumps
595  if (oc.isSet("netstate-dump")) {
597  oc.getInt("netstate-dump.precision"));
598  }
599 
600  // check fcd dumps
601  if (OptionsCont::getOptions().isSet("fcd-output")) {
603  }
604 
605  // check emission dumps
606  if (OptionsCont::getOptions().isSet("emission-output")) {
608  }
609 
610  // battery dumps
611  if (OptionsCont::getOptions().isSet("battery-output")) {
613  oc.getInt("battery-output.precision"));
614  }
615 
616  // check full dumps
617  if (OptionsCont::getOptions().isSet("full-output")) {
619  }
620 
621  // check queue dumps
622  if (OptionsCont::getOptions().isSet("queue-output")) {
624  }
625 
626  // check amitran dumps
627  if (OptionsCont::getOptions().isSet("amitran-output")) {
629  }
630 
631  // check vtk dumps
632  if (OptionsCont::getOptions().isSet("vtk-output")) {
633 
634  if (MSNet::getInstance()->getVehicleControl().getRunningVehicleNo() > 0) {
635  std::string timestep = time2string(myStep);
636  timestep = timestep.substr(0, timestep.length() - 3);
637  std::string output = OptionsCont::getOptions().getString("vtk-output");
638  std::string filename = output + "_" + timestep + ".vtp";
639 
640  OutputDevice_File dev = OutputDevice_File(filename, false);
641 
642  //build a huge mass of xml files
644 
645  }
646 
647  }
648 
649  // summary output
650  if (OptionsCont::getOptions().isSet("summary-output")) {
651  OutputDevice& od = OutputDevice::getDeviceByOption("summary-output");
652  unsigned int departedVehiclesNumber = myVehicleControl->getDepartedVehicleNo();
653  const SUMOReal meanWaitingTime = departedVehiclesNumber != 0 ? myVehicleControl->getTotalDepartureDelay() / (SUMOReal) departedVehiclesNumber : -1.;
654  unsigned int endedVehicleNumber = myVehicleControl->getEndedVehicleNo();
655  const SUMOReal meanTravelTime = endedVehicleNumber != 0 ? myVehicleControl->getTotalTravelTime() / (SUMOReal) endedVehicleNumber : -1.;
657  .writeAttr("inserted", myVehicleControl->getDepartedVehicleNo()).writeAttr("running", myVehicleControl->getRunningVehicleNo())
658  .writeAttr("waiting", myInserter->getWaitingVehicleNo()).writeAttr("ended", myVehicleControl->getEndedVehicleNo())
659  .writeAttr("meanWaitingTime", meanWaitingTime).writeAttr("meanTravelTime", meanTravelTime);
660  if (myLogExecutionTime) {
661  od.writeAttr("duration", mySimStepDuration);
662  }
663  od.closeTag();
664  }
665 
666  // write detector values
668 
669  // write link states
670  if (OptionsCont::getOptions().isSet("link-output")) {
671  OutputDevice& od = OutputDevice::getDeviceByOption("link-output");
672  od.openTag("timestep");
674  const MSEdgeVector& edges = myEdges->getEdges();
675  for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
676  const std::vector<MSLane*>& lanes = (*i)->getLanes();
677  for (std::vector<MSLane*>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
678  const std::vector<MSLink*>& links = (*j)->getLinkCont();
679  for (std::vector<MSLink*>::const_iterator k = links.begin(); k != links.end(); ++k) {
680  (*k)->writeApproaching(od, (*j)->getID());
681  }
682  }
683  }
684  od.closeTag();
685  }
686 }
687 
688 
689 bool
691  return myLogExecutionTime;
692 }
693 
694 
697  if (myPersonControl == 0) {
699  }
700  return *myPersonControl;
701 }
702 
705  if (myContainerControl == 0) {
707  }
708  return *myContainerControl;
709 }
710 
711 
714  if (myEdgeWeights == 0) {
716  }
717  return *myEdgeWeights;
718 }
719 
720 
721 void
723  std::cout << "Step #" << time2string(myStep);
724 }
725 
726 
727 void
729  if (myLogExecutionTime) {
730  std::ostringstream oss;
731  oss.setf(std::ios::fixed , std::ios::floatfield); // use decimal format
732  oss.setf(std::ios::showpoint); // print decimal point
733  oss << std::setprecision(OUTPUT_ACCURACY);
734  if (mySimStepDuration != 0) {
735  oss << " (" << mySimStepDuration << "ms ~= "
736  << (1000. / (SUMOReal) mySimStepDuration) << "*RT, ~"
738  } else {
739  oss << " (0ms ?*RT. ?";
740  }
741  oss << "UPS, vehicles"
742  << " TOT " << myVehicleControl->getDepartedVehicleNo()
743  << " ACT " << myVehicleControl->getRunningVehicleNo()
744  << ") ";
745  std::string prev = "Step #" + time2string(myStep - DELTA_T);
746  std::cout << oss.str().substr(0, 78 - prev.length());
747  }
748  std::cout << '\r';
749 }
750 
751 
752 void
754  if (find(myVehicleStateListeners.begin(), myVehicleStateListeners.end(), listener) == myVehicleStateListeners.end()) {
755  myVehicleStateListeners.push_back(listener);
756  }
757 }
758 
759 
760 void
762  std::vector<VehicleStateListener*>::iterator i = find(myVehicleStateListeners.begin(), myVehicleStateListeners.end(), listener);
763  if (i != myVehicleStateListeners.end()) {
764  myVehicleStateListeners.erase(i);
765  }
766 }
767 
768 
769 void
771  for (std::vector<VehicleStateListener*>::iterator i = myVehicleStateListeners.begin(); i != myVehicleStateListeners.end(); ++i) {
772  (*i)->vehicleStateChanged(vehicle, to);
773  }
774 }
775 
776 
777 
778 // ------ Insertion and retrieval of bus stops ------
779 bool
781  return myBusStopDict.add(busStop->getID(), busStop);
782 }
783 
784 
786 MSNet::getBusStop(const std::string& id) const {
787  return myBusStopDict.get(id);
788 }
789 
790 
791 std::string
792 MSNet::getBusStopID(const MSLane* lane, const SUMOReal pos) const {
793  const std::map<std::string, MSStoppingPlace*>& vals = myBusStopDict.getMyMap();
794  for (std::map<std::string, MSStoppingPlace*>::const_iterator it = vals.begin(); it != vals.end(); ++it) {
795  MSStoppingPlace* stop = it->second;
796  if (&stop->getLane() == lane && fabs(stop->getEndLanePosition() - pos) < POSITION_EPS) {
797  return stop->getID();
798  }
799  }
800  return "";
801 }
802 
803 // ------ Insertion and retrieval of container stops ------
804 bool
806  return myContainerStopDict.add(containerStop->getID(), containerStop);
807 }
808 
810 MSNet::getContainerStop(const std::string& id) const {
811  return myContainerStopDict.get(id);
812 }
813 
814 std::string
815 MSNet::getContainerStopID(const MSLane* lane, const SUMOReal pos) const {
816  const std::map<std::string, MSStoppingPlace*>& vals = myContainerStopDict.getMyMap();
817  for (std::map<std::string, MSStoppingPlace*>::const_iterator it = vals.begin(); it != vals.end(); ++it) {
818  MSStoppingPlace* stop = it->second;
819  if (&stop->getLane() == lane && fabs(stop->getEndLanePosition() - pos) < POSITION_EPS) {
820  return stop->getID();
821  }
822  }
823  return "";
824 }
825 
826 
827 bool
829  return myChargingStationDict.add(chargingStation->getID(), chargingStation);
830 }
831 
832 
834 MSNet::getChargingStation(const std::string& id) const {
835  return myChargingStationDict.get(id);
836 }
837 
838 
839 std::string
840 MSNet::getChargingStationID(const MSLane* lane, const SUMOReal pos) const {
841  const std::map<std::string, MSChargingStation*>& vals = myChargingStationDict.getMyMap();
842  for (std::map<std::string, MSChargingStation*>::const_iterator it = vals.begin(); it != vals.end(); ++it) {
843  MSChargingStation* chargingStation = it->second;
844  if (&chargingStation->getLane() == lane && chargingStation->getBeginLanePosition() <= pos && chargingStation->getEndLanePosition() >= pos) {
845  return chargingStation->getID();
846  }
847  }
848  return "";
849 }
850 
851 
853 MSNet::getRouterTT(const MSEdgeVector& prohibited) const {
854  if (!myRouterTTInitialized) {
855  myRouterTTInitialized = true;
856  const std::string routingAlgorithm = OptionsCont::getOptions().getString("routing-algorithm");
857  if (routingAlgorithm == "dijkstra") {
860  } else {
861  if (routingAlgorithm != "astar") {
862  WRITE_WARNING("TraCI and Triggers cannot use routing algorithm '" + routingAlgorithm + "'. using 'astar' instead.");
863  }
866  }
867  }
868  if (myRouterTTDijkstra != 0) {
869  myRouterTTDijkstra->prohibit(prohibited);
870  return *myRouterTTDijkstra;
871  } else {
872  assert(myRouterTTAStar != 0);
873  myRouterTTAStar->prohibit(prohibited);
874  return *myRouterTTAStar;
875  }
876 }
877 
878 
880 MSNet::getRouterEffort(const MSEdgeVector& prohibited) const {
881  if (myRouterEffort == 0) {
884  }
885  myRouterEffort->prohibit(prohibited);
886  return *myRouterEffort;
887 }
888 
889 
891 MSNet::getPedestrianRouter(const MSEdgeVector& prohibited) const {
892  if (myPedestrianRouter == 0) {
894  }
895  myPedestrianRouter->prohibit(prohibited);
896  return *myPedestrianRouter;
897 }
898 
899 
900 const NamedRTree&
902  if (!myLanesRTree.first) {
903  MSLane::fill(myLanesRTree.second);
904  myLanesRTree.first = true;
905  }
906  return myLanesRTree.second;
907 }
908 
909 
910 bool
912  const MSEdgeVector& edges = myEdges->getEdges();
913  for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
914  for (std::vector<MSLane*>::const_iterator i = (*e)->getLanes().begin(); i != (*e)->getLanes().end(); ++i) {
915  if ((*i)->getShape().hasElevation()) {
916  return true;
917  }
918  }
919  }
920  return false;
921 }
922 
923 /****************************************************************************/
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:61
AStarRouter< MSEdge, SUMOVehicle, prohibited_withPermissions< MSEdge, SUMOVehicle > > * myRouterTTAStar
Definition: MSNet.h:765
unsigned int getTeleportsYield() const
return the number of teleports due to vehicles stuck on a minor road
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:257
unsigned int getLoadedPersonNumber() const
Returns the number of build Persons.
Computes the shortest path through a network using the Dijkstra algorithm.
bool lefthand() const
return whether the network was built for lefthand traffic
Definition: MSNet.h:638
int getPendingFlowCount() const
Returns the number of flows that are still active.
unsigned int getTeleportsWrongLane() const
return the number of teleports due to vehicles stuck on the wrong lane
void postSimStepOutput() const
Prints the statistics of the step at its end.
Definition: MSNet.cpp:728
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
long long int SUMOTime
Definition: SUMOTime.h:43
Interface for objects listening to vehicle state changes.
Definition: MSNet.h:553
long mySimStepEnd
Definition: MSNet.h:706
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:761
unsigned int getRunningVehicleNo() const
Returns the number of build and inserted, but not yet deleted vehicles.
MSEventControl * myEndOfTimestepEvents
Controls events executed at the end of a time step;.
Definition: MSNet.h:685
static SUMOReal getEffort(const MSEdge *const e, const SUMOVehicle *const v, SUMOReal t)
Returns the effort to pass an edge.
Definition: MSNet.cpp:130
SUMOReal getTotalDepartureDelay() const
Returns the total departure delay.
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
unsigned int getDepartedVehicleNo() const
Returns the number of inserted vehicles.
static size_t numericalDictSize()
Returns the number of edges with a numerical id.
Definition: MSEdge.cpp:619
A lane area vehicles can halt at.
The simulation contains too many vehicles (.
Definition: MSNet.h:111
virtual bool add(const std::string &id, T item)
Adds an item.
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:294
void patchActiveLanes()
Resets information whether a lane is active for all lanes.
static void fill(RTREE &into)
Fills the given RTree with lane instances.
Definition: MSLane.cpp:924
MSVehicleControl * myVehicleControl
Controls vehicle building and deletion;.
Definition: MSNet.h:667
void updateDetectors(const SUMOTime step)
Computes detector values.
std::vector< SUMOTime > myStateDumpTimes
Times at which a state shall be written.
Definition: MSNet.h:721
virtual void execute(SUMOTime time)
Executes time-dependant commands.
DijkstraRouterEffort< MSEdge, SUMOVehicle, prohibited_withPermissions< MSEdge, SUMOVehicle > > * myRouterEffort
Definition: MSNet.h:766
bool hasInternalLinks() const
return whether the network contains internal links
Definition: MSNet.h:628
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
PedestrianRouterDijkstra< MSEdge, MSLane, MSJunction > MSPedestrianRouterDijkstra
Definition: MSNet.h:115
void abortWaiting()
aborts the plan for any container that is still waiting for a ride
std::string getContainerStopID(const MSLane *lane, const SUMOReal pos) const
Returns the container stop close to the given position.
Definition: MSNet.cpp:815
int simulate(SUMOTime start, SUMOTime stop)
Simulates from timestep start to stop.
Definition: MSNet.cpp:304
void changeLanes(SUMOTime t)
Moves (precomputes) critical vehicles.
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:61
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
MSPedestrianRouterDijkstra & getPedestrianRouter(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:891
int getActiveVehicleCount() const
Returns the number of build vehicles that have not been removed or need to wait for a passenger or a ...
unsigned int getJammedPersonNumber() const
Returns the number of times a person was jammed.
SUMOReal getEndLanePosition() const
Returns the end position of this stop.
unsigned int getRunningPersonNumber() const
Returns the number of build and inserted, but not yet deleted Persons.
MSChargingStation * getChargingStation(const std::string &id) const
Returns the named charging station.
Definition: MSNet.cpp:834
bool addBusStop(MSStoppingPlace *busStop)
Adds a bus stop.
Definition: MSNet.cpp:780
MSPersonControl * myPersonControl
Controls person building and deletion;.
Definition: MSNet.h:669
void closeBuilding(MSEdgeControl *edges, MSJunctionControl *junctions, SUMORouteLoaderControl *routeLoaders, MSTLLogicControl *tlc, std::vector< SUMOTime > stateDumpTimes, std::vector< std::string > stateDumpFiles, bool hasInternalLinks, bool lefthand, SUMOReal version)
Closes the network&#39;s building process.
Definition: MSNet.cpp:218
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:162
bool myHavePermissions
Whether the network contains edges which not all vehicles may pass.
Definition: MSNet.h:729
MSEdgeControl * myEdges
Controls edges, performs vehicle movement;.
Definition: MSNet.h:673
The final simulation step has been performed.
Definition: MSNet.h:103
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:723
bool myLogExecutionTime
Information whether the simulation duration shall be logged.
Definition: MSNet.h:700
Storage for geometrical objects.
static const std::string STAGE_LANECHANGE
Definition: MSNet.h:777
static void write(OutputDevice &of, SUMOTime timestep)
Dumping a hugh List of Parameters available in the Simulation.
NamedObjectCont< MSStoppingPlace * > myContainerStopDict
Dictionary of container stops.
Definition: MSNet.h:750
Detectors container; responsible for string and output generation.
bool myLefthand
Whether the network was built for left-hand traffic.
Definition: MSNet.h:741
A storage for edge travel times and efforts.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:255
void detectCollisions(SUMOTime timestep, const std::string &stage)
Detect collisions.
std::string getBusStopID(const MSLane *lane, const SUMOReal pos) const
Returns the bus stop close to the given position.
Definition: MSNet.cpp:792
void addVehicleStateListener(VehicleStateListener *listener)
Adds a vehicle states listener.
Definition: MSNet.cpp:753
SimulationState
Possible states of a simulation - running or stopped with different reasons.
Definition: MSNet.h:99
MSPedestrianRouterDijkstra * myPedestrianRouter
Definition: MSNet.h:767
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
The simulated network and simulation perfomer.
Definition: MSNet.h:94
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:689
std::pair< bool, NamedRTree > myLanesRTree
An RTree structure holding lane IDs.
Definition: MSNet.h:771
static void cleanup()
Container for junctions; performs operations on all stored junctions.
bool hasPersons() const
checks whether any person waits to finish her plan
DijkstraRouterTT< MSEdge, SUMOVehicle, prohibited_withPermissions< MSEdge, SUMOVehicle > > * myRouterTTDijkstra
Definition: MSNet.h:764
SUMOReal getTotalTravelTime() const
Returns the total travel time.
static bool gCheck4Accidents
Definition: MSGlobals.h:77
#define OUTPUT_ACCURACY
Definition: config.h:164
static void write(OutputDevice &of, SUMOTime timestep)
Export the queueing length in front of a junction (very experimental!)
static void write(OutputDevice &of, SUMOTime timestep, bool elevation)
Writes the posion and the angle of each vehcile into the given device.
Definition: MSFCDExport.cpp:58
void postProcessVTD()
T get(const std::string &id) const
Retrieves an item.
static void write(OutputDevice &of, SUMOTime timestep)
Writes the complete network state of the given edges into the given device.
unsigned int getCollisionCount() const
return the number of collisions
A class that stores and controls tls and switching of their programs.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
const std::string & getID() const
Returns the id.
Definition: Named.h:65
A road/street connecting two junctions.
Definition: MSEdge.h:81
long long int myVehiclesMoved
The overall number of vehicle movements.
Definition: MSNet.h:712
long mySimStepBegin
The last simulation step begin, end and duration.
Definition: MSNet.h:706
static void close()
request termination of connection
The simulation does not contain further vehicles.
Definition: MSNet.h:105
unsigned int getLoadedVehicleNo() const
Returns the number of build vehicles.
static void generateOutputForUnfinished()
generate output for vehicles which are still in the network
An error occured during the simulation step.
Definition: MSNet.h:109
const MSLane & getLane() const
Returns the lane this stop is located at.
static void clear()
Clears the dictionary (delete all known routes, too)
Definition: MSRoute.cpp:160
void writeOutput()
Write netstate, summary and detector output.
Definition: MSNet.cpp:589
unsigned int getTeleportCount() const
return the number of teleports (including collisions)
unsigned int getWaitingVehicleNo() const
Returns the number of waiting vehicles.
void abortWaiting()
aborts the plan for any person that is still waiting for a ride
MSStoppingPlace * getBusStop(const std::string &id) const
Returns the named bus stop.
Definition: MSNet.cpp:786
static std::string printStatistics()
get statistics for printing to stdout
MSInsertionControl * myInserter
Controls vehicle insertion;.
Definition: MSNet.h:679
Representation of a vehicle.
Definition: SUMOVehicle.h:65
void checkInsertions(SUMOTime time)
Checks "movement" of stored vehicles.
SUMORouteLoaderControl * myRouteLoaders
Route loader for dynamic loading of routes.
Definition: MSNet.h:656
void closeSimulation(SUMOTime start)
Closes the simulation (all files, connections, etc.)
Definition: MSNet.cpp:355
bool myLogStepNumber
Information whether the number of the simulation step shall be logged.
Definition: MSNet.h:703
An output device that encapsulates an ofstream.
virtual MSContainerControl & getContainerControl()
Returns the container control.
Definition: MSNet.cpp:704
static void clear()
Clears the dictionary.
Definition: MSEdge.cpp:625
SUMOTime getTargetTime()
Definition: TraCIServer.h:80
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:308
static SUMOReal getTravelTime(const MSEdge *const e, const SUMOVehicle *const v, SUMOReal t)
Returns the travel time to pass an edge.
Definition: MSNet.cpp:144
MSDetectorControl * myDetectorControl
Controls detectors;.
Definition: MSNet.h:681
void checkWaitingPersons(MSNet *net, const SUMOTime time)
checks whether any persons waiting or walking time is over
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:677
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:107
The simulation is running.
Definition: MSNet.h:101
SUMOTime string2time(const std::string &r)
Definition: SUMOTime.cpp:48
void check2Switch(SUMOTime step)
Checks whether any WAUT is trying to switch a tls into another program.
#define POSITION_EPS
Definition: config.h:188
void preSimStepOutput() const
Prints the current step number.
Definition: MSNet.cpp:722
std::map< std::string, std::map< SUMOVehicleClass, SUMOReal > > myRestrictions
The vehicle class specific speed restrictions.
Definition: MSNet.h:732
static void cleanup()
properly deletes all trigger instances
Definition: MSTrigger.cpp:47
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:53
SUMOReal myVersion
the network version
Definition: MSNet.h:744
TraCI server used to control sumo by a remote TraCI client.
Definition: TraCIServer.h:74
static void generateOutputForUnfinished()
generate vehroute output for vehicles which are still in the network
MSContainerControl * myContainerControl
Controls container building and deletion;.
Definition: MSNet.h:671
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:526
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:853
bool hasNonWaiting() const
checks whether any person is still engaged in walking / stopping
static MSVehicleTransfer * getInstance()
Returns the instance of this object.
void prohibit(const std::vector< E * > &toProhibit)
static const std::string STAGE_MOVEMENTS
Definition: MSNet.h:776
const IDMap & getMyMap() const
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:756
static MSNet * myInstance
Unique instance of MSNet.
Definition: MSNet.h:653
unsigned int getTeleportsJam() const
return the number of teleports due to jamming
bool isEmpty()
Returns whether events are in the que.
static void clearAll()
Clears all dictionaries.
Definition: MSNet.cpp:573
bool myRouterTTInitialized
Definition: MSNet.h:763
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:805
bool addChargingStation(MSChargingStation *chargingStation)
Adds a chargingg station.
Definition: MSNet.cpp:828
void close(SUMOTime step)
Closes the detector outputs.
SimulationState simulationState(SUMOTime stopTime) const
Called after a simulation step, this method returns the current simulation state. ...
Definition: MSNet.cpp:520
MSJunctionControl * myJunctions
Controls junctions, realizes right-of-way rules;.
Definition: MSNet.h:675
virtual MSPersonControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:696
static void clear()
Clears the dictionary.
Definition: MSLane.cpp:907
static void write(OutputDevice &of, SUMOTime timestep, int precision)
Writes the complete network state of the given edges into the given device.
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:911
static void cleanup()
remove state at simulation end
Definition: MSPModel.cpp:83
SUMOReal getBeginLanePosition() const
Returns the begin position of this stop.
static TraCIServer * getInstance()
Definition: TraCIServer.h:83
MSEventControl * myBeginOfTimestepEvents
Controls events executed at the begin of a time step;.
Definition: MSNet.h:683
A storage for options typed value containers)
Definition: OptionsCont.h:108
MSEdgeWeightsStorage * myEdgeWeights
The net&#39;s knowledge about edge efforts/travel times;.
Definition: MSNet.h:691
MSStoppingPlace * getContainerStop(const std::string &id) const
Returns the named container stop.
Definition: MSNet.cpp:810
MSNet(MSVehicleControl *vc, MSEventControl *beginOfTimestepEvents, MSEventControl *endOfTimestepEvents, MSEventControl *insertionEvents, ShapeContainer *shapeCont=0)
Constructor.
Definition: MSNet.cpp:170
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:288
unsigned int emitVehicles(SUMOTime time)
Emits vehicles that want to depart at the given time.
unsigned int getEndedVehicleNo() const
Returns the number of removed vehicles.
void informVehicleStateListener(const SUMOVehicle *const vehicle, VehicleState to)
Informs all added listeners about a vehicle&#39;s state change.
Definition: MSNet.cpp:770
const NamedRTree & getLanesRTree() const
Returns an RTree that contains lane IDs.
Definition: MSNet.cpp:901
static void cleanup()
cleanup remaining data structures
void prohibit(const std::vector< E * > &toProhibit)
SUMOReal version() const
return the network version
Definition: MSNet.h:643
long mySimBeginMillis
The overall simulation duration.
Definition: MSNet.h:709
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:159
virtual ~MSNet()
Destructor.
Definition: MSNet.cpp:248
bool myHasElevation
Whether the network contains elevation data.
Definition: MSNet.h:738
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:214
static const bool gUseMesoSim
Definition: MSGlobals.h:102
static std::string getStateMessage(SimulationState state)
Returns the message to show if a certain state occurs.
Definition: MSNet.cpp:552
SUMOReal getMinimumTravelTime(const SUMOVehicle *const veh) const
returns the minimum travel time for the given vehicle
Definition: MSEdge.h:410
NamedObjectCont< MSChargingStation * > myChargingStationDict
Dictionary of charging Stations.
Definition: MSNet.h:753
bool logSimulationDuration() const
Returns whether duration shall be logged.
Definition: MSNet.cpp:690
#define DELTA_T
Definition: SUMOTime.h:50
bool retrieveExistingEffort(const MSEdge *const e, const SUMOReal t, SUMOReal &value) const
Returns an effort for an edge and time if stored.
SUMOTime myStep
Current time step.
Definition: MSNet.h:659
std::string getChargingStationID(const MSLane *lane, const SUMOReal pos) const
Returns the charging station close to the given position.
Definition: MSNet.cpp:840
The class responsible for building and deletion of vehicles.
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:78
void simulationStep()
Performs a single simulation step.
Definition: MSNet.cpp:422
static long getCurrentMillis()
Returns the current time in milliseconds.
Definition: SysUtils.cpp:50
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
void loadRoutes()
loads routes for the next few steps
Definition: MSNet.cpp:349
bool hasNonWaiting() const
checks whether any container is still engaged in walking / stopping
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:201
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterEffort(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:880
static const std::string STAGE_INSERTIONS
Definition: MSNet.h:778
MSEventControl * myInsertionEvents
Controls insertion events;.
Definition: MSNet.h:687
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
const MSEdgeWeightsStorage & getWeightsStorage() const
Returns the vehicle&#39;s internal edge travel times/efforts container.
Definition: MSVehicle.cpp:540
long mySimStepDuration
Definition: MSNet.h:706
NamedObjectCont< MSStoppingPlace * > myBusStopDict
Dictionary of bus stops.
Definition: MSNet.h:747
static bool wasClosed()
check whether close was requested
bool retrieveExistingTravelTime(const MSEdge *const e, const SUMOReal t, SUMOReal &value) const
Returns a travel time for an edge and time if stored.
Stores time-dependant events and executes them at the proper time.
bool myHasInternalLinks
Whether the network contains internal links/lanes/edges.
Definition: MSNet.h:735
unsigned int getEmergencyStops() const
return the number of emergency stops
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
void checkWaitingContainers(MSNet *net, const SUMOTime time)
checks whether any containers waiting time is over
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 MSEdgeVector & getEdges() const
Returns loaded edges.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
MSEdgeWeightsStorage & getWeightsStorage()
Returns the net&#39;s internal edge travel times/efforts container.
Definition: MSNet.cpp:713
static const std::string STAGE_EVENTS
string constants for simstep stages
Definition: MSNet.h:775