SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSNet.cpp
Go to the documentation of this file.
1 /****************************************************************************/
15 // The simulated network and simulation perfomer
16 /****************************************************************************/
17 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
18 // Copyright (C) 2001-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 #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 "MSEdgeControl.h"
51 #include "MSJunctionControl.h"
52 #include "MSInsertionControl.h"
53 #include "MSEventControl.h"
54 #include "MSEdge.h"
55 #include "MSJunction.h"
56 #include "MSJunctionLogic.h"
57 #include "MSLane.h"
58 #include "MSVehicleTransfer.h"
59 #include "MSRoute.h"
61 #include "trigger/MSTrigger.h"
62 #include "trigger/MSCalibrator.h"
64 #include "MSVehicleControl.h"
66 #include <utils/common/ToString.h>
73 #include <utils/shapes/Polygon.h>
75 
77 #include "output/MSFCDExport.h"
79 #include "output/MSFullExport.h"
80 #include "output/MSQueueExport.h"
81 #include "output/MSVTKExport.h"
82 #include "output/MSXMLRawOut.h"
85 #include <utils/common/SysUtils.h>
89 #include "MSGlobals.h"
90 #include "MSPModel.h"
92 #include "MSPerson.h"
93 #include "MSEdgeWeightsStorage.h"
94 #include "MSStateHandler.h"
95 
96 #ifdef HAVE_INTERNAL
97 #include <mesosim/MELoop.h>
99 #endif
100 
101 #ifndef NO_TRACI
103 #endif
104 
105 #ifdef CHECK_MEMORY_LEAKS
106 #include <foreign/nvwa/debug_new.h>
107 #endif // CHECK_MEMORY_LEAKS
108 
109 
110 // ===========================================================================
111 // static member definitions
112 // ===========================================================================
114 
115 const std::string MSNet::STAGE_EVENTS("events");
116 const std::string MSNet::STAGE_MOVEMENTS("move");
117 const std::string MSNet::STAGE_LANECHANGE("laneChange");
118 const std::string MSNet::STAGE_INSERTIONS("insertion");
119 
120 // ===========================================================================
121 // member method definitions
122 // ===========================================================================
123 SUMOReal
124 MSNet::getEffort(const MSEdge* const e, const SUMOVehicle* const v, SUMOReal t) {
125  SUMOReal value;
126  const MSVehicle* const veh = dynamic_cast<const MSVehicle* const>(v);
127  if (veh != 0 && veh->getWeightsStorage().retrieveExistingEffort(e, t, value)) {
128  return value;
129  }
130  if (getInstance()->getWeightsStorage().retrieveExistingEffort(e, t, value)) {
131  return value;
132  }
133  return 0;
134 }
135 
136 
137 SUMOReal
138 MSNet::getTravelTime(const MSEdge* const e, const SUMOVehicle* const v, SUMOReal t) {
139  SUMOReal value;
140  const MSVehicle* const veh = dynamic_cast<const MSVehicle* const>(v);
141  if (veh != 0 && veh->getWeightsStorage().retrieveExistingTravelTime(e, t, value)) {
142  return value;
143  }
145  return value;
146  }
147  return e->getMinimumTravelTime(v);
148 }
149 
150 
151 
152 // ---------------------------------------------------------------------------
153 // MSNet - methods
154 // ---------------------------------------------------------------------------
155 MSNet*
157  if (myInstance != 0) {
158  return myInstance;
159  }
160  throw ProcessError("A network was not yet constructed.");
161 }
162 
163 
164 MSNet::MSNet(MSVehicleControl* vc, MSEventControl* beginOfTimestepEvents,
165  MSEventControl* endOfTimestepEvents, MSEventControl* insertionEvents,
166  ShapeContainer* shapeCont):
167  myVehiclesMoved(0),
168  myHaveRestrictions(false),
169  myRouterTTInitialized(false),
170  myRouterTTDijkstra(0),
171  myRouterTTAStar(0),
172  myRouterEffort(0),
173  myPedestrianRouter(0) {
174  if (myInstance != 0) {
175  throw ProcessError("A network was already constructed.");
176  }
178  myStep = string2time(oc.getString("begin"));
179  myLogExecutionTime = !oc.getBool("no-duration-log");
180  myLogStepNumber = !oc.getBool("no-step-log");
181  myTooManyVehicles = oc.getInt("max-num-vehicles");
182  myInserter = new MSInsertionControl(*vc, string2time(oc.getString("max-depart-delay")), !oc.getBool("eager-insert"));
183  myVehicleControl = vc;
185  myEdges = 0;
186  myJunctions = 0;
187  myRouteLoaders = 0;
188  myLogics = 0;
189  myPersonControl = 0;
190  myEdgeWeights = 0;
191  myShapeContainer = shapeCont == 0 ? new ShapeContainer() : shapeCont;
192 
193  myBeginOfTimestepEvents = beginOfTimestepEvents;
194  myEndOfTimestepEvents = endOfTimestepEvents;
195  myInsertionEvents = insertionEvents;
196  myLanesRTree.first = false;
197 
198 #ifdef HAVE_INTERNAL
200  MSGlobals::gMesoNet = new MELoop(string2time(oc.getString("meso-recheck")));
201  }
202 #endif
203  myInstance = this;
204 }
205 
206 
207 
208 
209 void
211  SUMORouteLoaderControl* routeLoaders,
212  MSTLLogicControl* tlc,
213  std::vector<SUMOTime> stateDumpTimes,
214  std::vector<std::string> stateDumpFiles) {
215  myEdges = edges;
216  myJunctions = junctions;
217  myRouteLoaders = routeLoaders;
218  myLogics = tlc;
219  // save the time the network state shall be saved at
220  myStateDumpTimes = stateDumpTimes;
221  myStateDumpFiles = stateDumpFiles;
222 
223  // set requests/responses
225 
226  // initialise performance computation
227  if (myLogExecutionTime) {
229  }
230 }
231 
232 
234  // delete events first maybe they do some cleanup
237  delete myEndOfTimestepEvents;
239  delete myInsertionEvents;
240  myInsertionEvents = 0;
241  // delete controls
242  delete myJunctions;
243  delete myDetectorControl;
244  // delete mean data
245  delete myEdges;
246  delete myInserter;
247  delete myLogics;
248  delete myRouteLoaders;
249  delete myVehicleControl;
250  if (myPersonControl != 0) {
251  delete myPersonControl;
252  }
253  delete myShapeContainer;
254  delete myEdgeWeights;
255  delete myRouterTTDijkstra;
256  delete myRouterTTAStar;
257  delete myRouterEffort;
258  myLanesRTree.second.RemoveAll();
259  clearAll();
260 #ifdef HAVE_INTERNAL
262  delete MSGlobals::gMesoNet;
263  }
264 #endif
265  myInstance = 0;
266 }
267 
268 
269 int
271  // report the begin when wished
272  WRITE_MESSAGE("Simulation started with time: " + time2string(start));
273  // the simulation loop
275  myStep = start;
276  // preload the routes especially for TraCI
277  loadRoutes();
278 #ifndef NO_TRACI
279 #ifdef HAVE_PYTHON
280  if (OptionsCont::getOptions().isSet("python-script")) {
281  TraCIServer::runEmbedded(OptionsCont::getOptions().getString("python-script"));
282  closeSimulation(start);
283  WRITE_MESSAGE("Simulation ended at time: " + time2string(getCurrentTimeStep()));
284  WRITE_MESSAGE("Reason: Script ended");
285  return 0;
286  }
287 #endif
288 #endif
289  while (state == SIMSTATE_RUNNING) {
290  if (myLogStepNumber) {
292  }
293  simulationStep();
294  if (myLogStepNumber) {
296  }
297  state = simulationState(stop);
298 #ifndef NO_TRACI
299  if (state != SIMSTATE_RUNNING) {
300  if (OptionsCont::getOptions().getInt("remote-port") != 0 && !TraCIServer::wasClosed()) {
301  state = SIMSTATE_RUNNING;
302  }
303  }
304 #endif
305  }
306  // report the end when wished
307  WRITE_MESSAGE("Simulation ended at time: " + time2string(getCurrentTimeStep()));
308  WRITE_MESSAGE("Reason: " + getStateMessage(state));
309  // exit simulation loop
310  closeSimulation(start);
311  return 0;
312 }
313 
314 void
317 }
318 
319 
320 void
322  if (myLogExecutionTime) {
323  long duration = SysUtils::getCurrentMillis() - mySimBeginMillis;
324  std::ostringstream msg;
325  // print performance notice
326  msg << "Performance: " << "\n" << " Duration: " << duration << "ms" << "\n";
327  if (duration != 0) {
328  msg << " Real time factor: " << (STEPS2TIME(myStep - start) * 1000. / (SUMOReal)duration) << "\n";
329  msg.setf(std::ios::fixed , std::ios::floatfield); // use decimal format
330  msg.setf(std::ios::showpoint); // print decimal point
331  msg << " UPS: " << ((SUMOReal)myVehiclesMoved / ((SUMOReal)duration / 1000)) << "\n";
332  }
333  // print vehicle statistics
334  const std::string discardNotice = ((myVehicleControl->getLoadedVehicleNo() != myVehicleControl->getDepartedVehicleNo()) ?
335  " (Loaded: " + toString(myVehicleControl->getLoadedVehicleNo()) + ")" : "");
336  msg << "Vehicles: " << "\n"
337  << " Inserted: " << myVehicleControl->getDepartedVehicleNo() << discardNotice << "\n"
338  << " Running: " << myVehicleControl->getRunningVehicleNo() << "\n"
339  << " Waiting: " << myInserter->getWaitingVehicleNo() << "\n";
340 
341  if (myVehicleControl->getTeleportCount() > 0) {
342  // print optional teleport statistics
343  std::vector<std::string> reasons;
344  if (myVehicleControl->getCollisionCount() > 0) {
345  reasons.push_back("Collisions: " + toString(myVehicleControl->getCollisionCount()));
346  }
347  if (myVehicleControl->getTeleportsJam() > 0) {
348  reasons.push_back("Jam: " + toString(myVehicleControl->getTeleportsJam()));
349  }
350  if (myVehicleControl->getTeleportsYield() > 0) {
351  reasons.push_back("Yield: " + toString(myVehicleControl->getTeleportsYield()));
352  }
354  reasons.push_back("Wrong Lane: " + toString(myVehicleControl->getTeleportsWrongLane()));
355  }
356  msg << "Teleports: " << myVehicleControl->getTeleportCount() << " (" << joinToString(reasons, ", ") << ")\n";
357  }
358  if (myVehicleControl->getEmergencyStops() > 0) {
359  msg << "Emergency Stops: " << myVehicleControl->getEmergencyStops() << "\n";
360  }
361  WRITE_MESSAGE(msg.str());
362  }
364  if (OptionsCont::getOptions().getBool("vehroute-output.write-unfinished")) {
366  }
367  if (OptionsCont::getOptions().getBool("tripinfo-output.write-unfinished")) {
369  }
370 #ifndef NO_TRACI
372 #endif
373 }
374 
375 
376 void
378 #ifndef NO_TRACI
381  if (t != 0 && t->getTargetTime() != 0 && t->getTargetTime() < myStep) {
382  return;
383  }
384 #endif
385  // execute beginOfTimestepEvents
386  if (myLogExecutionTime) {
388  }
389  // simulation state output
390  std::vector<SUMOTime>::iterator timeIt = find(myStateDumpTimes.begin(), myStateDumpTimes.end(), myStep);
391  if (timeIt != myStateDumpTimes.end()) {
392  const int dist = (int)distance(myStateDumpTimes.begin(), timeIt);
394  }
396 #ifdef HAVE_FOX
397  MSDevice_Routing::waitForAll();
398 #endif
401  }
402  // check whether the tls programs need to be switched
404 
405 #ifdef HAVE_INTERNAL
407  MSGlobals::gMesoNet->simulate(myStep);
408  } else {
409 #endif
410 
411  // assure all lanes with vehicles are 'active'
413 
414  // compute safe velocities for all vehicles for the next few lanes
415  // also register ApproachingVehicleInformation for all links
417 
418  // decide right-of-way and execute movements
422  }
423 
424  // vehicles may change lanes
426 
429  }
430 #ifdef HAVE_INTERNAL
431  }
432 #endif
433  loadRoutes();
434 
435  // persons
436  if (myPersonControl != 0 && myPersonControl->hasPersons()) {
438  }
439  // insert vehicles
442 #ifdef HAVE_FOX
443  MSDevice_Routing::waitForAll();
444 #endif
448  }
450 
451  // execute endOfTimestepEvents
453 
454 #ifndef NO_TRACI
455  if (TraCIServer::getInstance() != 0) {
457  }
458 #endif
459  // update and write (if needed) detector values
460  writeOutput();
461 
462  if (myLogExecutionTime) {
466  }
467  myStep += DELTA_T;
468 }
469 
470 
475  }
476 #ifndef NO_TRACI
477  if (TraCIServer::wasClosed()) {
479  }
480  if (stopTime < 0 && OptionsCont::getOptions().getInt("remote-port") == 0) {
481 #else
482  if (stopTime < 0) {
483 #endif
486  && (myInserter->getPendingFlowCount() == 0)
487  && (myPersonControl == 0 || !myPersonControl->hasNonWaiting())) {
488  if (myPersonControl) {
490  }
493  }
494  }
495  if (stopTime >= 0 && myStep >= stopTime) {
497  }
498  return SIMSTATE_RUNNING;
499 }
500 
501 
502 std::string
504  switch (state) {
506  return "";
508  return "The final simulation step has been reached.";
510  return "All vehicles have left the simulation.";
512  return "TraCI requested termination.";
514  return "An error occured (see log).";
516  return "Too many vehicles.";
517  default:
518  return "Unknown reason.";
519  }
520 }
521 
522 
523 void
525  // clear container
526  MSEdge::clear();
527  MSLane::clear();
528  MSRoute::clear();
535 }
536 
537 
538 void
540  // update detector values
542 
543  // check state dumps
544  if (OptionsCont::getOptions().isSet("netstate-dump")) {
546  }
547 
548  // check fcd dumps
549  if (OptionsCont::getOptions().isSet("fcd-output")) {
551  }
552 
553  // check emission dumps
554  if (OptionsCont::getOptions().isSet("emission-output")) {
556  }
557 
558  // check full dumps
559  if (OptionsCont::getOptions().isSet("full-output")) {
561  }
562 
563  // check queue dumps
564  if (OptionsCont::getOptions().isSet("queue-output")) {
566  }
567 
568  // check amitran dumps
569  if (OptionsCont::getOptions().isSet("amitran-output")) {
571  }
572 
573  // check vtk dumps
574  if (OptionsCont::getOptions().isSet("vtk-output")) {
575 
576  if (MSNet::getInstance()->getVehicleControl().getRunningVehicleNo() > 0) {
577  std::string timestep = time2string(myStep);
578  timestep = timestep.substr(0, timestep.length() - 3);
579  std::string output = OptionsCont::getOptions().getString("vtk-output");
580  std::string filename = output + "_" + timestep + ".vtp";
581 
582  OutputDevice_File dev = OutputDevice_File(filename, false);
583 
584  //build a huge mass of xml files
586 
587  }
588 
589  }
590 
591  // summary output
592  if (OptionsCont::getOptions().isSet("summary-output")) {
593  OutputDevice& od = OutputDevice::getDeviceByOption("summary-output");
594  unsigned int departedVehiclesNumber = myVehicleControl->getDepartedVehicleNo();
595  const SUMOReal meanWaitingTime = departedVehiclesNumber != 0 ? myVehicleControl->getTotalDepartureDelay() / (SUMOReal) departedVehiclesNumber : -1.;
596  unsigned int endedVehicleNumber = myVehicleControl->getEndedVehicleNo();
597  const SUMOReal meanTravelTime = endedVehicleNumber != 0 ? myVehicleControl->getTotalTravelTime() / (SUMOReal) endedVehicleNumber : -1.;
599  .writeAttr("inserted", myVehicleControl->getDepartedVehicleNo()).writeAttr("running", myVehicleControl->getRunningVehicleNo())
600  .writeAttr("waiting", myInserter->getWaitingVehicleNo()).writeAttr("ended", myVehicleControl->getEndedVehicleNo())
601  .writeAttr("meanWaitingTime", meanWaitingTime).writeAttr("meanTravelTime", meanTravelTime);
602  if (myLogExecutionTime) {
603  od.writeAttr("duration", mySimStepDuration);
604  }
605  od.closeTag();
606  }
607 
608  // write detector values
610 
611  // write link states
612  if (OptionsCont::getOptions().isSet("link-output")) {
613  OutputDevice& od = OutputDevice::getDeviceByOption("link-output");
614  od.openTag("timestep");
616  const std::vector<MSEdge*>& edges = myEdges->getEdges();
617  for (std::vector<MSEdge*>::const_iterator i = edges.begin(); i != edges.end(); ++i) {
618  const std::vector<MSLane*>& lanes = (*i)->getLanes();
619  for (std::vector<MSLane*>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
620  const std::vector<MSLink*>& links = (*j)->getLinkCont();
621  for (std::vector<MSLink*>::const_iterator k = links.begin(); k != links.end(); ++k) {
622  (*k)->writeApproaching(od, (*j)->getID());
623  }
624  }
625  }
626  od.closeTag();
627  }
628 }
629 
630 
631 bool
633  return myLogExecutionTime;
634 }
635 
636 
639  if (myPersonControl == 0) {
641  }
642  return *myPersonControl;
643 }
644 
645 
648  if (myEdgeWeights == 0) {
650  }
651  return *myEdgeWeights;
652 }
653 
654 
655 void
657  std::cout << "Step #" << time2string(myStep);
658 }
659 
660 
661 void
663  if (myLogExecutionTime) {
664  std::ostringstream oss;
665  oss.setf(std::ios::fixed , std::ios::floatfield); // use decimal format
666  oss.setf(std::ios::showpoint); // print decimal point
667  oss << std::setprecision(OUTPUT_ACCURACY);
668  if (mySimStepDuration != 0) {
669  oss << " (" << mySimStepDuration << "ms ~= "
670  << (1000. / (SUMOReal) mySimStepDuration) << "*RT, ~"
672  } else {
673  oss << " (0ms ?*RT. ?";
674  }
675  oss << "UPS, vehicles"
676  << " TOT " << myVehicleControl->getDepartedVehicleNo()
677  << " ACT " << myVehicleControl->getRunningVehicleNo()
678  << ") ";
679  std::string prev = "Step #" + time2string(myStep - DELTA_T);
680  std::cout << oss.str().substr(0, 78 - prev.length());
681  }
682  std::cout << '\r';
683 }
684 
685 
686 void
688  if (find(myVehicleStateListeners.begin(), myVehicleStateListeners.end(), listener) == myVehicleStateListeners.end()) {
689  myVehicleStateListeners.push_back(listener);
690  }
691 }
692 
693 
694 void
696  std::vector<VehicleStateListener*>::iterator i = find(myVehicleStateListeners.begin(), myVehicleStateListeners.end(), listener);
697  if (i != myVehicleStateListeners.end()) {
698  myVehicleStateListeners.erase(i);
699  }
700 }
701 
702 
703 void
705  for (std::vector<VehicleStateListener*>::iterator i = myVehicleStateListeners.begin(); i != myVehicleStateListeners.end(); ++i) {
706  (*i)->vehicleStateChanged(vehicle, to);
707  }
708 }
709 
710 
711 
712 // ------ Insertion and retrieval of bus stops ------
713 bool
715  return myBusStopDict.add(busStop->getID(), busStop);
716 }
717 
718 
719 MSBusStop*
720 MSNet::getBusStop(const std::string& id) const {
721  return myBusStopDict.get(id);
722 }
723 
724 
725 std::string
726 MSNet::getBusStopID(const MSLane* lane, const SUMOReal pos) const {
727  const std::map<std::string, MSBusStop*>& vals = myBusStopDict.getMyMap();
728  for (std::map<std::string, MSBusStop*>::const_iterator it = vals.begin(); it != vals.end(); ++it) {
729  MSBusStop* stop = it->second;
730  if (&stop->getLane() == lane && fabs(stop->getEndLanePosition() - pos) < POSITION_EPS) {
731  return stop->getID();
732  }
733  }
734  return "";
735 }
736 
737 
739 MSNet::getRouterTT(const std::vector<MSEdge*>& prohibited) const {
740  if (!myRouterTTInitialized) {
741  myRouterTTInitialized = true;
742  const std::string routingAlgorithm = OptionsCont::getOptions().getString("routing-algorithm");
743  if (routingAlgorithm == "dijkstra") {
746  } else {
747  if (routingAlgorithm != "astar") {
748  WRITE_WARNING("TraCI and Triggers cannot use routing algorithm '" + routingAlgorithm + "'. using 'astar' instead.");
749  }
752  }
753  }
754  if (myRouterTTDijkstra != 0) {
755  myRouterTTDijkstra->prohibit(prohibited);
756  return *myRouterTTDijkstra;
757  } else {
758  assert(myRouterTTAStar != 0);
759  myRouterTTAStar->prohibit(prohibited);
760  return *myRouterTTAStar;
761  }
762 }
763 
764 
766 MSNet::getRouterEffort(const std::vector<MSEdge*>& prohibited) const {
767  if (myRouterEffort == 0) {
770  }
771  myRouterEffort->prohibit(prohibited);
772  return *myRouterEffort;
773 }
774 
775 
777 MSNet::getPedestrianRouter(const std::vector<MSEdge*>& prohibited) const {
778  if (myPedestrianRouter == 0) {
780  }
781  myPedestrianRouter->prohibit(prohibited);
782  return *myPedestrianRouter;
783 }
784 
785 
786 const NamedRTree&
788  if (!myLanesRTree.first) {
789  MSLane::fill(myLanesRTree.second);
790  myLanesRTree.first = true;
791  }
792  return myLanesRTree.second;
793 }
794 
795 
796 /****************************************************************************/
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:662
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:78
Interface for objects listening to vehicle state changes.
Definition: MSNet.h:464
long mySimStepEnd
Definition: MSNet.h:592
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:695
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:571
static SUMOReal getEffort(const MSEdge *const e, const SUMOVehicle *const v, SUMOReal t)
Returns the effort to pass an edge.
Definition: MSNet.cpp:124
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:563
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:909
MSVehicleControl * myVehicleControl
Controls vehicle building and deletion;.
Definition: MSNet.h:555
void updateDetectors(const SUMOTime step)
Computes detector values.
std::vector< SUMOTime > myStateDumpTimes
Times at which a state shall be written.
Definition: MSNet.h:607
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:270
void changeLanes(SUMOTime t)
Moves (precomputes) critical vehicles.
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:61
A RT-tree for efficient storing of SUMO&#39;s Named objects.
Definition: NamedRTree.h:72
Computes the shortest path through a network using the Dijkstra algorithm.
Definition: AStarRouter.h:71
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:557
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:156
MSEdgeControl * myEdges
Controls edges, performs vehicle movement;.
Definition: MSNet.h:559
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:609
bool myLogExecutionTime
Information whether the simulation duration shall be logged.
Definition: MSNet.h:586
Storage for geometrical objects.
static const std::string STAGE_LANECHANGE
Definition: MSNet.h:645
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:230
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:766
std::string getBusStopID(const MSLane *lane, const SUMOReal pos) const
Returns the bus stop close to the given position.
Definition: MSNet.cpp:726
void addVehicleStateListener(VehicleStateListener *listener)
Adds a vehicle states listener.
Definition: MSNet.cpp:687
SimulationState
Possible states of a simulation - running or stopped with different reasons.
Definition: MSNet.h:96
MSPedestrianRouterDijkstra * myPedestrianRouter
Definition: MSNet.h:635
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
The simulated network and simulation perfomer.
Definition: MSNet.h:91
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:598
DijkstraRouterTT< MSEdge, SUMOVehicle, prohibited_withRestrictions< MSEdge, SUMOVehicle > > * myRouterTTDijkstra
Definition: MSNet.h:632
ShapeContainer * myShapeContainer
A container for geometrical shapes;.
Definition: MSNet.h:575
std::pair< bool, NamedRTree > myLanesRTree
An RTree structure holding lane IDs.
Definition: MSNet.h:639
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:634
SUMOReal getTotalTravelTime() const
Returns the total travel time.
bool addBusStop(MSBusStop *busStop)
Adds a bus stop.
Definition: MSNet.cpp:714
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:75
void prohibit(const std::vector< E * > &toProhibit)
long mySimStepBegin
The last simulation step begin, end and duration.
Definition: MSNet.h:592
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.
static void generateOutputForUnfinished()
generate output for vehicles which are still in the network
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:539
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:565
Representation of a vehicle.
Definition: SUMOVehicle.h:64
void checkInsertions(SUMOTime time)
Checks &quot;movement&quot; 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:61
SUMORouteLoaderControl * myRouteLoaders
Route loader for dynamic loading of routes.
Definition: MSNet.h:544
void closeSimulation(SUMOTime start)
Closes the simulation (all files, connections, etc.)
Definition: MSNet.cpp:321
bool myLogStepNumber
Information whether the number of the simulation step shall be logged.
Definition: MSNet.h:589
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:569
SUMOTime getTargetTime()
Definition: TraCIServer.h:80
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:283
static SUMOReal getTravelTime(const MSEdge *const e, const SUMOVehicle *const v, SUMOReal t)
Returns the travel time to pass an edge.
Definition: MSNet.cpp:138
MSDetectorControl * myDetectorControl
Controls detectors;.
Definition: MSNet.h:567
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:563
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
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:189
void preSimStepOutput() const
Prints the current step number.
Definition: MSNet.cpp:656
MSBusStop * getBusStop(const std::string &id) const
Returns the named bus stop.
Definition: MSNet.cpp:720
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
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:437
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:644
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:624
static MSNet * myInstance
Unique instance of MSNet.
Definition: MSNet.h:541
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:524
bool myRouterTTInitialized
Definition: MSNet.h:631
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:472
MSJunctionControl * myJunctions
Controls junctions, realizes right-of-way rules;.
Definition: MSNet.h:561
virtual MSPersonControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:638
static void clear()
Clears the dictionary.
Definition: MSLane.cpp:892
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:569
A storage for options typed value containers)
Definition: OptionsCont.h:108
MSEdgeWeightsStorage * myEdgeWeights
The net&#39;s knowledge about edge efforts/travel times;.
Definition: MSNet.h:577
MSNet(MSVehicleControl *vc, MSEventControl *beginOfTimestepEvents, MSEventControl *endOfTimestepEvents, MSEventControl *insertionEvents, ShapeContainer *shapeCont=0)
Constructor.
Definition: MSNet.cpp:164
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:739
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&#39;s state change.
Definition: MSNet.cpp:704
const NamedRTree & getLanesRTree() const
Returns an RTree that contains lane IDs.
Definition: MSNet.cpp:787
static void cleanup()
cleanup remaining data structures
long mySimBeginMillis
The overall simulation duration.
Definition: MSNet.h:595
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:233
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: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:503
SUMOReal getMinimumTravelTime(const SUMOVehicle *const veh) const
returns the minimum travel time for the given vehicle
Definition: MSEdge.h:389
bool logSimulationDuration() const
Returns whether duration shall be logged.
Definition: MSNet.cpp:632
AStarRouter< MSEdge, SUMOVehicle, prohibited_withRestrictions< MSEdge, SUMOVehicle > > * myRouterTTAStar
Definition: MSNet.h:633
#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:547
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&#39;s building process.
Definition: MSNet.cpp:210
NamedObjectCont< MSBusStop * > myBusStopDict
Dictionary of bus stops.
Definition: MSNet.h:621
void simulationStep()
Performs a single simulation step.
Definition: MSNet.cpp:377
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:315
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:201
MSPedestrianRouterDijkstra & getPedestrianRouter(const std::vector< MSEdge * > &prohibited=std::vector< MSEdge * >()) const
Definition: MSNet.cpp:777
static const std::string STAGE_INSERTIONS
Definition: MSNet.h:646
MSEventControl * myInsertionEvents
Controls insertion events;.
Definition: MSNet.h:573
int myTooManyVehicles
Storage for maximum vehicle number.
Definition: MSNet.h:618
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:518
long mySimStepDuration
Definition: MSNet.h:592
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
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.
MSEdgeWeightsStorage & getWeightsStorage()
Returns the net&#39;s internal edge travel times/efforts container.
Definition: MSNet.cpp:647
static const std::string STAGE_EVENTS
string constants for simstep stages
Definition: MSNet.h:643