SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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),
178  myRouterTTDijkstra(0),
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  myTooManyVehicles = oc.getInt("max-num-vehicles");
190  myInserter = new MSInsertionControl(*vc, string2time(oc.getString("max-depart-delay")), !oc.getBool("eager-insert"));
191  myVehicleControl = vc;
193  myEdges = 0;
194  myJunctions = 0;
195  myRouteLoaders = 0;
196  myLogics = 0;
197  myPersonControl = 0;
198  myContainerControl = 0;
199  myEdgeWeights = 0;
200  myShapeContainer = shapeCont == 0 ? new ShapeContainer() : shapeCont;
201 
202  myBeginOfTimestepEvents = beginOfTimestepEvents;
203  myEndOfTimestepEvents = endOfTimestepEvents;
204  myInsertionEvents = insertionEvents;
205  myLanesRTree.first = false;
206 
207 #ifdef HAVE_INTERNAL
209  MSGlobals::gMesoNet = new MELoop(string2time(oc.getString("meso-recheck")));
210  }
211 #endif
212  myInstance = this;
213 }
214 
215 
216 
217 
218 void
220  SUMORouteLoaderControl* routeLoaders,
221  MSTLLogicControl* tlc,
222  std::vector<SUMOTime> stateDumpTimes,
223  std::vector<std::string> stateDumpFiles,
224  bool hasInternalLinks) {
225  myEdges = edges;
226  myJunctions = junctions;
227  myRouteLoaders = routeLoaders;
228  myLogics = tlc;
229  // save the time the network state shall be saved at
230  myStateDumpTimes = stateDumpTimes;
231  myStateDumpFiles = stateDumpFiles;
232 
233  // set requests/responses
235 
236  // initialise performance computation
237  if (myLogExecutionTime) {
239  }
242 }
243 
244 
246  // delete events first maybe they do some cleanup
249  delete myEndOfTimestepEvents;
251  delete myInsertionEvents;
252  myInsertionEvents = 0;
253  // delete controls
254  delete myJunctions;
255  delete myDetectorControl;
256  // delete mean data
257  delete myEdges;
258  delete myInserter;
259  delete myLogics;
260  delete myRouteLoaders;
261  delete myVehicleControl;
262  if (myPersonControl != 0) {
263  delete myPersonControl;
264  }
265  if (myContainerControl != 0) {
266  delete myContainerControl;
267  }
268  delete myShapeContainer;
269  delete myEdgeWeights;
270  delete myRouterTTDijkstra;
271  delete myRouterTTAStar;
272  delete myRouterEffort;
273  myLanesRTree.second.RemoveAll();
274  clearAll();
275 #ifdef HAVE_INTERNAL
277  delete MSGlobals::gMesoNet;
278  }
279 #endif
280  myInstance = 0;
281 }
282 
283 
284 void
285 MSNet::addRestriction(const std::string& id, const SUMOVehicleClass svc, const SUMOReal speed) {
286  myRestrictions[id][svc] = speed;
287 }
288 
289 
290 const std::map<SUMOVehicleClass, SUMOReal>*
291 MSNet::getRestrictions(const std::string& id) const {
292  std::map<std::string, std::map<SUMOVehicleClass, SUMOReal> >::const_iterator i = myRestrictions.find(id);
293  if (i == myRestrictions.end()) {
294  return 0;
295  }
296  return &i->second;
297 }
298 
299 
300 int
302  // report the begin when wished
303  WRITE_MESSAGE("Simulation started with time: " + time2string(start));
304  // the simulation loop
306  myStep = start;
307  // preload the routes especially for TraCI
308  loadRoutes();
309 #ifndef NO_TRACI
310 #ifdef HAVE_PYTHON
311  if (OptionsCont::getOptions().isSet("python-script")) {
312  TraCIServer::runEmbedded(OptionsCont::getOptions().getString("python-script"));
313  closeSimulation(start);
314  WRITE_MESSAGE("Simulation ended at time: " + time2string(getCurrentTimeStep()));
315  WRITE_MESSAGE("Reason: Script ended");
316  return 0;
317  }
318 #endif
319 #endif
320  while (state == SIMSTATE_RUNNING) {
321  if (myLogStepNumber) {
323  }
324  simulationStep();
325  if (myLogStepNumber) {
327  }
328  state = simulationState(stop);
329 #ifndef NO_TRACI
330  if (state != SIMSTATE_RUNNING) {
331  if (OptionsCont::getOptions().getInt("remote-port") != 0 && !TraCIServer::wasClosed()) {
332  state = SIMSTATE_RUNNING;
333  }
334  }
335 #endif
336  }
337  // report the end when wished
338  WRITE_MESSAGE("Simulation ended at time: " + time2string(getCurrentTimeStep()));
339  WRITE_MESSAGE("Reason: " + getStateMessage(state));
340  // exit simulation loop
341  closeSimulation(start);
342  return 0;
343 }
344 
345 void
348 }
349 
350 
351 void
353  if (myLogExecutionTime) {
354  long duration = SysUtils::getCurrentMillis() - mySimBeginMillis;
355  std::ostringstream msg;
356  // print performance notice
357  msg << "Performance: " << "\n" << " Duration: " << duration << "ms" << "\n";
358  if (duration != 0) {
359  msg << " Real time factor: " << (STEPS2TIME(myStep - start) * 1000. / (SUMOReal)duration) << "\n";
360  msg.setf(std::ios::fixed , std::ios::floatfield); // use decimal format
361  msg.setf(std::ios::showpoint); // print decimal point
362  msg << " UPS: " << ((SUMOReal)myVehiclesMoved / ((SUMOReal)duration / 1000)) << "\n";
363  }
364  // print vehicle statistics
365  const std::string discardNotice = ((myVehicleControl->getLoadedVehicleNo() != myVehicleControl->getDepartedVehicleNo()) ?
366  " (Loaded: " + toString(myVehicleControl->getLoadedVehicleNo()) + ")" : "");
367  msg << "Vehicles: " << "\n"
368  << " Inserted: " << myVehicleControl->getDepartedVehicleNo() << discardNotice << "\n"
369  << " Running: " << myVehicleControl->getRunningVehicleNo() << "\n"
370  << " Waiting: " << myInserter->getWaitingVehicleNo() << "\n";
371 
372  if (myVehicleControl->getTeleportCount() > 0) {
373  // print optional teleport statistics
374  std::vector<std::string> reasons;
375  if (myVehicleControl->getCollisionCount() > 0) {
376  reasons.push_back("Collisions: " + toString(myVehicleControl->getCollisionCount()));
377  }
378  if (myVehicleControl->getTeleportsJam() > 0) {
379  reasons.push_back("Jam: " + toString(myVehicleControl->getTeleportsJam()));
380  }
381  if (myVehicleControl->getTeleportsYield() > 0) {
382  reasons.push_back("Yield: " + toString(myVehicleControl->getTeleportsYield()));
383  }
385  reasons.push_back("Wrong Lane: " + toString(myVehicleControl->getTeleportsWrongLane()));
386  }
387  msg << "Teleports: " << myVehicleControl->getTeleportCount() << " (" << joinToString(reasons, ", ") << ")\n";
388  }
389  if (myVehicleControl->getEmergencyStops() > 0) {
390  msg << "Emergency Stops: " << myVehicleControl->getEmergencyStops() << "\n";
391  }
392  WRITE_MESSAGE(msg.str());
393  }
395  if (OptionsCont::getOptions().getBool("vehroute-output.write-unfinished")) {
397  }
398  if (OptionsCont::getOptions().getBool("tripinfo-output.write-unfinished")) {
400  }
401 #ifndef NO_TRACI
403 #endif
404 }
405 
406 
407 void
409 #ifndef NO_TRACI
412  if (t != 0 && t->getTargetTime() != 0 && t->getTargetTime() < myStep) {
413  return;
414  }
415 #endif
416  // execute beginOfTimestepEvents
417  if (myLogExecutionTime) {
419  }
420  // simulation state output
421  std::vector<SUMOTime>::iterator timeIt = find(myStateDumpTimes.begin(), myStateDumpTimes.end(), myStep);
422  if (timeIt != myStateDumpTimes.end()) {
423  const int dist = (int)distance(myStateDumpTimes.begin(), timeIt);
425  }
427 #ifdef HAVE_FOX
428  MSDevice_Routing::waitForAll();
429 #endif
432  }
433  // check whether the tls programs need to be switched
435 
436 #ifdef HAVE_INTERNAL
438  MSGlobals::gMesoNet->simulate(myStep);
439  } else {
440 #endif
441 
442  // assure all lanes with vehicles are 'active'
444 
445  // compute safe velocities for all vehicles for the next few lanes
446  // also register ApproachingVehicleInformation for all links
448 
449  // decide right-of-way and execute movements
453  }
454 
455  // vehicles may change lanes
457 
460  }
461 #ifdef HAVE_INTERNAL
462  }
463 #endif
464  loadRoutes();
465 
466  // persons
467  if (myPersonControl != 0 && myPersonControl->hasPersons()) {
469  }
470  // insert vehicles
471  myInserter->determineCandidates(myStep); // containers
472  if (myContainerControl != 0) {
474  }
476 #ifdef HAVE_FOX
477  MSDevice_Routing::waitForAll();
478 #endif
482  }
484 
485  // execute endOfTimestepEvents
487 
488 #ifndef NO_TRACI
489  if (TraCIServer::getInstance() != 0) {
491  }
492 #endif
493  // update and write (if needed) detector values
494  writeOutput();
495 
496  if (myLogExecutionTime) {
500  }
501  myStep += DELTA_T;
502 }
503 
504 
509  }
510 #ifndef NO_TRACI
511  if (TraCIServer::wasClosed()) {
513  }
514  if (stopTime < 0 && OptionsCont::getOptions().getInt("remote-port") == 0) {
515 #else
516  if (stopTime < 0) {
517 #endif
520  && (myInserter->getPendingFlowCount() == 0)
523  if (myPersonControl) {
525  }
526  if (myContainerControl) {
528  }
531  }
532  }
533  if (stopTime >= 0 && myStep >= stopTime) {
535  }
536  return SIMSTATE_RUNNING;
537 }
538 
539 
540 std::string
542  switch (state) {
544  return "";
546  return "The final simulation step has been reached.";
548  return "All vehicles have left the simulation.";
550  return "TraCI requested termination.";
552  return "An error occured (see log).";
554  return "Too many vehicles.";
555  default:
556  return "Unknown reason.";
557  }
558 }
559 
560 
561 void
563  // clear container
564  MSEdge::clear();
565  MSLane::clear();
566  MSRoute::clear();
574 }
575 
576 
577 void
579  // update detector values
581  const OptionsCont& oc = OptionsCont::getOptions();
582 
583  // check state dumps
584  if (oc.isSet("netstate-dump")) {
586  oc.getInt("netstate-dump.precision"));
587  }
588 
589  // check fcd dumps
590  if (OptionsCont::getOptions().isSet("fcd-output")) {
592  }
593 
594  // check emission dumps
595  if (OptionsCont::getOptions().isSet("emission-output")) {
597  }
598 
599  // battery dumps
600  if (OptionsCont::getOptions().isSet("battery-output")) {
602  oc.getInt("battery-output.precision"));
603  }
604 
605  // check full dumps
606  if (OptionsCont::getOptions().isSet("full-output")) {
608  }
609 
610  // check queue dumps
611  if (OptionsCont::getOptions().isSet("queue-output")) {
613  }
614 
615  // check amitran dumps
616  if (OptionsCont::getOptions().isSet("amitran-output")) {
618  }
619 
620  // check vtk dumps
621  if (OptionsCont::getOptions().isSet("vtk-output")) {
622 
623  if (MSNet::getInstance()->getVehicleControl().getRunningVehicleNo() > 0) {
624  std::string timestep = time2string(myStep);
625  timestep = timestep.substr(0, timestep.length() - 3);
626  std::string output = OptionsCont::getOptions().getString("vtk-output");
627  std::string filename = output + "_" + timestep + ".vtp";
628 
629  OutputDevice_File dev = OutputDevice_File(filename, false);
630 
631  //build a huge mass of xml files
633 
634  }
635 
636  }
637 
638  // summary output
639  if (OptionsCont::getOptions().isSet("summary-output")) {
640  OutputDevice& od = OutputDevice::getDeviceByOption("summary-output");
641  unsigned int departedVehiclesNumber = myVehicleControl->getDepartedVehicleNo();
642  const SUMOReal meanWaitingTime = departedVehiclesNumber != 0 ? myVehicleControl->getTotalDepartureDelay() / (SUMOReal) departedVehiclesNumber : -1.;
643  unsigned int endedVehicleNumber = myVehicleControl->getEndedVehicleNo();
644  const SUMOReal meanTravelTime = endedVehicleNumber != 0 ? myVehicleControl->getTotalTravelTime() / (SUMOReal) endedVehicleNumber : -1.;
646  .writeAttr("inserted", myVehicleControl->getDepartedVehicleNo()).writeAttr("running", myVehicleControl->getRunningVehicleNo())
647  .writeAttr("waiting", myInserter->getWaitingVehicleNo()).writeAttr("ended", myVehicleControl->getEndedVehicleNo())
648  .writeAttr("meanWaitingTime", meanWaitingTime).writeAttr("meanTravelTime", meanTravelTime);
649  if (myLogExecutionTime) {
650  od.writeAttr("duration", mySimStepDuration);
651  }
652  od.closeTag();
653  }
654 
655  // write detector values
657 
658  // write link states
659  if (OptionsCont::getOptions().isSet("link-output")) {
660  OutputDevice& od = OutputDevice::getDeviceByOption("link-output");
661  od.openTag("timestep");
663  const MSEdgeVector& edges = myEdges->getEdges();
664  for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
665  const std::vector<MSLane*>& lanes = (*i)->getLanes();
666  for (std::vector<MSLane*>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
667  const std::vector<MSLink*>& links = (*j)->getLinkCont();
668  for (std::vector<MSLink*>::const_iterator k = links.begin(); k != links.end(); ++k) {
669  (*k)->writeApproaching(od, (*j)->getID());
670  }
671  }
672  }
673  od.closeTag();
674  }
675 }
676 
677 
678 bool
680  return myLogExecutionTime;
681 }
682 
683 
686  if (myPersonControl == 0) {
688  }
689  return *myPersonControl;
690 }
691 
694  if (myContainerControl == 0) {
696  }
697  return *myContainerControl;
698 }
699 
700 
703  if (myEdgeWeights == 0) {
705  }
706  return *myEdgeWeights;
707 }
708 
709 
710 void
712  std::cout << "Step #" << time2string(myStep);
713 }
714 
715 
716 void
718  if (myLogExecutionTime) {
719  std::ostringstream oss;
720  oss.setf(std::ios::fixed , std::ios::floatfield); // use decimal format
721  oss.setf(std::ios::showpoint); // print decimal point
722  oss << std::setprecision(OUTPUT_ACCURACY);
723  if (mySimStepDuration != 0) {
724  oss << " (" << mySimStepDuration << "ms ~= "
725  << (1000. / (SUMOReal) mySimStepDuration) << "*RT, ~"
727  } else {
728  oss << " (0ms ?*RT. ?";
729  }
730  oss << "UPS, vehicles"
731  << " TOT " << myVehicleControl->getDepartedVehicleNo()
732  << " ACT " << myVehicleControl->getRunningVehicleNo()
733  << ") ";
734  std::string prev = "Step #" + time2string(myStep - DELTA_T);
735  std::cout << oss.str().substr(0, 78 - prev.length());
736  }
737  std::cout << '\r';
738 }
739 
740 
741 void
743  if (find(myVehicleStateListeners.begin(), myVehicleStateListeners.end(), listener) == myVehicleStateListeners.end()) {
744  myVehicleStateListeners.push_back(listener);
745  }
746 }
747 
748 
749 void
751  std::vector<VehicleStateListener*>::iterator i = find(myVehicleStateListeners.begin(), myVehicleStateListeners.end(), listener);
752  if (i != myVehicleStateListeners.end()) {
753  myVehicleStateListeners.erase(i);
754  }
755 }
756 
757 
758 void
760  for (std::vector<VehicleStateListener*>::iterator i = myVehicleStateListeners.begin(); i != myVehicleStateListeners.end(); ++i) {
761  (*i)->vehicleStateChanged(vehicle, to);
762  }
763 }
764 
765 
766 
767 // ------ Insertion and retrieval of bus stops ------
768 bool
770  return myBusStopDict.add(busStop->getID(), busStop);
771 }
772 
773 
775 MSNet::getBusStop(const std::string& id) const {
776  return myBusStopDict.get(id);
777 }
778 
779 
780 std::string
781 MSNet::getBusStopID(const MSLane* lane, const SUMOReal pos) const {
782  const std::map<std::string, MSStoppingPlace*>& vals = myBusStopDict.getMyMap();
783  for (std::map<std::string, MSStoppingPlace*>::const_iterator it = vals.begin(); it != vals.end(); ++it) {
784  MSStoppingPlace* stop = it->second;
785  if (&stop->getLane() == lane && fabs(stop->getEndLanePosition() - pos) < POSITION_EPS) {
786  return stop->getID();
787  }
788  }
789  return "";
790 }
791 
792 // ------ Insertion and retrieval of container stops ------
793 bool
795  return myContainerStopDict.add(containerStop->getID(), containerStop);
796 }
797 
799 MSNet::getContainerStop(const std::string& id) const {
800  return myContainerStopDict.get(id);
801 }
802 
803 std::string
804 MSNet::getContainerStopID(const MSLane* lane, const SUMOReal pos) const {
805  const std::map<std::string, MSStoppingPlace*>& vals = myContainerStopDict.getMyMap();
806  for (std::map<std::string, MSStoppingPlace*>::const_iterator it = vals.begin(); it != vals.end(); ++it) {
807  MSStoppingPlace* stop = it->second;
808  if (&stop->getLane() == lane && fabs(stop->getEndLanePosition() - pos) < POSITION_EPS) {
809  return stop->getID();
810  }
811  }
812  return "";
813 }
814 
815 
816 bool
818  return myChrgStnDict.add(chrgStn->getID(), chrgStn);
819 }
820 
821 
822 MSChrgStn*
823 MSNet::getChrgStn(const std::string& id) const {
824  return myChrgStnDict.get(id);
825 }
826 
827 
828 std::string
829 MSNet::getChrgStnID(const MSLane* lane, const SUMOReal pos) const {
830  const std::map<std::string, MSChrgStn*>& vals = myChrgStnDict.getMyMap();
831  for (std::map<std::string, MSChrgStn*>::const_iterator it = vals.begin(); it != vals.end(); ++it) {
832  MSChrgStn* chrgStn = it->second;
833  if (&chrgStn->getLane() == lane && chrgStn->getBeginLanePosition() <= pos && chrgStn->getEndLanePosition() >= pos) {
834  return chrgStn->getID();
835  }
836  }
837  return "";
838 }
839 
840 
842 MSNet::getRouterTT(const MSEdgeVector& prohibited) const {
843  if (!myRouterTTInitialized) {
844  myRouterTTInitialized = true;
845  const std::string routingAlgorithm = OptionsCont::getOptions().getString("routing-algorithm");
846  if (routingAlgorithm == "dijkstra") {
849  } else {
850  if (routingAlgorithm != "astar") {
851  WRITE_WARNING("TraCI and Triggers cannot use routing algorithm '" + routingAlgorithm + "'. using 'astar' instead.");
852  }
855  }
856  }
857  if (myRouterTTDijkstra != 0) {
858  myRouterTTDijkstra->prohibit(prohibited);
859  return *myRouterTTDijkstra;
860  } else {
861  assert(myRouterTTAStar != 0);
862  myRouterTTAStar->prohibit(prohibited);
863  return *myRouterTTAStar;
864  }
865 }
866 
867 
869 MSNet::getRouterEffort(const MSEdgeVector& prohibited) const {
870  if (myRouterEffort == 0) {
873  }
874  myRouterEffort->prohibit(prohibited);
875  return *myRouterEffort;
876 }
877 
878 
880 MSNet::getPedestrianRouter(const MSEdgeVector& prohibited) const {
881  if (myPedestrianRouter == 0) {
883  }
884  myPedestrianRouter->prohibit(prohibited);
885  return *myPedestrianRouter;
886 }
887 
888 
889 const NamedRTree&
891  if (!myLanesRTree.first) {
892  MSLane::fill(myLanesRTree.second);
893  myLanesRTree.first = true;
894  }
895  return myLanesRTree.second;
896 }
897 
898 
899 bool
901  const MSEdgeVector& edges = myEdges->getEdges();
902  for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
903  for (std::vector<MSLane*>::const_iterator i = (*e)->getLanes().begin(); i != (*e)->getLanes().end(); ++i) {
904  if ((*i)->getShape().hasElevation()) {
905  return true;
906  }
907  }
908  }
909  return false;
910 }
911 
912 /****************************************************************************/
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:60
AStarRouter< MSEdge, SUMOVehicle, prohibited_withPermissions< MSEdge, SUMOVehicle > > * myRouterTTAStar
Definition: MSNet.h:748
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
bool addChrgStn(MSChrgStn *chrgStn)
Adds a chargingg station.
Definition: MSNet.cpp:817
Computes the shortest path through a network using the Dijkstra algorithm.
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:717
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
Interface for objects listening to vehicle state changes.
Definition: MSNet.h:549
long mySimStepEnd
Definition: MSNet.h:692
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:750
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:671
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:593
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:291
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:930
MSVehicleControl * myVehicleControl
Controls vehicle building and deletion;.
Definition: MSNet.h:653
void updateDetectors(const SUMOTime step)
Computes detector values.
std::vector< SUMOTime > myStateDumpTimes
Times at which a state shall be written.
Definition: MSNet.h:707
virtual void execute(SUMOTime time)
Executes time-dependant commands.
DijkstraRouterEffort< MSEdge, SUMOVehicle, prohibited_withPermissions< MSEdge, SUMOVehicle > > * myRouterEffort
Definition: MSNet.h:749
bool hasInternalLinks() const
return whether the network contains internal links
Definition: MSNet.h:624
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:804
int simulate(SUMOTime start, SUMOTime stop)
Simulates from timestep start to stop.
Definition: MSNet.cpp:301
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
std::string getChrgStnID(const MSLane *lane, const SUMOReal pos) const
Returns the charging station close to the given position.
Definition: MSNet.cpp:829
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:880
int getActiveVehicleCount() const
Returns the number of build vehicles that have not been removed or need to wait for a passenger or a ...
SUMOReal getEndLanePosition() const
Returns the end position of this stop.
bool addBusStop(MSStoppingPlace *busStop)
Adds a bus stop.
Definition: MSNet.cpp:769
MSPersonControl * myPersonControl
Controls person building and deletion;.
Definition: MSNet.h:655
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:162
MSEdgeControl * myEdges
Controls edges, performs vehicle movement;.
Definition: MSNet.h:659
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:709
bool myLogExecutionTime
Information whether the simulation duration shall be logged.
Definition: MSNet.h:686
Storage for geometrical objects.
static const std::string STAGE_LANECHANGE
Definition: MSNet.h:760
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:733
MSChrgStn * getChrgStn(const std::string &id) const
Returns the named charging station.
Definition: MSNet.cpp:823
Detectors container; responsible for string and output generation.
A storage for edge travel times and efforts.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:251
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:781
void addVehicleStateListener(VehicleStateListener *listener)
Adds a vehicle states listener.
Definition: MSNet.cpp:742
SimulationState
Possible states of a simulation - running or stopped with different reasons.
Definition: MSNet.h:99
MSPedestrianRouterDijkstra * myPedestrianRouter
Definition: MSNet.h:750
#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:675
std::pair< bool, NamedRTree > myLanesRTree
An RTree structure holding lane IDs.
Definition: MSNet.h:754
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:747
SUMOReal getTotalTravelTime() const
Returns the total travel time.
static bool gCheck4Accidents
Definition: MSGlobals.h:77
#define OUTPUT_ACCURACY
Definition: config.h:165
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:57
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:60
A road/street connecting two junctions.
Definition: MSEdge.h:81
long long int myVehiclesMoved
The overall number of vehicle movements.
Definition: MSNet.h:698
long mySimStepBegin
The last simulation step begin, end and duration.
Definition: MSNet.h:692
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
void closeBuilding(MSEdgeControl *edges, MSJunctionControl *junctions, SUMORouteLoaderControl *routeLoaders, MSTLLogicControl *tlc, std::vector< SUMOTime > stateDumpTimes, std::vector< std::string > stateDumpFiles, bool hasInternalLinks)
Closes the network&#39;s building process.
Definition: MSNet.cpp:219
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:578
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:775
MSInsertionControl * myInserter
Controls vehicle insertion;.
Definition: MSNet.h:665
Representation of a vehicle.
Definition: SUMOVehicle.h:65
void checkInsertions(SUMOTime time)
Checks &quot;movement&quot; of stored vehicles.
SUMORouteLoaderControl * myRouteLoaders
Route loader for dynamic loading of routes.
Definition: MSNet.h:642
void closeSimulation(SUMOTime start)
Closes the simulation (all files, connections, etc.)
Definition: MSNet.cpp:352
bool myLogStepNumber
Information whether the number of the simulation step shall be logged.
Definition: MSNet.h:689
An output device that encapsulates an ofstream.
virtual MSContainerControl & getContainerControl()
Returns the container control.
Definition: MSNet.cpp:693
static void clear()
Clears the dictionary.
Definition: MSEdge.cpp:599
SUMOTime getTargetTime()
Definition: TraCIServer.h:80
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:304
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:667
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:663
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:189
void preSimStepOutput() const
Prints the current step number.
Definition: MSNet.cpp:711
std::map< std::string, std::map< SUMOVehicleClass, SUMOReal > > myRestrictions
The vehicle class specific speed restrictions.
Definition: MSNet.h:718
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
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:657
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:522
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:842
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:759
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:739
static MSNet * myInstance
Unique instance of MSNet.
Definition: MSNet.h:639
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:562
bool myRouterTTInitialized
Definition: MSNet.h:746
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:794
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:506
MSJunctionControl * myJunctions
Controls junctions, realizes right-of-way rules;.
Definition: MSNet.h:661
virtual MSPersonControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:685
static void clear()
Clears the dictionary.
Definition: MSLane.cpp:913
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:900
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:669
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:677
MSStoppingPlace * getContainerStop(const std::string &id) const
Returns the named container stop.
Definition: MSNet.cpp:799
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:285
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:759
const NamedRTree & getLanesRTree() const
Returns an RTree that contains lane IDs.
Definition: MSNet.cpp:890
static void cleanup()
cleanup remaining data structures
void prohibit(const std::vector< E * > &toProhibit)
long mySimBeginMillis
The overall simulation duration.
Definition: MSNet.h:695
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:245
bool myHasElevation
Whether the network contains elevation data.
Definition: MSNet.h:724
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:215
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:541
SUMOReal getMinimumTravelTime(const SUMOVehicle *const veh) const
returns the minimum travel time for the given vehicle
Definition: MSEdge.h:410
bool logSimulationDuration() const
Returns whether duration shall be logged.
Definition: MSNet.cpp:679
#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:645
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:408
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:346
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:869
static const std::string STAGE_INSERTIONS
Definition: MSNet.h:761
MSEventControl * myInsertionEvents
Controls insertion events;.
Definition: MSNet.h:673
int myTooManyVehicles
Storage for maximum vehicle number.
Definition: MSNet.h:727
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:520
long mySimStepDuration
Definition: MSNet.h:692
NamedObjectCont< MSStoppingPlace * > myBusStopDict
Dictionary of bus stops.
Definition: MSNet.h:730
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:721
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.
NamedObjectCont< MSChrgStn * > myChrgStnDict
Dictionary of charging Stations.
Definition: MSNet.h:736
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:702
static const std::string STAGE_EVENTS
string constants for simstep stages
Definition: MSNet.h:758