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-sim.org/
18 // Copyright (C) 2001-2014 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 #ifdef HAVE_VERSION_H
40 #include <version.h>
41 #endif
42 
43 #include <string>
44 #include <iostream>
45 #include <sstream>
46 #include <typeinfo>
47 #include <algorithm>
48 #include <cassert>
49 #include <vector>
50 #include <ctime>
52 #include "MSNet.h"
53 #include "MSPersonControl.h"
54 #include "MSEdgeControl.h"
55 #include "MSJunctionControl.h"
56 #include "MSInsertionControl.h"
57 #include "MSEventControl.h"
58 #include "MSEdge.h"
59 #include "MSJunction.h"
60 #include "MSJunctionLogic.h"
61 #include "MSLane.h"
62 #include "MSVehicleTransfer.h"
63 #include "MSRoute.h"
65 #include "trigger/MSTrigger.h"
66 #include "trigger/MSCalibrator.h"
68 #include "MSVehicleControl.h"
70 #include <utils/common/ToString.h>
76 #include <utils/shapes/Polygon.h>
78 
80 #include "output/MSFCDExport.h"
82 #include "output/MSFullExport.h"
83 #include "output/MSQueueExport.h"
84 #include "output/MSVTKExport.h"
85 #include "output/MSXMLRawOut.h"
88 #include <utils/common/SysUtils.h>
92 #include "MSGlobals.h"
93 #include "MSPModel.h"
95 #include "MSPerson.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  myRouterTTInitialized(false),
172  myRouterTTDijkstra(0),
173  myRouterTTAStar(0),
174  myRouterEffort(0),
175  myPedestrianRouter(0) {
176  if (myInstance != 0) {
177  throw ProcessError("A network was already constructed.");
178  }
180  myStep = string2time(oc.getString("begin"));
181  myLogExecutionTime = !oc.getBool("no-duration-log");
182  myLogStepNumber = !oc.getBool("no-step-log");
183  myTooManyVehicles = oc.getInt("max-num-vehicles");
184  myInserter = new MSInsertionControl(*vc, string2time(oc.getString("max-depart-delay")), !oc.getBool("eager-insert"));
185  myVehicleControl = vc;
187  myEdges = 0;
188  myJunctions = 0;
189  myRouteLoaders = 0;
190  myLogics = 0;
191  myPersonControl = 0;
192  myEdgeWeights = 0;
193  myShapeContainer = shapeCont == 0 ? new ShapeContainer() : shapeCont;
194 
195  myBeginOfTimestepEvents = beginOfTimestepEvents;
196  myEndOfTimestepEvents = endOfTimestepEvents;
197  myInsertionEvents = insertionEvents;
198  myLanesRTree.first = false;
199 
200 #ifdef HAVE_INTERNAL
202  MSGlobals::gMesoNet = new MELoop(string2time(oc.getString("meso-recheck")));
203  }
204 #endif
205  myInstance = this;
206 }
207 
208 
209 
210 
211 void
213  SUMORouteLoaderControl* routeLoaders,
214  MSTLLogicControl* tlc,
215  std::vector<SUMOTime> stateDumpTimes,
216  std::vector<std::string> stateDumpFiles) {
217  myEdges = edges;
218  myJunctions = junctions;
219  myRouteLoaders = routeLoaders;
220  myLogics = tlc;
221  // save the time the network state shall be saved at
222  myStateDumpTimes = stateDumpTimes;
223  myStateDumpFiles = stateDumpFiles;
224 
225  // set requests/responses
227 
228  // initialise performance computation
229  if (myLogExecutionTime) {
231  }
232 }
233 
234 
236  // delete events first maybe they do some cleanup
238  delete myEndOfTimestepEvents;
239  delete myInsertionEvents;
240  // delete controls
241  delete myJunctions;
242  delete myDetectorControl;
243  // delete mean data
244  delete myEdges;
245  delete myInserter;
246  delete myLogics;
247  delete myRouteLoaders;
248  delete myVehicleControl;
249  if (myPersonControl != 0) {
250  delete myPersonControl;
251  }
252  delete myShapeContainer;
253  delete myEdgeWeights;
254  delete myRouterTTDijkstra;
255  delete myRouterTTAStar;
256  delete myRouterEffort;
257  myLanesRTree.second.RemoveAll();
258  clearAll();
259 #ifdef HAVE_INTERNAL
261  delete MSGlobals::gMesoNet;
262  }
263 #endif
264  myInstance = 0;
265 }
266 
267 
268 int
270  // report the begin when wished
271  WRITE_MESSAGE("Simulation started with time: " + time2string(start));
272  // the simulation loop
274  myStep = start;
275  // preload the routes especially for TraCI
276  loadRoutes();
277 #ifndef NO_TRACI
278 #ifdef HAVE_PYTHON
279  if (OptionsCont::getOptions().isSet("python-script")) {
280  TraCIServer::runEmbedded(OptionsCont::getOptions().getString("python-script"));
281  closeSimulation(start);
282  WRITE_MESSAGE("Simulation ended at time: " + time2string(getCurrentTimeStep()));
283  WRITE_MESSAGE("Reason: Script ended");
284  return 0;
285  }
286 #endif
287 #endif
288  while (state == SIMSTATE_RUNNING) {
289  if (myLogStepNumber) {
291  }
292  simulationStep();
293  if (myLogStepNumber) {
295  }
296  state = simulationState(stop);
297 #ifndef NO_TRACI
298  if (state != SIMSTATE_RUNNING) {
299  if (OptionsCont::getOptions().getInt("remote-port") != 0 && !TraCIServer::wasClosed()) {
300  state = SIMSTATE_RUNNING;
301  }
302  }
303 #endif
304  }
305  // report the end when wished
306  WRITE_MESSAGE("Simulation ended at time: " + time2string(getCurrentTimeStep()));
307  WRITE_MESSAGE("Reason: " + getStateMessage(state));
308  // exit simulation loop
309  closeSimulation(start);
310  return 0;
311 }
312 
313 void
316 }
317 
318 
319 void
321  if (myLogExecutionTime) {
322  long duration = SysUtils::getCurrentMillis() - mySimBeginMillis;
323  std::ostringstream msg;
324  // print performance notice
325  msg << "Performance: " << "\n" << " Duration: " << duration << " ms" << "\n";
326  if (duration != 0) {
327  msg << " Real time factor: " << (STEPS2TIME(myStep - start) * 1000. / (SUMOReal)duration) << "\n";
328  msg.setf(std::ios::fixed , std::ios::floatfield); // use decimal format
329  msg.setf(std::ios::showpoint); // print decimal point
330  msg << " UPS: " << ((SUMOReal)myVehiclesMoved / ((SUMOReal)duration / 1000)) << "\n";
331  }
332  // print vehicle statistics
333  const std::string discardNotice = ((myVehicleControl->getLoadedVehicleNo() != myVehicleControl->getDepartedVehicleNo()) ?
334  " (Loaded: " + toString(myVehicleControl->getLoadedVehicleNo()) + ")" : "");
335  msg << "Vehicles: " << "\n"
336  << " Inserted: " << myVehicleControl->getDepartedVehicleNo() << discardNotice << "\n"
337  << " Running: " << myVehicleControl->getRunningVehicleNo() << "\n"
338  << " Waiting: " << myInserter->getWaitingVehicleNo() << "\n";
339 
340  if (myVehicleControl->getTeleportCount() > 0) {
341  // print optional teleport statistics
342  std::vector<std::string> reasons;
343  if (myVehicleControl->getCollisionCount() > 0) {
344  reasons.push_back("Collisions: " + toString(myVehicleControl->getCollisionCount()));
345  }
346  if (myVehicleControl->getTeleportsJam() > 0) {
347  reasons.push_back("Jam: " + toString(myVehicleControl->getTeleportsJam()));
348  }
349  if (myVehicleControl->getTeleportsYield() > 0) {
350  reasons.push_back("Yield: " + toString(myVehicleControl->getTeleportsYield()));
351  }
353  reasons.push_back("Wrong Lane: " + toString(myVehicleControl->getTeleportsWrongLane()));
354  }
355  msg << "Teleports: " << myVehicleControl->getTeleportCount() << " (" << joinToString(reasons, ", ") << ")\n";
356  }
357  if (myVehicleControl->getEmergencyStops() > 0) {
358  msg << "Emergency Stops: " << myVehicleControl->getEmergencyStops() << "\n";
359  }
360  WRITE_MESSAGE(msg.str());
361  }
363  if (OptionsCont::getOptions().getBool("vehroute-output.write-unfinished")) {
365  }
366 #ifndef NO_TRACI
368 #endif
369 }
370 
371 
372 void
374 #ifndef NO_TRACI
377  if (t != 0 && t->getTargetTime() != 0 && t->getTargetTime() < myStep) {
378  return;
379  }
380 #endif
381  // execute beginOfTimestepEvents
382  if (myLogExecutionTime) {
384  }
385  // simulation state output
386  std::vector<SUMOTime>::iterator timeIt = find(myStateDumpTimes.begin(), myStateDumpTimes.end(), myStep);
387  if (timeIt != myStateDumpTimes.end()) {
388  const int dist = (int)distance(myStateDumpTimes.begin(), timeIt);
390  }
394  }
395  // check whether the tls programs need to be switched
397 
398 #ifdef HAVE_INTERNAL
400  MSGlobals::gMesoNet->simulate(myStep);
401  } else {
402 #endif
403 
404  // assure all lanes with vehicles are 'active'
406 
407  // compute safe velocities for all vehicles for the next few lanes
408  // also register ApproachingVehicleInformation for all links
410 
411  // decide right-of-way and execute movements
415  }
416 
417  // Vehicles change Lanes (maybe)
419 
422  }
423 #ifdef HAVE_INTERNAL
424  }
425 #endif
426  loadRoutes();
427 
428  // persons
429  if (myPersonControl != 0) {
431  }
432  // insert Vehicles
437  }
439 
440  // execute endOfTimestepEvents
442 
443 #ifndef NO_TRACI
444  if (TraCIServer::getInstance() != 0) {
446  }
447 #endif
448  // update and write (if needed) detector values
449  writeOutput();
450 
451  if (myLogExecutionTime) {
455  }
456  myStep += DELTA_T;
457 }
458 
459 
464  }
465 #ifndef NO_TRACI
466  if (TraCIServer::wasClosed()) {
468  }
469  if (stopTime < 0 && OptionsCont::getOptions().getInt("remote-port") == 0) {
470 #else
471  if (stopTime < 0) {
472 #endif
475  && (myInserter->getPendingFlowCount() == 0)
476  && (myPersonControl == 0 || !myPersonControl->hasNonWaiting())) {
477  if (myPersonControl) {
479  }
482  }
483  }
484  if (stopTime >= 0 && myStep >= stopTime) {
486  }
487  return SIMSTATE_RUNNING;
488 }
489 
490 
491 std::string
493  switch (state) {
495  return "";
497  return "The final simulation step has been reached.";
499  return "All vehicles have left the simulation.";
501  return "TraCI requested termination.";
503  return "An error occured (see log).";
505  return "Too many vehicles.";
506  default:
507  return "Unknown reason.";
508  }
509 }
510 
511 
512 void
514  // clear container
515  MSEdge::clear();
516  MSLane::clear();
517  MSRoute::clear();
524 }
525 
526 
527 void
529  // update detector values
531 
532  // check state dumps
533  if (OptionsCont::getOptions().isSet("netstate-dump")) {
535  }
536 
537  // check fcd dumps
538  if (OptionsCont::getOptions().isSet("fcd-output")) {
540  }
541 
542  // check emission dumps
543  if (OptionsCont::getOptions().isSet("emission-output")) {
545  }
546 
547  // check full dumps
548  if (OptionsCont::getOptions().isSet("full-output")) {
550  }
551 
552  // check queue dumps
553  if (OptionsCont::getOptions().isSet("queue-output")) {
555  }
556 
557  // check amitran dumps
558  if (OptionsCont::getOptions().isSet("amitran-output")) {
560  }
561 
562  // check vtk dumps
563  if (OptionsCont::getOptions().isSet("vtk-output")) {
564 
565  if (MSNet::getInstance()->getVehicleControl().getRunningVehicleNo() > 0) {
566  std::string timestep = time2string(myStep);
567  timestep = timestep.substr(0, timestep.length() - 3);
568  std::string output = OptionsCont::getOptions().getString("vtk-output");
569  std::string filename = output + "_" + timestep + ".vtp";
570 
571  OutputDevice_File dev = OutputDevice_File(filename, false);
572 
573  //build a huge mass of xml files
575 
576  }
577 
578  }
579 
580  // summary output
581  if (OptionsCont::getOptions().isSet("summary-output")) {
582  OutputDevice& od = OutputDevice::getDeviceByOption("summary-output");
583  unsigned int departedVehiclesNumber = myVehicleControl->getDepartedVehicleNo();
584  const SUMOReal meanWaitingTime = departedVehiclesNumber != 0 ? myVehicleControl->getTotalDepartureDelay() / (SUMOReal) departedVehiclesNumber : -1.;
585  unsigned int endedVehicleNumber = myVehicleControl->getEndedVehicleNo();
586  const SUMOReal meanTravelTime = endedVehicleNumber != 0 ? myVehicleControl->getTotalTravelTime() / (SUMOReal) endedVehicleNumber : -1.;
588  .writeAttr("inserted", myVehicleControl->getDepartedVehicleNo()).writeAttr("running", myVehicleControl->getRunningVehicleNo())
589  .writeAttr("waiting", myInserter->getWaitingVehicleNo()).writeAttr("ended", myVehicleControl->getEndedVehicleNo())
590  .writeAttr("meanWaitingTime", meanWaitingTime).writeAttr("meanTravelTime", meanTravelTime);
591  if (myLogExecutionTime) {
592  od.writeAttr("duration", mySimStepDuration);
593  }
594  od.closeTag();
595  }
596 
597  // write detector values
599 
600  // write link states
601  if (OptionsCont::getOptions().isSet("link-output")) {
602  OutputDevice& od = OutputDevice::getDeviceByOption("link-output");
603  od.openTag("timestep");
605  const std::vector<MSEdge*>& edges = myEdges->getEdges();
606  for (std::vector<MSEdge*>::const_iterator i = edges.begin(); i != edges.end(); ++i) {
607  const std::vector<MSLane*>& lanes = (*i)->getLanes();
608  for (std::vector<MSLane*>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
609  const std::vector<MSLink*>& links = (*j)->getLinkCont();
610  for (std::vector<MSLink*>::const_iterator k = links.begin(); k != links.end(); ++k) {
611  (*k)->writeApproaching(od, (*j)->getID());
612  }
613  }
614  }
615  od.closeTag();
616  }
617 }
618 
619 
620 bool
622  return myLogExecutionTime;
623 }
624 
625 
628  if (myPersonControl == 0) {
630  }
631  return *myPersonControl;
632 }
633 
634 
637  if (myEdgeWeights == 0) {
639  }
640  return *myEdgeWeights;
641 }
642 
643 
644 void
646  std::cout << "Step #" << time2string(myStep);
647 }
648 
649 
650 void
652  if (myLogExecutionTime) {
653  std::ostringstream oss;
654  oss.setf(std::ios::fixed , std::ios::floatfield); // use decimal format
655  oss.setf(std::ios::showpoint); // print decimal point
656  oss << std::setprecision(OUTPUT_ACCURACY);
657  if (mySimStepDuration != 0) {
658  oss << " (" << mySimStepDuration << "ms ~= "
659  << (1000. / (SUMOReal) mySimStepDuration) << "*RT, ~"
661  } else {
662  oss << " (0ms ?*RT. ?";
663  }
664  oss << "UPS, vehicles"
665  << " TOT " << myVehicleControl->getDepartedVehicleNo()
666  << " ACT " << myVehicleControl->getRunningVehicleNo()
667  << ") ";
668  std::string prev = "Step #" + time2string(myStep - DELTA_T);
669  std::cout << oss.str().substr(0, 78 - prev.length());
670  }
671  std::cout << '\r';
672 }
673 
674 
675 void
677  if (find(myVehicleStateListeners.begin(), myVehicleStateListeners.end(), listener) == myVehicleStateListeners.end()) {
678  myVehicleStateListeners.push_back(listener);
679  }
680 }
681 
682 
683 void
685  std::vector<VehicleStateListener*>::iterator i = find(myVehicleStateListeners.begin(), myVehicleStateListeners.end(), listener);
686  if (i != myVehicleStateListeners.end()) {
687  myVehicleStateListeners.erase(i);
688  }
689 }
690 
691 
692 void
694  for (std::vector<VehicleStateListener*>::iterator i = myVehicleStateListeners.begin(); i != myVehicleStateListeners.end(); ++i) {
695  (*i)->vehicleStateChanged(vehicle, to);
696  }
697 }
698 
699 
700 
701 // ------ Insertion and retrieval of bus stops ------
702 bool
704  return myBusStopDict.add(busStop->getID(), busStop);
705 }
706 
707 
708 MSBusStop*
709 MSNet::getBusStop(const std::string& id) const {
710  return myBusStopDict.get(id);
711 }
712 
713 
714 std::string
715 MSNet::getBusStopID(const MSLane* lane, const SUMOReal pos) const {
716  const std::map<std::string, MSBusStop*>& vals = myBusStopDict.getMyMap();
717  for (std::map<std::string, MSBusStop*>::const_iterator it = vals.begin(); it != vals.end(); ++it) {
718  MSBusStop* stop = it->second;
719  if (&stop->getLane() == lane && fabs(stop->getEndLanePosition() - pos) < POSITION_EPS) {
720  return stop->getID();
721  }
722  }
723  return "";
724 }
725 
726 
728 MSNet::getRouterTT(const std::vector<MSEdge*>& prohibited) const {
729  if (!myRouterTTInitialized) {
730  myRouterTTInitialized = true;
731  const std::string routingAlgorithm = OptionsCont::getOptions().getString("routing-algorithm");
732  if (routingAlgorithm == "dijkstra") {
735  } else {
736  if (routingAlgorithm != "astar") {
737  WRITE_WARNING("TraCI and Triggers cannot use routing algorithm '" + routingAlgorithm + "'. using 'astar' instead.");
738  }
741  }
742  }
743  if (myRouterTTDijkstra != 0) {
744  myRouterTTDijkstra->prohibit(prohibited);
745  return *myRouterTTDijkstra;
746  } else {
747  assert(myRouterTTAStar != 0);
748  myRouterTTAStar->prohibit(prohibited);
749  return *myRouterTTAStar;
750  }
751 }
752 
753 
755 MSNet::getRouterEffort(const std::vector<MSEdge*>& prohibited) const {
756  if (myRouterEffort == 0) {
759  }
760  myRouterEffort->prohibit(prohibited);
761  return *myRouterEffort;
762 }
763 
764 
766 MSNet::getPedestrianRouter(const std::vector<MSEdge*>& prohibited) const {
767  if (myPedestrianRouter == 0) {
769  }
770  myPedestrianRouter->prohibit(prohibited);
771  return *myPedestrianRouter;
772 }
773 
774 
775 const NamedRTree&
777  if (!myLanesRTree.first) {
778  MSLane::fill(myLanesRTree.second);
779  myLanesRTree.first = true;
780  }
781  return myLanesRTree.second;
782 }
783 
784 
785 /****************************************************************************/
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
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:651
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
Interface for objects listening to vehicle state changes.
Definition: MSNet.h:450
long mySimStepEnd
Definition: MSNet.h:578
void loadNext(SUMOTime step)
loads the next routes
void removeVehicleStateListener(VehicleStateListener *listener)
Removes a vehicle states listener.
Definition: MSNet.cpp:684
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:557
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:513
The simulation contains too many vehicles (.
Definition: MSNet.h:108
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:868
MSVehicleControl * myVehicleControl
Controls vehicle building and deletion;.
Definition: MSNet.h:541
void updateDetectors(const SUMOTime step)
Computes detector values.
std::vector< SUMOTime > myStateDumpTimes
Times at which a state shall be written.
Definition: MSNet.h:593
virtual void execute(SUMOTime time)
Executes time-dependant commands.
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:112
int simulate(SUMOTime start, SUMOTime stop)
Simulates from timestep start to stop.
Definition: MSNet.cpp:269
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
int getActiveVehicleCount() const
Returns the number of build vehicles that have not been removed or need to wait for a passenger...
MSPersonControl * myPersonControl
Controls person building and deletion;.
Definition: MSNet.h:543
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:545
The final simulation step has been performed.
Definition: MSNet.h:100
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:595
bool myLogExecutionTime
Information whether the simulation duration shall be logged.
Definition: MSNet.h:572
Storage for geometrical objects.
static const std::string STAGE_LANECHANGE
Definition: MSNet.h:628
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:216
void detectCollisions(SUMOTime timestep, const std::string &stage)
Detect collisions.
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterEffort(const std::vector< MSEdge * > &prohibited=std::vector< MSEdge * >()) const
Definition: MSNet.cpp:755
std::string getBusStopID(const MSLane *lane, const SUMOReal pos) const
Returns the bus stop close to the given position.
Definition: MSNet.cpp:715
void addVehicleStateListener(VehicleStateListener *listener)
Adds a vehicle states listener.
Definition: MSNet.cpp:676
SimulationState
Possible states of a simulation - running or stopped with different reasons.
Definition: MSNet.h:96
MSPedestrianRouterDijkstra * myPedestrianRouter
Definition: MSNet.h:618
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
The simulated network and simulation perfomer.
Definition: MSNet.h:91
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:67
SUMOLong myVehiclesMoved
The overall number of vehicle movements.
Definition: MSNet.h:584
ShapeContainer * myShapeContainer
A container for geometrical shapes;.
Definition: MSNet.h:561
std::pair< bool, NamedRTree > myLanesRTree
An RTree structure holding lane IDs.
Definition: MSNet.h:622
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.
SUMOReal getTotalTravelTime() const
Returns the total travel time.
bool addBusStop(MSBusStop *busStop)
Adds a bus stop.
Definition: MSNet.cpp:703
static bool gCheck4Accidents
Definition: MSGlobals.h:77
#define OUTPUT_ACCURACY
Definition: config.h:162
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:74
void prohibit(const std::vector< E * > &toProhibit)
long mySimStepBegin
The last simulation step begin, end and duration.
Definition: MSNet.h:578
static void close()
request termination of connection
The simulation does not contain further vehicles.
Definition: MSNet.h:102
unsigned int getLoadedVehicleNo() const
Returns the number of build vehicles.
An error occured during the simulation step.
Definition: MSNet.h:106
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:528
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:551
Representation of a vehicle.
Definition: SUMOVehicle.h:64
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:60
SUMORouteLoaderControl * myRouteLoaders
Route loader for dynamic loading of routes.
Definition: MSNet.h:530
void closeSimulation(SUMOTime start)
Closes the simulation (all files, connections, etc.)
Definition: MSNet.cpp:320
bool myLogStepNumber
Information whether the number of the simulation step shall be logged.
Definition: MSNet.h:575
A lane area vehicles can halt at.
Definition: MSBusStop.h:64
An output device that encapsulates an ofstream.
static void clear()
Clears the dictionary.
Definition: MSEdge.cpp:519
SUMOTime getTargetTime()
Definition: TraCIServer.h:80
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:269
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:553
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:73
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
MSTLLogicControl * myLogics
Controls tls logics, realizes waiting on tls rules;.
Definition: MSNet.h:549
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:104
DijkstraRouterTT_ByProxi< MSEdge, SUMOVehicle, prohibited_withRestrictions< MSEdge, SUMOVehicle > > * myRouterTTDijkstra
Definition: MSNet.h:615
The simulation is running.
Definition: MSNet.h:98
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:186
void preSimStepOutput() const
Prints the current step number.
Definition: MSNet.cpp:645
MSBusStop * getBusStop(const std::string &id) const
Returns the named bus stop.
Definition: MSNet.cpp:709
static void cleanup()
properly deletes all trigger instances
Definition: MSTrigger.cpp:47
AStarRouterTT_ByProxi< MSEdge, SUMOVehicle, prohibited_withRestrictions< MSEdge, SUMOVehicle > > * myRouterTTAStar
Definition: MSNet.h:616
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
Inserts vehicles into the network when their departure time is reached.
void postloadInitContainer()
Closes building of junctions.
void abortWaiting()
removes any vehicles that are still waiting
VehicleState
Definition of a vehicle state.
Definition: MSNet.h:423
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:627
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:607
static MSNet * myInstance
Unique instance of MSNet.
Definition: MSNet.h:527
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:513
bool myRouterTTInitialized
Definition: MSNet.h:614
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:461
MSJunctionControl * myJunctions
Controls junctions, realizes right-of-way rules;.
Definition: MSNet.h:547
virtual MSPersonControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:627
static void clear()
Clears the dictionary.
Definition: MSLane.cpp:851
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:555
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:563
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.
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const std::vector< MSEdge * > &prohibited=std::vector< MSEdge * >()) const
Definition: MSNet.cpp:728
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:693
const NamedRTree & getLanesRTree() const
Returns an RTree that contains lane IDs.
Definition: MSNet.cpp:776
static void cleanup()
cleanup remaining data structures
long mySimBeginMillis
The overall simulation duration.
Definition: MSNet.h:581
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:153
virtual ~MSNet()
Destructor.
Definition: MSNet.cpp:235
const std::vector< MSEdge * > & getEdges() const
Returns loaded edges.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
static void cleanup()
deletes the router instance
bool closeTag()
Closes the most recently opened tag.
#define SUMOReal
Definition: config.h:215
static const bool gUseMesoSim
Definition: MSGlobals.h:99
static std::string getStateMessage(SimulationState state)
Returns the message to show if a certain state occurs.
Definition: MSNet.cpp:492
SUMOReal getMinimumTravelTime(const SUMOVehicle *const veh) const
returns the minimum travel time for the given vehicle
Definition: MSEdge.h:358
bool logSimulationDuration() const
Returns whether duration shall be logged.
Definition: MSNet.cpp:621
#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:533
The class responsible for building and deletion of vehicles.
void closeBuilding(MSEdgeControl *edges, MSJunctionControl *junctions, SUMORouteLoaderControl *routeLoaders, MSTLLogicControl *tlc, std::vector< SUMOTime > stateDumpTimes, std::vector< std::string > stateDumpFiles)
Closes the network's building process.
Definition: MSNet.cpp:212
NamedObjectCont< MSBusStop * > myBusStopDict
Dictionary of bus stops.
Definition: MSNet.h:604
void simulationStep()
Performs a single simulation step.
Definition: MSNet.cpp:373
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:314
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:201
MSPedestrianRouterDijkstra & getPedestrianRouter(const std::vector< MSEdge * > &prohibited=std::vector< MSEdge * >()) const
Definition: MSNet.cpp:766
static const std::string STAGE_INSERTIONS
Definition: MSNet.h:629
MSEventControl * myInsertionEvents
Controls insertion events;.
Definition: MSNet.h:559
int myTooManyVehicles
Storage for maximum vehicle number.
Definition: MSNet.h:601
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:539
long mySimStepDuration
Definition: MSNet.h:578
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.
unsigned int getEmergencyStops() const
return the number of emergency stops
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
static void write(OutputDevice &of, const MSEdgeControl &ec, SUMOTime timestep)
Writes the complete network state of the given edges into the given device.
Definition: MSXMLRawOut.cpp:59
static void saveState(const std::string &file, SUMOTime step)
Saves the current state.
MSEdgeWeightsStorage & getWeightsStorage()
Returns the net's internal edge travel times/efforts container.
Definition: MSNet.cpp:636
DijkstraRouterEffort_ByProxi< MSEdge, SUMOVehicle, prohibited_withRestrictions< MSEdge, SUMOVehicle > > * myRouterEffort
Definition: MSNet.h:617
static const std::string STAGE_EVENTS
string constants for simstep stages
Definition: MSNet.h:626