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 
230  // set requests/responses
232 
233  // initialise performance computation
234  if (myLogExecutionTime) {
236  }
241  myVersion = version;
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  if (myPedestrianRouter != 0) {
274  delete myPedestrianRouter;
275  }
276  myLanesRTree.second.RemoveAll();
277  clearAll();
279  delete MSGlobals::gMesoNet;
280  }
281 // delete myPedestrianRouter;
282  myInstance = 0;
283 }
284 
285 
286 void
287 MSNet::addRestriction(const std::string& id, const SUMOVehicleClass svc, const SUMOReal speed) {
288  myRestrictions[id][svc] = speed;
289 }
290 
291 
292 const std::map<SUMOVehicleClass, SUMOReal>*
293 MSNet::getRestrictions(const std::string& id) const {
294  std::map<std::string, std::map<SUMOVehicleClass, SUMOReal> >::const_iterator i = myRestrictions.find(id);
295  if (i == myRestrictions.end()) {
296  return 0;
297  }
298  return &i->second;
299 }
300 
301 
302 int
304  // report the begin when wished
305  WRITE_MESSAGE("Simulation started with time: " + time2string(start));
306  // the simulation loop
308  myStep = start;
309  // preload the routes especially for TraCI
310  loadRoutes();
311 #ifndef NO_TRACI
312 #ifdef HAVE_PYTHON
313  if (OptionsCont::getOptions().isSet("python-script")) {
314  TraCIServer::runEmbedded(OptionsCont::getOptions().getString("python-script"));
315  closeSimulation(start);
316  WRITE_MESSAGE("Simulation ended at time: " + time2string(getCurrentTimeStep()));
317  WRITE_MESSAGE("Reason: Script ended");
318  return 0;
319  }
320 #endif
321 #endif
322  while (state == SIMSTATE_RUNNING) {
323  if (myLogStepNumber) {
325  }
326  simulationStep();
327  if (myLogStepNumber) {
329  }
330  state = simulationState(stop);
331 #ifndef NO_TRACI
332  if (state != SIMSTATE_RUNNING) {
333  if (OptionsCont::getOptions().getInt("remote-port") != 0 && !TraCIServer::wasClosed()) {
334  state = SIMSTATE_RUNNING;
335  }
336  }
337 #endif
338  }
339  // report the end when wished
340  WRITE_MESSAGE("Simulation ended at time: " + time2string(getCurrentTimeStep()));
341  WRITE_MESSAGE("Reason: " + getStateMessage(state));
342  // exit simulation loop
343  closeSimulation(start);
344  return 0;
345 }
346 
347 void
350 }
351 
352 
353 void
355  if (myLogExecutionTime) {
356  long duration = SysUtils::getCurrentMillis() - mySimBeginMillis;
357  std::ostringstream msg;
358  // print performance notice
359  msg << "Performance: " << "\n" << " Duration: " << duration << "ms" << "\n";
360  if (duration != 0) {
361  msg << " Real time factor: " << (STEPS2TIME(myStep - start) * 1000. / (SUMOReal)duration) << "\n";
362  msg.setf(std::ios::fixed , std::ios::floatfield); // use decimal format
363  msg.setf(std::ios::showpoint); // print decimal point
364  msg << " UPS: " << ((SUMOReal)myVehiclesMoved / ((SUMOReal)duration / 1000)) << "\n";
365  }
366  // print vehicle statistics
367  const std::string discardNotice = ((myVehicleControl->getLoadedVehicleNo() != myVehicleControl->getDepartedVehicleNo()) ?
368  " (Loaded: " + toString(myVehicleControl->getLoadedVehicleNo()) + ")" : "");
369  msg << "Vehicles: " << "\n"
370  << " Inserted: " << myVehicleControl->getDepartedVehicleNo() << discardNotice << "\n"
371  << " Running: " << myVehicleControl->getRunningVehicleNo() << "\n"
372  << " Waiting: " << myInserter->getWaitingVehicleNo() << "\n";
373 
375  // print optional teleport statistics
376  std::vector<std::string> reasons;
377  if (myVehicleControl->getCollisionCount() > 0) {
378  reasons.push_back("Collisions: " + toString(myVehicleControl->getCollisionCount()));
379  }
380  if (myVehicleControl->getTeleportsJam() > 0) {
381  reasons.push_back("Jam: " + toString(myVehicleControl->getTeleportsJam()));
382  }
383  if (myVehicleControl->getTeleportsYield() > 0) {
384  reasons.push_back("Yield: " + toString(myVehicleControl->getTeleportsYield()));
385  }
387  reasons.push_back("Wrong Lane: " + toString(myVehicleControl->getTeleportsWrongLane()));
388  }
389  msg << "Teleports: " << myVehicleControl->getTeleportCount() << " (" << joinToString(reasons, ", ") << ")\n";
390  }
391  if (myVehicleControl->getEmergencyStops() > 0) {
392  msg << "Emergency Stops: " << myVehicleControl->getEmergencyStops() << "\n";
393  }
394  if (myPersonControl != 0 && myPersonControl->getLoadedNumber() > 0) {
395  msg << "Persons: " << "\n"
396  << " Inserted: " << myPersonControl->getLoadedNumber() << "\n"
397  << " Running: " << myPersonControl->getRunningNumber() << "\n";
398  if (myPersonControl->getJammedNumber() > 0) {
399  msg << " Jammed: " << myPersonControl->getJammedNumber() << "\n";
400  }
401  }
402  if (OptionsCont::getOptions().getBool("duration-log.statistics")) {
404  }
405  WRITE_MESSAGE(msg.str());
406  }
408  if (OptionsCont::getOptions().getBool("vehroute-output.write-unfinished")) {
410  }
411  if (OptionsCont::getOptions().getBool("tripinfo-output.write-unfinished")) {
413  }
414 #ifndef NO_TRACI
416 #endif
417 }
418 
419 
420 void
422 #ifndef NO_TRACI
425  if (t != 0 && t->getTargetTime() != 0 && t->getTargetTime() < myStep) {
426  return;
427  }
428 #endif
429  // execute beginOfTimestepEvents
430  if (myLogExecutionTime) {
432  }
433  // simulation state output
434  std::vector<SUMOTime>::iterator timeIt = find(myStateDumpTimes.begin(), myStateDumpTimes.end(), myStep);
435  if (timeIt != myStateDumpTimes.end()) {
436  const int dist = (int)distance(myStateDumpTimes.begin(), timeIt);
438  }
440 #ifdef HAVE_FOX
441  MSDevice_Routing::waitForAll();
442 #endif
445  }
446  // check whether the tls programs need to be switched
448 
451  } else {
452  // assure all lanes with vehicles are 'active'
454 
455  // compute safe velocities for all vehicles for the next few lanes
456  // also register ApproachingVehicleInformation for all links
458 
459  // decide right-of-way and execute movements
463  }
464 
465  // vehicles may change lanes
467 
470  }
471  }
472  loadRoutes();
473 
474  // persons
477  }
478  // containers
481  }
482  // insert vehicles
485 #ifdef HAVE_FOX
486  MSDevice_Routing::waitForAll();
487 #endif
490  //myEdges->patchActiveLanes(); // @note required to detect collisions on lanes that were empty before insertion. wasteful?
492  }
494 
495  // execute endOfTimestepEvents
497 
498 #ifndef NO_TRACI
499  if (TraCIServer::getInstance() != 0) {
501  }
502 #endif
503  // update and write (if needed) detector values
504  writeOutput();
505 
506  if (myLogExecutionTime) {
510  }
511  myStep += DELTA_T;
512 }
513 
514 
517 #ifndef NO_TRACI
518  if (TraCIServer::wasClosed()) {
520  }
521  if (stopTime < 0 && OptionsCont::getOptions().getInt("remote-port") == 0) {
522 #else
523  if (stopTime < 0) {
524 #endif
527  && (myInserter->getPendingFlowCount() == 0)
530  if (myPersonControl) {
532  }
533  if (myContainerControl) {
535  }
538  }
539  }
540  if (stopTime >= 0 && myStep >= stopTime) {
542  }
543  return SIMSTATE_RUNNING;
544 }
545 
546 
547 std::string
549  switch (state) {
551  return "";
553  return "The final simulation step has been reached.";
555  return "All vehicles have left the simulation.";
557  return "TraCI requested termination.";
559  return "An error occured (see log).";
561  return "Too many vehicles.";
562  default:
563  return "Unknown reason.";
564  }
565 }
566 
567 
568 void
570  // clear container
571  MSEdge::clear();
572  MSLane::clear();
573  MSRoute::clear();
581 }
582 
583 
584 void
586  // update detector values
588  const OptionsCont& oc = OptionsCont::getOptions();
589 
590  // check state dumps
591  if (oc.isSet("netstate-dump")) {
593  oc.getInt("netstate-dump.precision"));
594  }
595 
596  // check fcd dumps
597  if (OptionsCont::getOptions().isSet("fcd-output")) {
599  }
600 
601  // check emission dumps
602  if (OptionsCont::getOptions().isSet("emission-output")) {
604  oc.getInt("emission-output.precision"));
605  }
606 
607  // battery dumps
608  if (OptionsCont::getOptions().isSet("battery-output")) {
610  oc.getInt("battery-output.precision"));
611  }
612 
613  // check full dumps
614  if (OptionsCont::getOptions().isSet("full-output")) {
616  }
617 
618  // check queue dumps
619  if (OptionsCont::getOptions().isSet("queue-output")) {
621  }
622 
623  // check amitran dumps
624  if (OptionsCont::getOptions().isSet("amitran-output")) {
626  }
627 
628  // check vtk dumps
629  if (OptionsCont::getOptions().isSet("vtk-output")) {
630 
631  if (MSNet::getInstance()->getVehicleControl().getRunningVehicleNo() > 0) {
632  std::string timestep = time2string(myStep);
633  timestep = timestep.substr(0, timestep.length() - 3);
634  std::string output = OptionsCont::getOptions().getString("vtk-output");
635  std::string filename = output + "_" + timestep + ".vtp";
636 
637  OutputDevice_File dev = OutputDevice_File(filename, false);
638 
639  //build a huge mass of xml files
641 
642  }
643 
644  }
645 
646  // summary output
647  if (OptionsCont::getOptions().isSet("summary-output")) {
648  OutputDevice& od = OutputDevice::getDeviceByOption("summary-output");
649  unsigned int departedVehiclesNumber = myVehicleControl->getDepartedVehicleNo();
650  const SUMOReal meanWaitingTime = departedVehiclesNumber != 0 ? myVehicleControl->getTotalDepartureDelay() / (SUMOReal) departedVehiclesNumber : -1.;
651  unsigned int endedVehicleNumber = myVehicleControl->getEndedVehicleNo();
652  const SUMOReal meanTravelTime = endedVehicleNumber != 0 ? myVehicleControl->getTotalTravelTime() / (SUMOReal) endedVehicleNumber : -1.;
654  .writeAttr("inserted", myVehicleControl->getDepartedVehicleNo()).writeAttr("running", myVehicleControl->getRunningVehicleNo())
655  .writeAttr("waiting", myInserter->getWaitingVehicleNo()).writeAttr("ended", myVehicleControl->getEndedVehicleNo())
656  .writeAttr("meanWaitingTime", meanWaitingTime).writeAttr("meanTravelTime", meanTravelTime);
657  if (myLogExecutionTime) {
658  od.writeAttr("duration", mySimStepDuration);
659  }
660  od.closeTag();
661  }
662 
663  // write detector values
665 
666  // write link states
667  if (OptionsCont::getOptions().isSet("link-output")) {
668  OutputDevice& od = OutputDevice::getDeviceByOption("link-output");
669  od.openTag("timestep");
671  const MSEdgeVector& edges = myEdges->getEdges();
672  for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
673  const std::vector<MSLane*>& lanes = (*i)->getLanes();
674  for (std::vector<MSLane*>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
675  const std::vector<MSLink*>& links = (*j)->getLinkCont();
676  for (std::vector<MSLink*>::const_iterator k = links.begin(); k != links.end(); ++k) {
677  (*k)->writeApproaching(od, (*j)->getID());
678  }
679  }
680  }
681  od.closeTag();
682  }
683 }
684 
685 
686 bool
688  return myLogExecutionTime;
689 }
690 
691 
694  if (myPersonControl == 0) {
696  }
697  return *myPersonControl;
698 }
699 
702  if (myContainerControl == 0) {
704  }
705  return *myContainerControl;
706 }
707 
708 
711  if (myEdgeWeights == 0) {
713  }
714  return *myEdgeWeights;
715 }
716 
717 
718 void
720  std::cout << "Step #" << time2string(myStep);
721 }
722 
723 
724 void
726  if (myLogExecutionTime) {
727  std::ostringstream oss;
728  oss.setf(std::ios::fixed , std::ios::floatfield); // use decimal format
729  oss.setf(std::ios::showpoint); // print decimal point
730  oss << std::setprecision(OUTPUT_ACCURACY);
731  if (mySimStepDuration != 0) {
732  oss << " (" << mySimStepDuration << "ms ~= "
733  << (1000. / (SUMOReal) mySimStepDuration) << "*RT, ~"
735  } else {
736  oss << " (0ms ?*RT. ?";
737  }
738  oss << "UPS, vehicles"
739  << " TOT " << myVehicleControl->getDepartedVehicleNo()
740  << " ACT " << myVehicleControl->getRunningVehicleNo()
741  << ") ";
742  std::string prev = "Step #" + time2string(myStep - DELTA_T);
743  std::cout << oss.str().substr(0, 78 - prev.length());
744  }
745  std::cout << '\r';
746 }
747 
748 
749 void
751  if (find(myVehicleStateListeners.begin(), myVehicleStateListeners.end(), listener) == myVehicleStateListeners.end()) {
752  myVehicleStateListeners.push_back(listener);
753  }
754 }
755 
756 
757 void
759  std::vector<VehicleStateListener*>::iterator i = find(myVehicleStateListeners.begin(), myVehicleStateListeners.end(), listener);
760  if (i != myVehicleStateListeners.end()) {
761  myVehicleStateListeners.erase(i);
762  }
763 }
764 
765 
766 void
768  for (std::vector<VehicleStateListener*>::iterator i = myVehicleStateListeners.begin(); i != myVehicleStateListeners.end(); ++i) {
769  (*i)->vehicleStateChanged(vehicle, to);
770  }
771 }
772 
773 
774 
775 // ------ Insertion and retrieval of bus stops ------
776 bool
778  return myBusStopDict.add(busStop->getID(), busStop);
779 }
780 
781 
783 MSNet::getBusStop(const std::string& id) const {
784  return myBusStopDict.get(id);
785 }
786 
787 
788 std::string
789 MSNet::getBusStopID(const MSLane* lane, const SUMOReal pos) const {
790  const std::map<std::string, MSStoppingPlace*>& vals = myBusStopDict.getMyMap();
791  for (std::map<std::string, MSStoppingPlace*>::const_iterator it = vals.begin(); it != vals.end(); ++it) {
792  MSStoppingPlace* stop = it->second;
793  if (&stop->getLane() == lane && fabs(stop->getEndLanePosition() - pos) < POSITION_EPS) {
794  return stop->getID();
795  }
796  }
797  return "";
798 }
799 
800 // ------ Insertion and retrieval of container stops ------
801 bool
803  return myContainerStopDict.add(containerStop->getID(), containerStop);
804 }
805 
807 MSNet::getContainerStop(const std::string& id) const {
808  return myContainerStopDict.get(id);
809 }
810 
811 std::string
812 MSNet::getContainerStopID(const MSLane* lane, const SUMOReal pos) const {
813  const std::map<std::string, MSStoppingPlace*>& vals = myContainerStopDict.getMyMap();
814  for (std::map<std::string, MSStoppingPlace*>::const_iterator it = vals.begin(); it != vals.end(); ++it) {
815  MSStoppingPlace* stop = it->second;
816  if (&stop->getLane() == lane && fabs(stop->getEndLanePosition() - pos) < POSITION_EPS) {
817  return stop->getID();
818  }
819  }
820  return "";
821 }
822 
823 
824 bool
826  return myChargingStationDict.add(chargingStation->getID(), chargingStation);
827 }
828 
829 
831 MSNet::getChargingStation(const std::string& id) const {
832  return myChargingStationDict.get(id);
833 }
834 
835 
836 std::string
837 MSNet::getChargingStationID(const MSLane* lane, const SUMOReal pos) const {
838  const std::map<std::string, MSChargingStation*>& vals = myChargingStationDict.getMyMap();
839  for (std::map<std::string, MSChargingStation*>::const_iterator it = vals.begin(); it != vals.end(); ++it) {
840  MSChargingStation* chargingStation = it->second;
841  if (&chargingStation->getLane() == lane && chargingStation->getBeginLanePosition() <= pos && chargingStation->getEndLanePosition() >= pos) {
842  return chargingStation->getID();
843  }
844  }
845  return "";
846 }
847 
848 
850 MSNet::getRouterTT(const MSEdgeVector& prohibited) const {
851  if (!myRouterTTInitialized) {
852  myRouterTTInitialized = true;
853  const std::string routingAlgorithm = OptionsCont::getOptions().getString("routing-algorithm");
854  if (routingAlgorithm == "dijkstra") {
857  } else {
858  if (routingAlgorithm != "astar") {
859  WRITE_WARNING("TraCI and Triggers cannot use routing algorithm '" + routingAlgorithm + "'. using 'astar' instead.");
860  }
863  }
864  }
865  if (myRouterTTDijkstra != 0) {
866  myRouterTTDijkstra->prohibit(prohibited);
867  return *myRouterTTDijkstra;
868  } else {
869  assert(myRouterTTAStar != 0);
870  myRouterTTAStar->prohibit(prohibited);
871  return *myRouterTTAStar;
872  }
873 }
874 
875 
877 MSNet::getRouterEffort(const MSEdgeVector& prohibited) const {
878  if (myRouterEffort == 0) {
881  }
882  myRouterEffort->prohibit(prohibited);
883  return *myRouterEffort;
884 }
885 
886 
888 MSNet::getPedestrianRouter(const MSEdgeVector& prohibited) const {
889  if (myPedestrianRouter == 0) {
891  }
892  myPedestrianRouter->prohibit(prohibited);
893  return *myPedestrianRouter;
894 }
895 
896 
897 const NamedRTree&
899  if (!myLanesRTree.first) {
900  MSLane::fill(myLanesRTree.second);
901  myLanesRTree.first = true;
902  }
903  return myLanesRTree.second;
904 }
905 
906 
907 bool
909  const MSEdgeVector& edges = myEdges->getEdges();
910  for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
911  for (std::vector<MSLane*>::const_iterator i = (*e)->getLanes().begin(); i != (*e)->getLanes().end(); ++i) {
912  if ((*i)->getShape().hasElevation()) {
913  return true;
914  }
915  }
916  }
917  return false;
918 }
919 
920 /****************************************************************************/
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:783
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
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:653
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:725
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:81
long long int SUMOTime
Definition: SUMOTime.h:43
Interface for objects listening to vehicle state changes.
Definition: MSNet.h:563
long mySimStepEnd
Definition: MSNet.h:721
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:758
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:700
static SUMOReal getEffort(const MSEdge *const e, const SUMOVehicle *const v, SUMOReal t)
Returns the effort to pass an edge.
Definition: MSNet.cpp:127
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.
A lane area vehicles can halt at.
The simulation contains too many vehicles (.
Definition: MSNet.h:110
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:293
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:1266
MSVehicleControl * myVehicleControl
Controls vehicle building and deletion;.
Definition: MSNet.h:682
void updateDetectors(const SUMOTime step)
Computes detector values.
std::vector< SUMOTime > myStateDumpTimes
Times at which a state shall be written.
Definition: MSNet.h:736
virtual void execute(SUMOTime time)
Executes time-dependant commands.
DijkstraRouterEffort< MSEdge, SUMOVehicle, prohibited_withPermissions< MSEdge, SUMOVehicle > > * myRouterEffort
Definition: MSNet.h:784
bool hasInternalLinks() const
return whether the network contains internal links
Definition: MSNet.h:638
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
std::string getContainerStopID(const MSLane *lane, const SUMOReal pos) const
Returns the container stop close to the given position.
Definition: MSNet.cpp:812
int simulate(SUMOTime start, SUMOTime stop)
Simulates from timestep start to stop.
Definition: MSNet.cpp:303
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
MSPedestrianRouterDijkstra & getPedestrianRouter(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:888
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.
MSChargingStation * getChargingStation(const std::string &id) const
Returns the named charging station.
Definition: MSNet.cpp:831
bool addBusStop(MSStoppingPlace *busStop)
Adds a bus stop.
Definition: MSNet.cpp:777
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:159
bool myHavePermissions
Whether the network contains edges which not all vehicles may pass.
Definition: MSNet.h:744
SUMOTime DELTA_T
Definition: SUMOTime.cpp:39
MSEdgeControl * myEdges
Controls edges, performs vehicle movement;.
Definition: MSNet.h:688
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:738
bool myLogExecutionTime
Information whether the simulation duration shall be logged.
Definition: MSNet.h:715
Storage for geometrical objects.
static const std::string STAGE_LANECHANGE
Definition: MSNet.h:795
unsigned int getRunningNumber() const
Returns the number of build and inserted, but not yet deleted transportables.
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:768
Detectors container; responsible for string and output generation.
bool myLefthand
Whether the network was built for left-hand traffic.
Definition: MSNet.h:759
A storage for edge travel times and efforts.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:253
unsigned int getLoadedNumber() const
Returns the number of build transportables.
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:789
void addVehicleStateListener(VehicleStateListener *listener)
Adds a vehicle states listener.
Definition: MSNet.cpp:750
SimulationState
Possible states of a simulation - running or stopped with different reasons.
Definition: MSNet.h:98
MSPedestrianRouterDijkstra * myPedestrianRouter
Definition: MSNet.h:785
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
The simulated network and simulation perfomer.
Definition: MSNet.h:93
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:704
std::pair< bool, NamedRTree > myLanesRTree
An RTree structure holding lane IDs.
Definition: MSNet.h:789
Container for junctions; performs operations on all stored junctions.
DijkstraRouterTT< MSEdge, SUMOVehicle, prohibited_withPermissions< MSEdge, SUMOVehicle > > * myRouterTTDijkstra
Definition: MSNet.h:782
SUMOReal getTotalTravelTime() const
Returns the total travel time.
static bool gCheck4Accidents
Definition: MSGlobals.h:75
#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!)
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition: MSNet.cpp:701
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()
T get(const std::string &id) const
Retrieves an item.
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:66
A road/street connecting two junctions.
Definition: MSEdge.h:80
long long int myVehiclesMoved
The overall number of vehicle movements.
Definition: MSNet.h:727
long mySimStepBegin
The last simulation step begin, end and duration.
Definition: MSNet.h:721
static void close()
request termination of connection
The simulation does not contain further vehicles.
Definition: MSNet.h:104
unsigned int getLoadedVehicleNo() const
Returns the number of build vehicles.
bool hasNonWaiting() const
checks whether any transportable is still engaged in walking / stopping
static void generateOutputForUnfinished()
generate output for vehicles which are still in the network
An error occured during the simulation step.
Definition: MSNet.h:108
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:178
The main mesocopic simulation loop.
Definition: MELoop.h:56
void writeOutput()
Write netstate, summary and detector output.
Definition: MSNet.cpp:585
unsigned int getTeleportCount() const
return the number of teleports (including collisions)
unsigned int getWaitingVehicleNo() const
Returns the number of waiting vehicles.
MSStoppingPlace * getBusStop(const std::string &id) const
Returns the named bus stop.
Definition: MSNet.cpp:783
static std::string printStatistics()
get statistics for printing to stdout
MSInsertionControl * myInserter
Controls vehicle insertion;.
Definition: MSNet.h:694
Representation of a vehicle.
Definition: SUMOVehicle.h:66
bool myHasNeighs
Whether the network contains explicit neighbor lanes.
Definition: MSNet.h:753
void checkInsertions(SUMOTime time)
Checks "movement" of stored vehicles.
SUMORouteLoaderControl * myRouteLoaders
Route loader for dynamic loading of routes.
Definition: MSNet.h:671
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:693
void closeSimulation(SUMOTime start)
Closes the simulation (all files, connections, etc.)
Definition: MSNet.cpp:354
bool myLogStepNumber
Information whether the number of the simulation step shall be logged.
Definition: MSNet.h:718
An output device that encapsulates an ofstream.
static void clear()
Clears the dictionary.
Definition: MSEdge.cpp:705
SUMOTime getTargetTime()
Definition: TraCIServer.h:79
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:306
void closeBuilding(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
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:696
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:692
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
bool hasNeighs() const
return whether the network contains explicit neighbor lanes
Definition: MSNet.h:643
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:188
void preSimStepOutput() const
Prints the current step number.
Definition: MSNet.cpp:719
std::map< std::string, std::map< SUMOVehicleClass, SUMOReal > > myRestrictions
The vehicle class specific speed restrictions.
Definition: MSNet.h:747
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:762
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
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:536
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:850
unsigned int getJammedNumber() const
Returns the number of times a transportables was jammed.
static MSVehicleTransfer * getInstance()
Returns the instance of this object.
static const std::string STAGE_MOVEMENTS
Definition: MSNet.h:794
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:774
static MSNet * myInstance
Unique instance of MSNet.
Definition: MSNet.h:668
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:569
bool myRouterTTInitialized
Definition: MSNet.h:781
bool hasTransportables() const
checks whether any transportable waits to finish her plan
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:802
bool addChargingStation(MSChargingStation *chargingStation)
Adds a chargingg station.
Definition: MSNet.cpp:825
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:516
MSTransportableControl * myContainerControl
Controls container building and deletion;.
Definition: MSNet.h:686
MSJunctionControl * myJunctions
Controls junctions, realizes right-of-way rules;.
Definition: MSNet.h:690
void abortWaiting()
aborts the plan for any transportable that is still waiting for a ride
static void clear()
Clears the dictionary.
Definition: MSLane.cpp:1249
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:684
static const MSEdgeVector & getAllEdges()
Returns all edges with a numerical id.
Definition: MSEdge.cpp:699
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:908
static void cleanup()
remove state at simulation end
Definition: MSPModel.cpp:81
SUMOReal getBeginLanePosition() const
Returns the begin position of this stop.
static TraCIServer * getInstance()
Definition: TraCIServer.h:82
MSEventControl * myBeginOfTimestepEvents
Controls events executed at the begin of a time step;.
Definition: MSNet.h:698
A storage for options typed value containers)
Definition: OptionsCont.h:108
static void cleanup()
removes remaining vehicleInformation in sVehicles
MSEdgeWeightsStorage * myEdgeWeights
The net&#39;s knowledge about edge efforts/travel times;.
Definition: MSNet.h:706
MSStoppingPlace * getContainerStop(const std::string &id) const
Returns the named container stop.
Definition: MSNet.cpp:807
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:287
unsigned int emitVehicles(SUMOTime time)
Emits vehicles that want to depart at the given time.
static MELoop * gMesoNet
mesoscopic simulation infrastructure
Definition: MSGlobals.h:102
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:767
const NamedRTree & getLanesRTree() const
Returns an RTree that contains lane IDs.
Definition: MSNet.cpp:898
static void cleanup()
cleanup remaining data structures
void prohibit(const std::vector< E * > &toProhibit)
SUMOReal version() const
return the network version
Definition: MSNet.h:658
long mySimBeginMillis
The overall simulation duration.
Definition: MSNet.h:724
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:245
bool myHasElevation
Whether the network contains elevation data.
Definition: MSNet.h:756
static void write(OutputDevice &of, SUMOTime timestep, int precision)
Writes the complete network state of the given edges into the given device.
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 std::string getStateMessage(SimulationState state)
Returns the message to show if a certain state occurs.
Definition: MSNet.cpp:548
SUMOReal getMinimumTravelTime(const SUMOVehicle *const veh) const
returns the minimum travel time for the given vehicle
Definition: MSEdge.h:444
NamedObjectCont< MSChargingStation * > myChargingStationDict
Dictionary of charging Stations.
Definition: MSNet.h:771
bool logSimulationDuration() const
Returns whether duration shall be logged.
Definition: MSNet.cpp:687
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:674
std::string getChargingStationID(const MSLane *lane, const SUMOReal pos) const
Returns the charging station close to the given position.
Definition: MSNet.cpp:837
The class responsible for building and deletion of vehicles.
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:77
void simulationStep()
Performs a single simulation step.
Definition: MSNet.cpp:421
static long getCurrentMillis()
Returns the current time in milliseconds.
Definition: SysUtils.cpp:50
void simulate(SUMOTime tMax)
Perform simulation up to the given time.
Definition: MELoop.cpp:73
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:348
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:201
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterEffort(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:877
static const std::string STAGE_INSERTIONS
Definition: MSNet.h:796
MSEventControl * myInsertionEvents
Controls insertion events;.
Definition: MSNet.h:702
static bool gUseMesoSim
Definition: MSGlobals.h:90
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
const MSEdgeWeightsStorage & getWeightsStorage() const
Returns the vehicle&#39;s internal edge travel times/efforts container.
Definition: MSVehicle.cpp:684
long mySimStepDuration
Definition: MSNet.h:721
NamedObjectCont< MSStoppingPlace * > myBusStopDict
Dictionary of bus stops.
Definition: MSNet.h:765
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:750
unsigned int getEmergencyStops() const
return the number of emergency stops
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.
void prohibit(const std::vector< E * > &toProhibit)
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:710
static const std::string STAGE_EVENTS
string constants for simstep stages
Definition: MSNet.h:793