SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 #include "output/MSFullExport.h"
81 #include "output/MSQueueExport.h"
82 #include "output/MSVTKExport.h"
83 #include "output/MSXMLRawOut.h"
86 #include <utils/common/SysUtils.h>
90 #include "MSGlobals.h"
95 #include "MSContainer.h"
96 #include "MSEdgeWeightsStorage.h"
97 #include "MSStateHandler.h"
98 
99 #ifdef HAVE_INTERNAL
100 #include <mesosim/MELoop.h>
102 #endif
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  myHaveRestrictions(false),
172  myHasInternalLinks(false),
173  myRouterTTInitialized(false),
174  myRouterTTDijkstra(0),
175  myRouterTTAStar(0),
176  myRouterEffort(0),
177  myPedestrianRouter(0) {
178  if (myInstance != 0) {
179  throw ProcessError("A network was already constructed.");
180  }
182  myStep = string2time(oc.getString("begin"));
183  myLogExecutionTime = !oc.getBool("no-duration-log");
184  myLogStepNumber = !oc.getBool("no-step-log");
185  myTooManyVehicles = oc.getInt("max-num-vehicles");
186  myInserter = new MSInsertionControl(*vc, string2time(oc.getString("max-depart-delay")), !oc.getBool("eager-insert"));
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 
203 #ifdef HAVE_INTERNAL
205  MSGlobals::gMesoNet = new MELoop(string2time(oc.getString("meso-recheck")));
206  }
207 #endif
208  myInstance = this;
209 }
210 
211 
212 
213 
214 void
216  SUMORouteLoaderControl* routeLoaders,
217  MSTLLogicControl* tlc,
218  std::vector<SUMOTime> stateDumpTimes,
219  std::vector<std::string> stateDumpFiles,
220  bool hasInternalLinks) {
221  myEdges = edges;
222  myJunctions = junctions;
223  myRouteLoaders = routeLoaders;
224  myLogics = tlc;
225  // save the time the network state shall be saved at
226  myStateDumpTimes = stateDumpTimes;
227  myStateDumpFiles = stateDumpFiles;
228 
229  // set requests/responses
231 
232  // initialise performance computation
233  if (myLogExecutionTime) {
235  }
237 }
238 
239 
241  // delete events first maybe they do some cleanup
244  delete myEndOfTimestepEvents;
246  delete myInsertionEvents;
247  myInsertionEvents = 0;
248  // delete controls
249  delete myJunctions;
250  delete myDetectorControl;
251  // delete mean data
252  delete myEdges;
253  delete myInserter;
254  delete myLogics;
255  delete myRouteLoaders;
256  delete myVehicleControl;
257  if (myPersonControl != 0) {
258  delete myPersonControl;
259  }
260  if (myContainerControl != 0) {
261  delete myContainerControl;
262  }
263  delete myShapeContainer;
264  delete myEdgeWeights;
265  delete myRouterTTDijkstra;
266  delete myRouterTTAStar;
267  delete myRouterEffort;
268  myLanesRTree.second.RemoveAll();
269  clearAll();
270 #ifdef HAVE_INTERNAL
272  delete MSGlobals::gMesoNet;
273  }
274 #endif
275  myInstance = 0;
276 }
277 
278 
279 int
281  // report the begin when wished
282  WRITE_MESSAGE("Simulation started with time: " + time2string(start));
283  // the simulation loop
285  myStep = start;
286  // preload the routes especially for TraCI
287  loadRoutes();
288 #ifndef NO_TRACI
289 #ifdef HAVE_PYTHON
290  if (OptionsCont::getOptions().isSet("python-script")) {
291  TraCIServer::runEmbedded(OptionsCont::getOptions().getString("python-script"));
292  closeSimulation(start);
293  WRITE_MESSAGE("Simulation ended at time: " + time2string(getCurrentTimeStep()));
294  WRITE_MESSAGE("Reason: Script ended");
295  return 0;
296  }
297 #endif
298 #endif
299  while (state == SIMSTATE_RUNNING) {
300  if (myLogStepNumber) {
302  }
303  simulationStep();
304  if (myLogStepNumber) {
306  }
307  state = simulationState(stop);
308 #ifndef NO_TRACI
309  if (state != SIMSTATE_RUNNING) {
310  if (OptionsCont::getOptions().getInt("remote-port") != 0 && !TraCIServer::wasClosed()) {
311  state = SIMSTATE_RUNNING;
312  }
313  }
314 #endif
315  }
316  // report the end when wished
317  WRITE_MESSAGE("Simulation ended at time: " + time2string(getCurrentTimeStep()));
318  WRITE_MESSAGE("Reason: " + getStateMessage(state));
319  // exit simulation loop
320  closeSimulation(start);
321  return 0;
322 }
323 
324 void
327 }
328 
329 
330 void
332  if (myLogExecutionTime) {
333  long duration = SysUtils::getCurrentMillis() - mySimBeginMillis;
334  std::ostringstream msg;
335  // print performance notice
336  msg << "Performance: " << "\n" << " Duration: " << duration << "ms" << "\n";
337  if (duration != 0) {
338  msg << " Real time factor: " << (STEPS2TIME(myStep - start) * 1000. / (SUMOReal)duration) << "\n";
339  msg.setf(std::ios::fixed , std::ios::floatfield); // use decimal format
340  msg.setf(std::ios::showpoint); // print decimal point
341  msg << " UPS: " << ((SUMOReal)myVehiclesMoved / ((SUMOReal)duration / 1000)) << "\n";
342  }
343  // print vehicle statistics
344  const std::string discardNotice = ((myVehicleControl->getLoadedVehicleNo() != myVehicleControl->getDepartedVehicleNo()) ?
345  " (Loaded: " + toString(myVehicleControl->getLoadedVehicleNo()) + ")" : "");
346  msg << "Vehicles: " << "\n"
347  << " Inserted: " << myVehicleControl->getDepartedVehicleNo() << discardNotice << "\n"
348  << " Running: " << myVehicleControl->getRunningVehicleNo() << "\n"
349  << " Waiting: " << myInserter->getWaitingVehicleNo() << "\n";
350 
351  if (myVehicleControl->getTeleportCount() > 0) {
352  // print optional teleport statistics
353  std::vector<std::string> reasons;
354  if (myVehicleControl->getCollisionCount() > 0) {
355  reasons.push_back("Collisions: " + toString(myVehicleControl->getCollisionCount()));
356  }
357  if (myVehicleControl->getTeleportsJam() > 0) {
358  reasons.push_back("Jam: " + toString(myVehicleControl->getTeleportsJam()));
359  }
360  if (myVehicleControl->getTeleportsYield() > 0) {
361  reasons.push_back("Yield: " + toString(myVehicleControl->getTeleportsYield()));
362  }
364  reasons.push_back("Wrong Lane: " + toString(myVehicleControl->getTeleportsWrongLane()));
365  }
366  msg << "Teleports: " << myVehicleControl->getTeleportCount() << " (" << joinToString(reasons, ", ") << ")\n";
367  }
368  if (myVehicleControl->getEmergencyStops() > 0) {
369  msg << "Emergency Stops: " << myVehicleControl->getEmergencyStops() << "\n";
370  }
371  WRITE_MESSAGE(msg.str());
372  }
374  if (OptionsCont::getOptions().getBool("vehroute-output.write-unfinished")) {
376  }
377  if (OptionsCont::getOptions().getBool("tripinfo-output.write-unfinished")) {
379  }
380 #ifndef NO_TRACI
382 #endif
383 }
384 
385 
386 void
388 #ifndef NO_TRACI
391  if (t != 0 && t->getTargetTime() != 0 && t->getTargetTime() < myStep) {
392  return;
393  }
394 #endif
395  // execute beginOfTimestepEvents
396  if (myLogExecutionTime) {
398  }
399  // simulation state output
400  std::vector<SUMOTime>::iterator timeIt = find(myStateDumpTimes.begin(), myStateDumpTimes.end(), myStep);
401  if (timeIt != myStateDumpTimes.end()) {
402  const int dist = (int)distance(myStateDumpTimes.begin(), timeIt);
404  }
406 #ifdef HAVE_FOX
407  MSDevice_Routing::waitForAll();
408 #endif
411  }
412  // check whether the tls programs need to be switched
414 
415 #ifdef HAVE_INTERNAL
417  MSGlobals::gMesoNet->simulate(myStep);
418  } else {
419 #endif
420 
421  // assure all lanes with vehicles are 'active'
423 
424  // compute safe velocities for all vehicles for the next few lanes
425  // also register ApproachingVehicleInformation for all links
427 
428  // decide right-of-way and execute movements
432  }
433 
434  // vehicles may change lanes
436 
439  }
440 #ifdef HAVE_INTERNAL
441  }
442 #endif
443  loadRoutes();
444 
445  // persons
446  if (myPersonControl != 0 && myPersonControl->hasPersons()) {
448  }
449  // insert vehicles
450  myInserter->determineCandidates(myStep); // containers
451  if (myContainerControl != 0) {
453  }
455 #ifdef HAVE_FOX
456  MSDevice_Routing::waitForAll();
457 #endif
461  }
463 
464  // execute endOfTimestepEvents
466 
467 #ifndef NO_TRACI
468  if (TraCIServer::getInstance() != 0) {
470  }
471 #endif
472  // update and write (if needed) detector values
473  writeOutput();
474 
475  if (myLogExecutionTime) {
479  }
480  myStep += DELTA_T;
481 }
482 
483 
488  }
489 #ifndef NO_TRACI
490  if (TraCIServer::wasClosed()) {
492  }
493  if (stopTime < 0 && OptionsCont::getOptions().getInt("remote-port") == 0) {
494 #else
495  if (stopTime < 0) {
496 #endif
499  && (myInserter->getPendingFlowCount() == 0)
502  if (myPersonControl) {
504  }
505  if (myContainerControl) {
507  }
510  }
511  }
512  if (stopTime >= 0 && myStep >= stopTime) {
514  }
515  return SIMSTATE_RUNNING;
516 }
517 
518 
519 std::string
521  switch (state) {
523  return "";
525  return "The final simulation step has been reached.";
527  return "All vehicles have left the simulation.";
529  return "TraCI requested termination.";
531  return "An error occured (see log).";
533  return "Too many vehicles.";
534  default:
535  return "Unknown reason.";
536  }
537 }
538 
539 
540 void
542  // clear container
543  MSEdge::clear();
544  MSLane::clear();
545  MSRoute::clear();
553 }
554 
555 
556 void
558  // update detector values
560  const OptionsCont& oc = OptionsCont::getOptions();
561 
562  // check state dumps
563  if (oc.isSet("netstate-dump")) {
565  oc.getInt("netstate-dump.precision"));
566  }
567 
568  // check fcd dumps
569  if (OptionsCont::getOptions().isSet("fcd-output")) {
571  }
572 
573  // check emission dumps
574  if (OptionsCont::getOptions().isSet("emission-output")) {
576  }
577 
578  // check full dumps
579  if (OptionsCont::getOptions().isSet("full-output")) {
581  }
582 
583  // check queue dumps
584  if (OptionsCont::getOptions().isSet("queue-output")) {
586  }
587 
588  // check amitran dumps
589  if (OptionsCont::getOptions().isSet("amitran-output")) {
591  }
592 
593  // check vtk dumps
594  if (OptionsCont::getOptions().isSet("vtk-output")) {
595 
596  if (MSNet::getInstance()->getVehicleControl().getRunningVehicleNo() > 0) {
597  std::string timestep = time2string(myStep);
598  timestep = timestep.substr(0, timestep.length() - 3);
599  std::string output = OptionsCont::getOptions().getString("vtk-output");
600  std::string filename = output + "_" + timestep + ".vtp";
601 
602  OutputDevice_File dev = OutputDevice_File(filename, false);
603 
604  //build a huge mass of xml files
606 
607  }
608 
609  }
610 
611  // summary output
612  if (OptionsCont::getOptions().isSet("summary-output")) {
613  OutputDevice& od = OutputDevice::getDeviceByOption("summary-output");
614  unsigned int departedVehiclesNumber = myVehicleControl->getDepartedVehicleNo();
615  const SUMOReal meanWaitingTime = departedVehiclesNumber != 0 ? myVehicleControl->getTotalDepartureDelay() / (SUMOReal) departedVehiclesNumber : -1.;
616  unsigned int endedVehicleNumber = myVehicleControl->getEndedVehicleNo();
617  const SUMOReal meanTravelTime = endedVehicleNumber != 0 ? myVehicleControl->getTotalTravelTime() / (SUMOReal) endedVehicleNumber : -1.;
619  .writeAttr("inserted", myVehicleControl->getDepartedVehicleNo()).writeAttr("running", myVehicleControl->getRunningVehicleNo())
620  .writeAttr("waiting", myInserter->getWaitingVehicleNo()).writeAttr("ended", myVehicleControl->getEndedVehicleNo())
621  .writeAttr("meanWaitingTime", meanWaitingTime).writeAttr("meanTravelTime", meanTravelTime);
622  if (myLogExecutionTime) {
623  od.writeAttr("duration", mySimStepDuration);
624  }
625  od.closeTag();
626  }
627 
628  // write detector values
630 
631  // write link states
632  if (OptionsCont::getOptions().isSet("link-output")) {
633  OutputDevice& od = OutputDevice::getDeviceByOption("link-output");
634  od.openTag("timestep");
636  const MSEdgeVector& edges = myEdges->getEdges();
637  for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
638  const std::vector<MSLane*>& lanes = (*i)->getLanes();
639  for (std::vector<MSLane*>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
640  const std::vector<MSLink*>& links = (*j)->getLinkCont();
641  for (std::vector<MSLink*>::const_iterator k = links.begin(); k != links.end(); ++k) {
642  (*k)->writeApproaching(od, (*j)->getID());
643  }
644  }
645  }
646  od.closeTag();
647  }
648 }
649 
650 
651 bool
653  return myLogExecutionTime;
654 }
655 
656 
659  if (myPersonControl == 0) {
661  }
662  return *myPersonControl;
663 }
664 
667  if (myContainerControl == 0) {
669  }
670  return *myContainerControl;
671 }
672 
673 
676  if (myEdgeWeights == 0) {
678  }
679  return *myEdgeWeights;
680 }
681 
682 
683 void
685  std::cout << "Step #" << time2string(myStep);
686 }
687 
688 
689 void
691  if (myLogExecutionTime) {
692  std::ostringstream oss;
693  oss.setf(std::ios::fixed , std::ios::floatfield); // use decimal format
694  oss.setf(std::ios::showpoint); // print decimal point
695  oss << std::setprecision(OUTPUT_ACCURACY);
696  if (mySimStepDuration != 0) {
697  oss << " (" << mySimStepDuration << "ms ~= "
698  << (1000. / (SUMOReal) mySimStepDuration) << "*RT, ~"
700  } else {
701  oss << " (0ms ?*RT. ?";
702  }
703  oss << "UPS, vehicles"
704  << " TOT " << myVehicleControl->getDepartedVehicleNo()
705  << " ACT " << myVehicleControl->getRunningVehicleNo()
706  << ") ";
707  std::string prev = "Step #" + time2string(myStep - DELTA_T);
708  std::cout << oss.str().substr(0, 78 - prev.length());
709  }
710  std::cout << '\r';
711 }
712 
713 
714 void
716  if (find(myVehicleStateListeners.begin(), myVehicleStateListeners.end(), listener) == myVehicleStateListeners.end()) {
717  myVehicleStateListeners.push_back(listener);
718  }
719 }
720 
721 
722 void
724  std::vector<VehicleStateListener*>::iterator i = find(myVehicleStateListeners.begin(), myVehicleStateListeners.end(), listener);
725  if (i != myVehicleStateListeners.end()) {
726  myVehicleStateListeners.erase(i);
727  }
728 }
729 
730 
731 void
733  for (std::vector<VehicleStateListener*>::iterator i = myVehicleStateListeners.begin(); i != myVehicleStateListeners.end(); ++i) {
734  (*i)->vehicleStateChanged(vehicle, to);
735  }
736 }
737 
738 
739 
740 // ------ Insertion and retrieval of bus stops ------
741 bool
743  return myBusStopDict.add(busStop->getID(), busStop);
744 }
745 
746 
747 MSBusStop*
748 MSNet::getBusStop(const std::string& id) const {
749  return myBusStopDict.get(id);
750 }
751 
752 
753 std::string
754 MSNet::getBusStopID(const MSLane* lane, const SUMOReal pos) const {
755  const std::map<std::string, MSBusStop*>& vals = myBusStopDict.getMyMap();
756  for (std::map<std::string, MSBusStop*>::const_iterator it = vals.begin(); it != vals.end(); ++it) {
757  MSBusStop* stop = it->second;
758  if (&stop->getLane() == lane && fabs(stop->getEndLanePosition() - pos) < POSITION_EPS) {
759  return stop->getID();
760  }
761  }
762  return "";
763 }
764 
765 // ------ Insertion and retrieval of container stops ------
766 bool
768  return myContainerStopDict.add(containerStop->getID(), containerStop);
769 }
770 
772 MSNet::getContainerStop(const std::string& id) const {
773  return myContainerStopDict.get(id);
774 }
775 
776 std::string
777 MSNet::getContainerStopID(const MSLane* lane, const SUMOReal pos) const {
778  const std::map<std::string, MSContainerStop*>& vals = myContainerStopDict.getMyMap();
779  for (std::map<std::string, MSContainerStop*>::const_iterator it = vals.begin(); it != vals.end(); ++it) {
780  MSContainerStop* stop = it->second;
781  if (&stop->getLane() == lane && fabs(stop->getEndLanePosition() - pos) < POSITION_EPS) {
782  return stop->getID();
783  }
784  }
785  return "";
786 }
787 
788 
790 MSNet::getRouterTT(const MSEdgeVector& prohibited) const {
791  if (!myRouterTTInitialized) {
792  myRouterTTInitialized = true;
793  const std::string routingAlgorithm = OptionsCont::getOptions().getString("routing-algorithm");
794  if (routingAlgorithm == "dijkstra") {
797  } else {
798  if (routingAlgorithm != "astar") {
799  WRITE_WARNING("TraCI and Triggers cannot use routing algorithm '" + routingAlgorithm + "'. using 'astar' instead.");
800  }
803  }
804  }
805  if (myRouterTTDijkstra != 0) {
806  myRouterTTDijkstra->prohibit(prohibited);
807  return *myRouterTTDijkstra;
808  } else {
809  assert(myRouterTTAStar != 0);
810  myRouterTTAStar->prohibit(prohibited);
811  return *myRouterTTAStar;
812  }
813 }
814 
815 
817 MSNet::getRouterEffort(const MSEdgeVector& prohibited) const {
818  if (myRouterEffort == 0) {
821  }
822  myRouterEffort->prohibit(prohibited);
823  return *myRouterEffort;
824 }
825 
826 
828 MSNet::getPedestrianRouter(const MSEdgeVector& prohibited) const {
829  if (myPedestrianRouter == 0) {
831  }
832  myPedestrianRouter->prohibit(prohibited);
833  return *myPedestrianRouter;
834 }
835 
836 
837 const NamedRTree&
839  if (!myLanesRTree.first) {
840  MSLane::fill(myLanesRTree.second);
841  myLanesRTree.first = true;
842  }
843  return myLanesRTree.second;
844 }
845 
846 
847 /****************************************************************************/
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
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.
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:690
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
Interface for objects listening to vehicle state changes.
Definition: MSNet.h:510
const MSLane & getLane() const
Returns the lane this container stop is located at.
A lane area vehicles can halt at and load and unload containers.
long mySimStepEnd
Definition: MSNet.h:644
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:723
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:623
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.
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:571
SUMOReal getEndLanePosition() const
Returns the end position of this container stop.
The simulation contains too many vehicles (.
Definition: MSNet.h:111
virtual bool add(const std::string &id, T item)
Adds an item.
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:892
MSVehicleControl * myVehicleControl
Controls vehicle building and deletion;.
Definition: MSNet.h:605
void updateDetectors(const SUMOTime step)
Computes detector values.
NamedObjectCont< MSContainerStop * > myContainerStopDict
Dictionary of container stops.
Definition: MSNet.h:679
std::vector< SUMOTime > myStateDumpTimes
Times at which a state shall be written.
Definition: MSNet.h:659
virtual void execute(SUMOTime time)
Executes time-dependant commands.
bool hasInternalLinks() const
return whether the network contains internal links
Definition: MSNet.h:585
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:777
int simulate(SUMOTime start, SUMOTime stop)
Simulates from timestep start to stop.
Definition: MSNet.cpp:280
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's Named objects.
Definition: NamedRTree.h:72
Computes the shortest path through a network using the Dijkstra algorithm.
Definition: AStarRouter.h:71
MSPedestrianRouterDijkstra & getPedestrianRouter(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:828
int getActiveVehicleCount() const
Returns the number of build vehicles that have not been removed or need to wait for a passenger or a ...
MSPersonControl * myPersonControl
Controls person building and deletion;.
Definition: MSNet.h:607
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:159
MSEdgeControl * myEdges
Controls edges, performs vehicle movement;.
Definition: MSNet.h:611
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:661
bool myLogExecutionTime
Information whether the simulation duration shall be logged.
Definition: MSNet.h:638
MSContainerStop * getContainerStop(const std::string &id) const
Returns the named container stop.
Definition: MSNet.cpp:772
Storage for geometrical objects.
static const std::string STAGE_LANECHANGE
Definition: MSNet.h:703
static void write(OutputDevice &of, SUMOTime timestep)
Dumping a hugh List of Parameters available in the Simulation.
SUMOReal getEndLanePosition() const
Returns the end position of this bus stop.
Definition: MSBusStop.cpp:72
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:235
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:754
void addVehicleStateListener(VehicleStateListener *listener)
Adds a vehicle states listener.
Definition: MSNet.cpp:715
SimulationState
Possible states of a simulation - running or stopped with different reasons.
Definition: MSNet.h:99
MSPedestrianRouterDijkstra * myPedestrianRouter
Definition: MSNet.h:693
#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:67
SUMOLong myVehiclesMoved
The overall number of vehicle movements.
Definition: MSNet.h:650
DijkstraRouterTT< MSEdge, SUMOVehicle, prohibited_withRestrictions< MSEdge, SUMOVehicle > > * myRouterTTDijkstra
Definition: MSNet.h:690
ShapeContainer * myShapeContainer
A container for geometrical shapes;.
Definition: MSNet.h:627
std::pair< bool, NamedRTree > myLanesRTree
An RTree structure holding lane IDs.
Definition: MSNet.h:697
static void cleanup()
const MSLane & getLane() const
Returns the lane this bus stop is located at.
Definition: MSBusStop.cpp:60
Container for junctions; performs operations on all stored junctions.
bool hasPersons() const
checks whether any person waits to finish her plan
DijkstraRouterEffort< MSEdge, SUMOVehicle, prohibited_withRestrictions< MSEdge, SUMOVehicle > > * myRouterEffort
Definition: MSNet.h:692
SUMOReal getTotalTravelTime() const
Returns the total travel time.
bool addBusStop(MSBusStop *busStop)
Adds a bus stop.
Definition: MSNet.cpp:742
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!)
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
void prohibit(const std::vector< E * > &toProhibit)
long mySimStepBegin
The last simulation step begin, end and duration.
Definition: MSNet.h:644
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's building process.
Definition: MSNet.cpp:215
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:557
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
MSInsertionControl * myInserter
Controls vehicle insertion;.
Definition: MSNet.h:617
Representation of a vehicle.
Definition: SUMOVehicle.h:65
void checkInsertions(SUMOTime time)
Checks "movement" of stored vehicles.
static void write(OutputDevice &of, SUMOTime timestep)
Writes the posion and the angle of each vehcile into the given device.
Definition: MSFCDExport.cpp:57
SUMORouteLoaderControl * myRouteLoaders
Route loader for dynamic loading of routes.
Definition: MSNet.h:594
void closeSimulation(SUMOTime start)
Closes the simulation (all files, connections, etc.)
Definition: MSNet.cpp:331
bool myLogStepNumber
Information whether the number of the simulation step shall be logged.
Definition: MSNet.h:641
A lane area vehicles can halt at.
Definition: MSBusStop.h:64
An output device that encapsulates an ofstream.
virtual MSContainerControl & getContainerControl()
Returns the container control.
Definition: MSNet.cpp:666
static void clear()
Clears the dictionary.
Definition: MSEdge.cpp:577
bool addContainerStop(MSContainerStop *containerStop)
Adds a container stop.
Definition: MSNet.cpp:767
SUMOTime getTargetTime()
Definition: TraCIServer.h:80
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:288
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:619
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:615
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:684
MSBusStop * getBusStop(const std::string &id) const
Returns the named bus stop.
Definition: MSNet.cpp:748
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:609
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:483
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:790
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:702
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:682
static MSNet * myInstance
Unique instance of MSNet.
Definition: MSNet.h:591
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:541
bool myRouterTTInitialized
Definition: MSNet.h:689
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.
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:485
MSJunctionControl * myJunctions
Controls junctions, realizes right-of-way rules;.
Definition: MSNet.h:613
virtual MSPersonControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:658
static void clear()
Clears the dictionary.
Definition: MSLane.cpp:875
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
static void cleanup()
remove state at simulation end
Definition: MSPModel.cpp:83
static TraCIServer * getInstance()
Definition: TraCIServer.h:83
MSEventControl * myBeginOfTimestepEvents
Controls events executed at the begin of a time step;.
Definition: MSNet.h:621
A storage for options typed value containers)
Definition: OptionsCont.h:108
MSEdgeWeightsStorage * myEdgeWeights
The net's knowledge about edge efforts/travel times;.
Definition: MSNet.h:629
MSNet(MSVehicleControl *vc, MSEventControl *beginOfTimestepEvents, MSEventControl *endOfTimestepEvents, MSEventControl *insertionEvents, ShapeContainer *shapeCont=0)
Constructor.
Definition: MSNet.cpp:167
static void write(OutputDevice &of, const SUMOTime timestep)
Writes the complete network state into the given device.
unsigned int emitVehicles(SUMOTime time)
Emits vehicles that want to depart at the given time.
int SUMOTime
Definition: SUMOTime.h:43
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's state change.
Definition: MSNet.cpp:732
const NamedRTree & getLanesRTree() const
Returns an RTree that contains lane IDs.
Definition: MSNet.cpp:838
static void cleanup()
cleanup remaining data structures
long mySimBeginMillis
The overall simulation duration.
Definition: MSNet.h:647
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:240
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:218
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:520
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:652
AStarRouter< MSEdge, SUMOVehicle, prohibited_withRestrictions< MSEdge, SUMOVehicle > > * myRouterTTAStar
Definition: MSNet.h:691
#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:597
The class responsible for building and deletion of vehicles.
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:78
NamedObjectCont< MSBusStop * > myBusStopDict
Dictionary of bus stops.
Definition: MSNet.h:676
void simulationStep()
Performs a single simulation step.
Definition: MSNet.cpp:387
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:325
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:817
static const std::string STAGE_INSERTIONS
Definition: MSNet.h:704
MSEventControl * myInsertionEvents
Controls insertion events;.
Definition: MSNet.h:625
int myTooManyVehicles
Storage for maximum vehicle number.
Definition: MSNet.h:673
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
const MSEdgeWeightsStorage & getWeightsStorage() const
Returns the vehicle's internal edge travel times/efforts container.
Definition: MSVehicle.cpp:526
long mySimStepDuration
Definition: MSNet.h:644
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:670
unsigned int getEmergencyStops() const
return the number of emergency stops
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
void checkWaitingContainers(MSNet *net, const SUMOTime time)
checks whether any containers waiting time is over
static void cleanup()
remove state at simulation end
void determineCandidates(SUMOTime time)
Checks for all vehicles whether they can be emitted.
static void saveState(const std::string &file, SUMOTime step)
Saves the current state.
const MSEdgeVector & getEdges() const
Returns loaded edges.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
MSEdgeWeightsStorage & getWeightsStorage()
Returns the net's internal edge travel times/efforts container.
Definition: MSNet.cpp:675
static const std::string STAGE_EVENTS
string constants for simstep stages
Definition: MSNet.h:701