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 "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>
75 #include <utils/shapes/Polygon.h>
77 
79 #include "output/MSFCDExport.h"
81 
82 #include "output/MSBatteryExport.h"
83 
84 #include "output/MSFullExport.h"
85 #include "output/MSQueueExport.h"
86 #include "output/MSVTKExport.h"
87 #include "output/MSXMLRawOut.h"
90 #include <utils/common/SysUtils.h>
94 #include "MSGlobals.h"
99 #include "MSContainer.h"
100 #include "MSEdgeWeightsStorage.h"
101 #include "MSStateHandler.h"
102 
103 #include <mesosim/MELoop.h>
104 
105 #ifndef NO_TRACI
107 #endif
108 
109 #ifdef CHECK_MEMORY_LEAKS
110 #include <foreign/nvwa/debug_new.h>
111 #endif // CHECK_MEMORY_LEAKS
112 
113 
114 // ===========================================================================
115 // static member definitions
116 // ===========================================================================
118 
119 const std::string MSNet::STAGE_EVENTS("events");
120 const std::string MSNet::STAGE_MOVEMENTS("move");
121 const std::string MSNet::STAGE_LANECHANGE("laneChange");
122 const std::string MSNet::STAGE_INSERTIONS("insertion");
123 
124 // ===========================================================================
125 // member method definitions
126 // ===========================================================================
127 SUMOReal
128 MSNet::getEffort(const MSEdge* const e, const SUMOVehicle* const v, SUMOReal t) {
129  SUMOReal value;
130  const MSVehicle* const veh = dynamic_cast<const MSVehicle* const>(v);
131  if (veh != 0 && veh->getWeightsStorage().retrieveExistingEffort(e, t, value)) {
132  return value;
133  }
134  if (getInstance()->getWeightsStorage().retrieveExistingEffort(e, t, value)) {
135  return value;
136  }
137  return 0;
138 }
139 
140 
141 SUMOReal
142 MSNet::getTravelTime(const MSEdge* const e, const SUMOVehicle* const v, SUMOReal t) {
143  SUMOReal value;
144  const MSVehicle* const veh = dynamic_cast<const MSVehicle* const>(v);
145  if (veh != 0 && veh->getWeightsStorage().retrieveExistingTravelTime(e, t, value)) {
146  return value;
147  }
149  return value;
150  }
151  return e->getMinimumTravelTime(v);
152 }
153 
154 
155 
156 // ---------------------------------------------------------------------------
157 // MSNet - methods
158 // ---------------------------------------------------------------------------
159 MSNet*
161  if (myInstance != 0) {
162  return myInstance;
163  }
164  throw ProcessError("A network was not yet constructed.");
165 }
166 
167 
168 MSNet::MSNet(MSVehicleControl* vc, MSEventControl* beginOfTimestepEvents,
169  MSEventControl* endOfTimestepEvents, MSEventControl* insertionEvents,
170  ShapeContainer* shapeCont):
171  myVehiclesMoved(0),
172  myHavePermissions(false),
173  myHasInternalLinks(false),
174  myHasElevation(false),
175  myRouterTTInitialized(false),
177  myRouterTTAStar(0),
178  myRouterEffort(0),
179  myPedestrianRouter(0) {
180  if (myInstance != 0) {
181  throw ProcessError("A network was already constructed.");
182  }
184  myStep = string2time(oc.getString("begin"));
185  myLogExecutionTime = !oc.getBool("no-duration-log");
186  myLogStepNumber = !oc.getBool("no-step-log");
187  myInserter = new MSInsertionControl(*vc, string2time(oc.getString("max-depart-delay")), !oc.getBool("eager-insert"), oc.getInt("max-num-vehicles"));
188  myVehicleControl = vc;
190  myEdges = 0;
191  myJunctions = 0;
192  myRouteLoaders = 0;
193  myLogics = 0;
194  myPersonControl = 0;
195  myContainerControl = 0;
196  myEdgeWeights = 0;
197  myShapeContainer = shapeCont == 0 ? new ShapeContainer() : shapeCont;
198 
199  myBeginOfTimestepEvents = beginOfTimestepEvents;
200  myEndOfTimestepEvents = endOfTimestepEvents;
201  myInsertionEvents = insertionEvents;
202  myLanesRTree.first = false;
203 
205  MSGlobals::gMesoNet = new MELoop(string2time(oc.getString("meso-recheck")));
206  }
207  myInstance = this;
208 }
209 
210 
211 
212 
213 void
215  SUMORouteLoaderControl* routeLoaders,
216  MSTLLogicControl* tlc,
217  std::vector<SUMOTime> stateDumpTimes,
218  std::vector<std::string> stateDumpFiles,
219  bool hasInternalLinks,
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  }
240  myVersion = version;
241 }
242 
243 
245  // delete events first maybe they do some cleanup
248  delete myEndOfTimestepEvents;
250  delete myInsertionEvents;
251  myInsertionEvents = 0;
252  // delete controls
253  delete myJunctions;
254  delete myDetectorControl;
255  // delete mean data
256  delete myEdges;
257  delete myInserter;
258  delete myLogics;
259  delete myRouteLoaders;
260  delete myVehicleControl;
261  if (myPersonControl != 0) {
262  delete myPersonControl;
263  }
264  if (myContainerControl != 0) {
265  delete myContainerControl;
266  }
267  delete myShapeContainer;
268  delete myEdgeWeights;
269  delete myRouterTTDijkstra;
270  delete myRouterTTAStar;
271  delete myRouterEffort;
272  if (myPedestrianRouter != 0) {
273  delete myPedestrianRouter;
274  }
275  myLanesRTree.second.RemoveAll();
276  clearAll();
278  delete MSGlobals::gMesoNet;
279  }
280 // delete myPedestrianRouter;
281  myInstance = 0;
282 }
283 
284 
285 void
286 MSNet::addRestriction(const std::string& id, const SUMOVehicleClass svc, const SUMOReal speed) {
287  myRestrictions[id][svc] = speed;
288 }
289 
290 
291 const std::map<SUMOVehicleClass, SUMOReal>*
292 MSNet::getRestrictions(const std::string& id) const {
293  std::map<std::string, std::map<SUMOVehicleClass, SUMOReal> >::const_iterator i = myRestrictions.find(id);
294  if (i == myRestrictions.end()) {
295  return 0;
296  }
297  return &i->second;
298 }
299 
300 
301 int
303  // report the begin when wished
304  WRITE_MESSAGE("Simulation started with time: " + time2string(start));
305  // the simulation loop
307  myStep = start;
308  // preload the routes especially for TraCI
309  loadRoutes();
310 #ifndef NO_TRACI
311 #ifdef HAVE_PYTHON
312  if (OptionsCont::getOptions().isSet("python-script")) {
313  TraCIServer::runEmbedded(OptionsCont::getOptions().getString("python-script"));
314  closeSimulation(start);
315  WRITE_MESSAGE("Simulation ended at time: " + time2string(getCurrentTimeStep()));
316  WRITE_MESSAGE("Reason: Script ended");
317  return 0;
318  }
319 #endif
320 #endif
321  while (state == SIMSTATE_RUNNING) {
322  if (myLogStepNumber) {
324  }
325  simulationStep();
326  if (myLogStepNumber) {
328  }
329  state = simulationState(stop);
330 #ifndef NO_TRACI
331  if (state != SIMSTATE_RUNNING) {
332  if (OptionsCont::getOptions().getInt("remote-port") != 0 && !TraCIServer::wasClosed()) {
333  state = SIMSTATE_RUNNING;
334  }
335  }
336 #endif
337  }
338  // report the end when wished
339  WRITE_MESSAGE("Simulation ended at time: " + time2string(getCurrentTimeStep()));
340  WRITE_MESSAGE("Reason: " + getStateMessage(state));
341  // exit simulation loop
342  closeSimulation(start);
343  return 0;
344 }
345 
346 void
349 }
350 
351 
352 void
354  if (myLogExecutionTime) {
355  long duration = SysUtils::getCurrentMillis() - mySimBeginMillis;
356  std::ostringstream msg;
357  // print performance notice
358  msg << "Performance: " << "\n" << " Duration: " << duration << "ms" << "\n";
359  if (duration != 0) {
360  msg << " Real time factor: " << (STEPS2TIME(myStep - start) * 1000. / (SUMOReal)duration) << "\n";
361  msg.setf(std::ios::fixed , std::ios::floatfield); // use decimal format
362  msg.setf(std::ios::showpoint); // print decimal point
363  msg << " UPS: " << ((SUMOReal)myVehiclesMoved / ((SUMOReal)duration / 1000)) << "\n";
364  }
365  // print vehicle statistics
366  const std::string discardNotice = ((myVehicleControl->getLoadedVehicleNo() != myVehicleControl->getDepartedVehicleNo()) ?
367  " (Loaded: " + toString(myVehicleControl->getLoadedVehicleNo()) + ")" : "");
368  msg << "Vehicles: " << "\n"
369  << " Inserted: " << myVehicleControl->getDepartedVehicleNo() << discardNotice << "\n"
370  << " Running: " << myVehicleControl->getRunningVehicleNo() << "\n"
371  << " Waiting: " << myInserter->getWaitingVehicleNo() << "\n";
372 
373  if (myVehicleControl->getTeleportCount() > 0) {
374  // print optional teleport statistics
375  std::vector<std::string> reasons;
376  if (myVehicleControl->getCollisionCount() > 0) {
377  reasons.push_back("Collisions: " + toString(myVehicleControl->getCollisionCount()));
378  }
379  if (myVehicleControl->getTeleportsJam() > 0) {
380  reasons.push_back("Jam: " + toString(myVehicleControl->getTeleportsJam()));
381  }
382  if (myVehicleControl->getTeleportsYield() > 0) {
383  reasons.push_back("Yield: " + toString(myVehicleControl->getTeleportsYield()));
384  }
386  reasons.push_back("Wrong Lane: " + toString(myVehicleControl->getTeleportsWrongLane()));
387  }
388  msg << "Teleports: " << myVehicleControl->getTeleportCount() << " (" << joinToString(reasons, ", ") << ")\n";
389  }
390  if (myVehicleControl->getEmergencyStops() > 0) {
391  msg << "Emergency Stops: " << myVehicleControl->getEmergencyStops() << "\n";
392  }
394  msg << "Persons: " << "\n"
395  << " Inserted: " << myPersonControl->getLoadedPersonNumber() << "\n"
396  << " Running: " << myPersonControl->getRunningPersonNumber() << "\n";
398  msg << " Jammed: " << myPersonControl->getJammedPersonNumber() << "\n";
399  }
400  }
401  if (OptionsCont::getOptions().getBool("duration-log.statistics")) {
403  }
404  WRITE_MESSAGE(msg.str());
405  }
407  if (OptionsCont::getOptions().getBool("vehroute-output.write-unfinished")) {
409  }
410  if (OptionsCont::getOptions().getBool("tripinfo-output.write-unfinished")) {
412  }
413 #ifndef NO_TRACI
415 #endif
416 }
417 
418 
419 void
421 #ifndef NO_TRACI
424  if (t != 0 && t->getTargetTime() != 0 && t->getTargetTime() < myStep) {
425  return;
426  }
427 #endif
428  // execute beginOfTimestepEvents
429  if (myLogExecutionTime) {
431  }
432  // simulation state output
433  std::vector<SUMOTime>::iterator timeIt = find(myStateDumpTimes.begin(), myStateDumpTimes.end(), myStep);
434  if (timeIt != myStateDumpTimes.end()) {
435  const int dist = (int)distance(myStateDumpTimes.begin(), timeIt);
437  }
439 #ifdef HAVE_FOX
440  MSDevice_Routing::waitForAll();
441 #endif
444  }
445  // check whether the tls programs need to be switched
447 
450  } else {
451  // assure all lanes with vehicles are 'active'
453 
454  // compute safe velocities for all vehicles for the next few lanes
455  // also register ApproachingVehicleInformation for all links
457 
458  // decide right-of-way and execute movements
462  }
463 
464  // vehicles may change lanes
466 
469  }
470  }
471  loadRoutes();
472 
473  // persons
474  if (myPersonControl != 0 && myPersonControl->hasPersons()) {
476  }
477  // insert vehicles
478  myInserter->determineCandidates(myStep); // containers
479  if (myContainerControl != 0) {
481  }
483 #ifdef HAVE_FOX
484  MSDevice_Routing::waitForAll();
485 #endif
489  }
491 
492  // execute endOfTimestepEvents
494 
495 #ifndef NO_TRACI
496  if (TraCIServer::getInstance() != 0) {
498  }
499 #endif
500  // update and write (if needed) detector values
501  writeOutput();
502 
503  if (myLogExecutionTime) {
507  }
508  myStep += DELTA_T;
509 }
510 
511 
514 #ifndef NO_TRACI
515  if (TraCIServer::wasClosed()) {
517  }
518  if (stopTime < 0 && OptionsCont::getOptions().getInt("remote-port") == 0) {
519 #else
520  if (stopTime < 0) {
521 #endif
524  && (myInserter->getPendingFlowCount() == 0)
527  if (myPersonControl) {
529  }
530  if (myContainerControl) {
532  }
535  }
536  }
537  if (stopTime >= 0 && myStep >= stopTime) {
539  }
540  return SIMSTATE_RUNNING;
541 }
542 
543 
544 std::string
546  switch (state) {
548  return "";
550  return "The final simulation step has been reached.";
552  return "All vehicles have left the simulation.";
554  return "TraCI requested termination.";
556  return "An error occured (see log).";
558  return "Too many vehicles.";
559  default:
560  return "Unknown reason.";
561  }
562 }
563 
564 
565 void
567  // clear container
568  MSEdge::clear();
569  MSLane::clear();
570  MSRoute::clear();
578 }
579 
580 
581 void
583  // update detector values
585  const OptionsCont& oc = OptionsCont::getOptions();
586 
587  // check state dumps
588  if (oc.isSet("netstate-dump")) {
590  oc.getInt("netstate-dump.precision"));
591  }
592 
593  // check fcd dumps
594  if (OptionsCont::getOptions().isSet("fcd-output")) {
596  }
597 
598  // check emission dumps
599  if (OptionsCont::getOptions().isSet("emission-output")) {
601  oc.getInt("emission-output.precision"));
602  }
603 
604  // battery dumps
605  if (OptionsCont::getOptions().isSet("battery-output")) {
607  oc.getInt("battery-output.precision"));
608  }
609 
610  // check full dumps
611  if (OptionsCont::getOptions().isSet("full-output")) {
613  }
614 
615  // check queue dumps
616  if (OptionsCont::getOptions().isSet("queue-output")) {
618  }
619 
620  // check amitran dumps
621  if (OptionsCont::getOptions().isSet("amitran-output")) {
623  }
624 
625  // check vtk dumps
626  if (OptionsCont::getOptions().isSet("vtk-output")) {
627 
628  if (MSNet::getInstance()->getVehicleControl().getRunningVehicleNo() > 0) {
629  std::string timestep = time2string(myStep);
630  timestep = timestep.substr(0, timestep.length() - 3);
631  std::string output = OptionsCont::getOptions().getString("vtk-output");
632  std::string filename = output + "_" + timestep + ".vtp";
633 
634  OutputDevice_File dev = OutputDevice_File(filename, false);
635 
636  //build a huge mass of xml files
638 
639  }
640 
641  }
642 
643  // summary output
644  if (OptionsCont::getOptions().isSet("summary-output")) {
645  OutputDevice& od = OutputDevice::getDeviceByOption("summary-output");
646  unsigned int departedVehiclesNumber = myVehicleControl->getDepartedVehicleNo();
647  const SUMOReal meanWaitingTime = departedVehiclesNumber != 0 ? myVehicleControl->getTotalDepartureDelay() / (SUMOReal) departedVehiclesNumber : -1.;
648  unsigned int endedVehicleNumber = myVehicleControl->getEndedVehicleNo();
649  const SUMOReal meanTravelTime = endedVehicleNumber != 0 ? myVehicleControl->getTotalTravelTime() / (SUMOReal) endedVehicleNumber : -1.;
651  .writeAttr("inserted", myVehicleControl->getDepartedVehicleNo()).writeAttr("running", myVehicleControl->getRunningVehicleNo())
652  .writeAttr("waiting", myInserter->getWaitingVehicleNo()).writeAttr("ended", myVehicleControl->getEndedVehicleNo())
653  .writeAttr("meanWaitingTime", meanWaitingTime).writeAttr("meanTravelTime", meanTravelTime);
654  if (myLogExecutionTime) {
655  od.writeAttr("duration", mySimStepDuration);
656  }
657  od.closeTag();
658  }
659 
660  // write detector values
662 
663  // write link states
664  if (OptionsCont::getOptions().isSet("link-output")) {
665  OutputDevice& od = OutputDevice::getDeviceByOption("link-output");
666  od.openTag("timestep");
668  const MSEdgeVector& edges = myEdges->getEdges();
669  for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
670  const std::vector<MSLane*>& lanes = (*i)->getLanes();
671  for (std::vector<MSLane*>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
672  const std::vector<MSLink*>& links = (*j)->getLinkCont();
673  for (std::vector<MSLink*>::const_iterator k = links.begin(); k != links.end(); ++k) {
674  (*k)->writeApproaching(od, (*j)->getID());
675  }
676  }
677  }
678  od.closeTag();
679  }
680 }
681 
682 
683 bool
685  return myLogExecutionTime;
686 }
687 
688 
691  if (myPersonControl == 0) {
693  }
694  return *myPersonControl;
695 }
696 
699  if (myContainerControl == 0) {
701  }
702  return *myContainerControl;
703 }
704 
705 
708  if (myEdgeWeights == 0) {
710  }
711  return *myEdgeWeights;
712 }
713 
714 
715 void
717  std::cout << "Step #" << time2string(myStep);
718 }
719 
720 
721 void
723  if (myLogExecutionTime) {
724  std::ostringstream oss;
725  oss.setf(std::ios::fixed , std::ios::floatfield); // use decimal format
726  oss.setf(std::ios::showpoint); // print decimal point
727  oss << std::setprecision(OUTPUT_ACCURACY);
728  if (mySimStepDuration != 0) {
729  oss << " (" << mySimStepDuration << "ms ~= "
730  << (1000. / (SUMOReal) mySimStepDuration) << "*RT, ~"
732  } else {
733  oss << " (0ms ?*RT. ?";
734  }
735  oss << "UPS, vehicles"
736  << " TOT " << myVehicleControl->getDepartedVehicleNo()
737  << " ACT " << myVehicleControl->getRunningVehicleNo()
738  << ") ";
739  std::string prev = "Step #" + time2string(myStep - DELTA_T);
740  std::cout << oss.str().substr(0, 78 - prev.length());
741  }
742  std::cout << '\r';
743 }
744 
745 
746 void
748  if (find(myVehicleStateListeners.begin(), myVehicleStateListeners.end(), listener) == myVehicleStateListeners.end()) {
749  myVehicleStateListeners.push_back(listener);
750  }
751 }
752 
753 
754 void
756  std::vector<VehicleStateListener*>::iterator i = find(myVehicleStateListeners.begin(), myVehicleStateListeners.end(), listener);
757  if (i != myVehicleStateListeners.end()) {
758  myVehicleStateListeners.erase(i);
759  }
760 }
761 
762 
763 void
765  for (std::vector<VehicleStateListener*>::iterator i = myVehicleStateListeners.begin(); i != myVehicleStateListeners.end(); ++i) {
766  (*i)->vehicleStateChanged(vehicle, to);
767  }
768 }
769 
770 
771 
772 // ------ Insertion and retrieval of bus stops ------
773 bool
775  return myBusStopDict.add(busStop->getID(), busStop);
776 }
777 
778 
780 MSNet::getBusStop(const std::string& id) const {
781  return myBusStopDict.get(id);
782 }
783 
784 
785 std::string
786 MSNet::getBusStopID(const MSLane* lane, const SUMOReal pos) const {
787  const std::map<std::string, MSStoppingPlace*>& vals = myBusStopDict.getMyMap();
788  for (std::map<std::string, MSStoppingPlace*>::const_iterator it = vals.begin(); it != vals.end(); ++it) {
789  MSStoppingPlace* stop = it->second;
790  if (&stop->getLane() == lane && fabs(stop->getEndLanePosition() - pos) < POSITION_EPS) {
791  return stop->getID();
792  }
793  }
794  return "";
795 }
796 
797 // ------ Insertion and retrieval of container stops ------
798 bool
800  return myContainerStopDict.add(containerStop->getID(), containerStop);
801 }
802 
804 MSNet::getContainerStop(const std::string& id) const {
805  return myContainerStopDict.get(id);
806 }
807 
808 std::string
809 MSNet::getContainerStopID(const MSLane* lane, const SUMOReal pos) const {
810  const std::map<std::string, MSStoppingPlace*>& vals = myContainerStopDict.getMyMap();
811  for (std::map<std::string, MSStoppingPlace*>::const_iterator it = vals.begin(); it != vals.end(); ++it) {
812  MSStoppingPlace* stop = it->second;
813  if (&stop->getLane() == lane && fabs(stop->getEndLanePosition() - pos) < POSITION_EPS) {
814  return stop->getID();
815  }
816  }
817  return "";
818 }
819 
820 
821 bool
823  return myChargingStationDict.add(chargingStation->getID(), chargingStation);
824 }
825 
826 
828 MSNet::getChargingStation(const std::string& id) const {
829  return myChargingStationDict.get(id);
830 }
831 
832 
833 std::string
834 MSNet::getChargingStationID(const MSLane* lane, const SUMOReal pos) const {
835  const std::map<std::string, MSChargingStation*>& vals = myChargingStationDict.getMyMap();
836  for (std::map<std::string, MSChargingStation*>::const_iterator it = vals.begin(); it != vals.end(); ++it) {
837  MSChargingStation* chargingStation = it->second;
838  if (&chargingStation->getLane() == lane && chargingStation->getBeginLanePosition() <= pos && chargingStation->getEndLanePosition() >= pos) {
839  return chargingStation->getID();
840  }
841  }
842  return "";
843 }
844 
845 
847 MSNet::getRouterTT(const MSEdgeVector& prohibited) const {
848  if (!myRouterTTInitialized) {
849  myRouterTTInitialized = true;
850  const std::string routingAlgorithm = OptionsCont::getOptions().getString("routing-algorithm");
851  if (routingAlgorithm == "dijkstra") {
854  } else {
855  if (routingAlgorithm != "astar") {
856  WRITE_WARNING("TraCI and Triggers cannot use routing algorithm '" + routingAlgorithm + "'. using 'astar' instead.");
857  }
860  }
861  }
862  if (myRouterTTDijkstra != 0) {
863  myRouterTTDijkstra->prohibit(prohibited);
864  return *myRouterTTDijkstra;
865  } else {
866  assert(myRouterTTAStar != 0);
867  myRouterTTAStar->prohibit(prohibited);
868  return *myRouterTTAStar;
869  }
870 }
871 
872 
874 MSNet::getRouterEffort(const MSEdgeVector& prohibited) const {
875  if (myRouterEffort == 0) {
878  }
879  myRouterEffort->prohibit(prohibited);
880  return *myRouterEffort;
881 }
882 
883 
885 MSNet::getPedestrianRouter(const MSEdgeVector& prohibited) const {
886  if (myPedestrianRouter == 0) {
888  }
889  myPedestrianRouter->prohibit(prohibited);
890  return *myPedestrianRouter;
891 }
892 
893 
894 const NamedRTree&
896  if (!myLanesRTree.first) {
897  MSLane::fill(myLanesRTree.second);
898  myLanesRTree.first = true;
899  }
900  return myLanesRTree.second;
901 }
902 
903 
904 bool
906  const MSEdgeVector& edges = myEdges->getEdges();
907  for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
908  for (std::vector<MSLane*>::const_iterator i = (*e)->getLanes().begin(); i != (*e)->getLanes().end(); ++i) {
909  if ((*i)->getShape().hasElevation()) {
910  return true;
911  }
912  }
913  }
914  return false;
915 }
916 
917 /****************************************************************************/
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: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:722
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:755
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:128
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: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:292
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:812
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)
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:809
int simulate(SUMOTime start, SUMOTime stop)
Simulates from timestep start to stop.
Definition: MSNet.cpp:302
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:885
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:828
bool addBusStop(MSStoppingPlace *busStop)
Adds a bus stop.
Definition: MSNet.cpp:774
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:214
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:160
bool myHavePermissions
Whether the network contains edges which not all vehicles may pass.
Definition: MSNet.h:729
SUMOTime DELTA_T
Definition: SUMOTime.cpp:39
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:786
void addVehicleStateListener(VehicleStateListener *listener)
Adds a vehicle states listener.
Definition: MSNet.cpp:747
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
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:75
#define OUTPUT_ACCURACY
Definition: config.h:163
static void write(OutputDevice &of, SUMOTime timestep)
Export the queueing length in front of a junction (very experimental!)
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:58
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:65
A road/street connecting two junctions.
Definition: MSEdge.h:80
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:178
The main mesocopic simulation loop.
Definition: MELoop.h:56
void writeOutput()
Write netstate, summary and detector output.
Definition: MSNet.cpp:582
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:780
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:353
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:698
static void clear()
Clears the dictionary.
Definition: MSEdge.cpp:617
SUMOTime getTargetTime()
Definition: TraCIServer.h:79
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:142
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:46
void check2Switch(SUMOTime step)
Checks whether any WAUT is trying to switch a tls into another program.
#define POSITION_EPS
Definition: config.h:187
void preSimStepOutput() const
Prints the current step number.
Definition: MSNet.cpp:716
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
PedestrianRouterDijkstra< MSEdge, MSLane, MSJunction, MSVehicle > MSPedestrianRouterDijkstra
Definition: MSNet.h:115
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:54
SUMOReal myVersion
the network version
Definition: MSNet.h:744
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
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:847
bool hasNonWaiting() const
checks whether any person is still engaged in walking / stopping
static MSVehicleTransfer * getInstance()
Returns the instance of this object.
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:566
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:799
bool addChargingStation(MSChargingStation *chargingStation)
Adds a chargingg station.
Definition: MSNet.cpp:822
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:513
MSJunctionControl * myJunctions
Controls junctions, realizes right-of-way rules;.
Definition: MSNet.h:675
virtual MSPersonControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:690
static void clear()
Clears the dictionary.
Definition: MSLane.cpp:795
static void write(OutputDevice &of, SUMOTime timestep, int precision)
Writes the complete network state of the given edges into the given device.
static const MSEdgeVector & getAllEdges()
Returns all edges with a numerical id.
Definition: MSEdge.cpp:611
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:905
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:683
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:691
MSStoppingPlace * getContainerStop(const std::string &id) const
Returns the named container stop.
Definition: MSNet.cpp:804
MSNet(MSVehicleControl *vc, MSEventControl *beginOfTimestepEvents, MSEventControl *endOfTimestepEvents, MSEventControl *insertionEvents, ShapeContainer *shapeCont=0)
Constructor.
Definition: MSNet.cpp:168
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:286
unsigned int emitVehicles(SUMOTime time)
Emits vehicles that want to depart at the given time.
static MELoop * gMesoNet
mesoscopic simulation infrastructure
Definition: MSGlobals.h:99
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:764
const NamedRTree & getLanesRTree() const
Returns an RTree that contains lane IDs.
Definition: MSNet.cpp:895
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:160
virtual ~MSNet()
Destructor.
Definition: MSNet.cpp:244
bool myHasElevation
Whether the network contains elevation data.
Definition: MSNet.h:738
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:213
static std::string getStateMessage(SimulationState state)
Returns the message to show if a certain state occurs.
Definition: MSNet.cpp:545
SUMOReal getMinimumTravelTime(const SUMOVehicle *const veh) const
returns the minimum travel time for the given vehicle
Definition: MSEdge.h:437
NamedObjectCont< MSChargingStation * > myChargingStationDict
Dictionary of charging Stations.
Definition: MSNet.h:753
bool logSimulationDuration() const
Returns whether duration shall be logged.
Definition: MSNet.cpp:684
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:834
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:420
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:347
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:874
static const std::string STAGE_INSERTIONS
Definition: MSNet.h:778
MSEventControl * myInsertionEvents
Controls insertion events;.
Definition: MSNet.h:687
static bool gUseMesoSim
Definition: MSGlobals.h:87
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:641
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.
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:707
static const std::string STAGE_EVENTS
string constants for simstep stages
Definition: MSNet.h:775