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 /****************************************************************************/
13 // The simulated network and simulation perfomer
14 /****************************************************************************/
15 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
16 // Copyright (C) 2001-2014 DLR (http://www.dlr.de/) and contributors
17 /****************************************************************************/
18 //
19 // This file is part of SUMO.
20 // SUMO is free software: you can redistribute it and/or modify
21 // it under the terms of the GNU General Public License as published by
22 // the Free Software Foundation, either version 3 of the License, or
23 // (at your option) any later version.
24 //
25 /****************************************************************************/
26 
27 
28 // ===========================================================================
29 // included modules
30 // ===========================================================================
31 #ifdef _MSC_VER
32 #include <windows_config.h>
33 #else
34 #include <config.h>
35 #endif
36 
37 #ifdef HAVE_VERSION_H
38 #include <version.h>
39 #endif
40 
41 #include <string>
42 #include <iostream>
43 #include <sstream>
44 #include <typeinfo>
45 #include <algorithm>
46 #include <cassert>
47 #include <vector>
49 #include "MSNet.h"
50 #include "MSPersonControl.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>
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"
84 #include <utils/common/SysUtils.h>
87 #include "MSGlobals.h"
89 #include <ctime>
90 #include "MSPerson.h"
91 #include "MSEdgeWeightsStorage.h"
92 #include "MSStateHandler.h"
93 
94 #ifdef HAVE_INTERNAL
95 #include <mesosim/MELoop.h>
97 #endif
98 
99 #ifndef NO_TRACI
101 #endif
102 
103 #ifdef CHECK_MEMORY_LEAKS
104 #include <foreign/nvwa/debug_new.h>
105 #endif // CHECK_MEMORY_LEAKS
106 
107 
108 // ===========================================================================
109 // static member definitions
110 // ===========================================================================
112 
113 const std::string MSNet::STAGE_EVENTS("events");
114 const std::string MSNet::STAGE_MOVEMENTS("move");
115 const std::string MSNet::STAGE_LANECHANGE("laneChange");
116 const std::string MSNet::STAGE_INSERTIONS("insertion");
117 
118 // ===========================================================================
119 // member method definitions
120 // ===========================================================================
121 SUMOReal
122 MSNet::getEffort(const MSEdge* const e, const SUMOVehicle* const v, SUMOReal t) {
123  SUMOReal value;
124  const MSVehicle* const veh = dynamic_cast<const MSVehicle* const>(v);
125  if (veh != 0 && veh->getWeightsStorage().retrieveExistingEffort(e, v, t, value)) {
126  return value;
127  }
128  if (getInstance()->getWeightsStorage().retrieveExistingEffort(e, v, t, value)) {
129  return value;
130  }
131  return 0;
132 }
133 
134 
135 SUMOReal
136 MSNet::getTravelTime(const MSEdge* const e, const SUMOVehicle* const v, SUMOReal t) {
137  SUMOReal value;
138  const MSVehicle* const veh = dynamic_cast<const MSVehicle* const>(v);
139  if (veh != 0 && veh->getWeightsStorage().retrieveExistingTravelTime(e, v, t, value)) {
140  return value;
141  }
142  if (getInstance()->getWeightsStorage().retrieveExistingTravelTime(e, v, t, value)) {
143  return value;
144  }
145  return e->getMinimumTravelTime(v);
146 }
147 
148 
149 
150 // ---------------------------------------------------------------------------
151 // MSNet - methods
152 // ---------------------------------------------------------------------------
153 MSNet*
155  if (myInstance != 0) {
156  return myInstance;
157  }
158  throw ProcessError("A network was not yet constructed.");
159 }
160 
161 
162 MSNet::MSNet(MSVehicleControl* vc, MSEventControl* beginOfTimestepEvents,
163  MSEventControl* endOfTimestepEvents, MSEventControl* insertionEvents,
164  ShapeContainer* shapeCont):
165  myVehiclesMoved(0),
166  myRouterTTInitialized(false),
167  myRouterTTDijkstra(0),
168  myRouterTTAStar(0),
169  myRouterEffort(0) {
170  if (myInstance != 0) {
171  throw ProcessError("A network was already constructed.");
172  }
174  myStep = string2time(oc.getString("begin"));
175  myLogExecutionTime = !oc.getBool("no-duration-log");
176  myLogStepNumber = !oc.getBool("no-step-log");
177  myTooManyVehicles = oc.getInt("max-num-vehicles");
178  myInserter = new MSInsertionControl(*vc, string2time(oc.getString("max-depart-delay")), !oc.getBool("eager-insert"));
179  myVehicleControl = vc;
181  myEdges = 0;
182  myJunctions = 0;
183  myRouteLoaders = 0;
184  myLogics = 0;
185  myPersonControl = 0;
186  myEdgeWeights = 0;
187  myShapeContainer = shapeCont == 0 ? new ShapeContainer() : shapeCont;
188 
189  myBeginOfTimestepEvents = beginOfTimestepEvents;
190  myEndOfTimestepEvents = endOfTimestepEvents;
191  myInsertionEvents = insertionEvents;
192  myLanesRTree.first = false;
193 
194 #ifdef HAVE_INTERNAL
196  MSGlobals::gMesoNet = new MELoop(string2time(oc.getString("meso-recheck")));
197  }
198 #endif
199  myInstance = this;
200 }
201 
202 
203 
204 
205 void
207  SUMORouteLoaderControl* routeLoaders,
208  MSTLLogicControl* tlc,
209  std::vector<SUMOTime> stateDumpTimes,
210  std::vector<std::string> stateDumpFiles) {
211  myEdges = edges;
212  myJunctions = junctions;
213  myRouteLoaders = routeLoaders;
214  myLogics = tlc;
215  // save the time the network state shall be saved at
216  myStateDumpTimes = stateDumpTimes;
217  myStateDumpFiles = stateDumpFiles;
218 
219  // set requests/responses
221 
222  // initialise performance computation
223  if (myLogExecutionTime) {
225  }
226 }
227 
228 
230  // delete events first maybe they do some cleanup
232  delete myEndOfTimestepEvents;
233  delete myInsertionEvents;
234  // delete controls
235  delete myJunctions;
236  delete myDetectorControl;
237  // delete mean data
238  delete myEdges;
239  delete myInserter;
240  delete myLogics;
241  delete myRouteLoaders;
242  delete myVehicleControl;
243  if (myPersonControl != 0) {
244  delete myPersonControl;
245  }
246  delete myShapeContainer;
247  delete myEdgeWeights;
248  delete myRouterTTDijkstra;
249  delete myRouterTTAStar;
250  delete myRouterEffort;
251  myLanesRTree.second.RemoveAll();
252  clearAll();
253 #ifdef HAVE_INTERNAL
255  delete MSGlobals::gMesoNet;
256  }
257 #endif
258  myInstance = 0;
259 }
260 
261 
262 int
264  // report the begin when wished
265  WRITE_MESSAGE("Simulation started with time: " + time2string(start));
266  // the simulation loop
268  myStep = start;
269  // preload the routes especially for TraCI
270  loadRoutes();
271 #ifndef NO_TRACI
272 #ifdef HAVE_PYTHON
273  if (OptionsCont::getOptions().isSet("python-script")) {
274  TraCIServer::runEmbedded(OptionsCont::getOptions().getString("python-script"));
275  closeSimulation(start);
276  WRITE_MESSAGE("Simulation ended at time: " + time2string(getCurrentTimeStep()));
277  WRITE_MESSAGE("Reason: Script ended");
278  return 0;
279  }
280 #endif
281 #endif
282  while (state == SIMSTATE_RUNNING) {
283  if (myLogStepNumber) {
285  }
286  simulationStep();
287  if (myLogStepNumber) {
289  }
290  state = simulationState(stop);
291 #ifndef NO_TRACI
292  if (state != SIMSTATE_RUNNING) {
293  if (OptionsCont::getOptions().getInt("remote-port") != 0 && !TraCIServer::wasClosed()) {
294  state = SIMSTATE_RUNNING;
295  }
296  }
297 #endif
298  }
299  // report the end when wished
300  WRITE_MESSAGE("Simulation ended at time: " + time2string(getCurrentTimeStep()));
301  WRITE_MESSAGE("Reason: " + getStateMessage(state));
302  // exit simulation loop
303  closeSimulation(start);
304  return 0;
305 }
306 
307 void
310 }
311 
312 
313 void
315  if (myLogExecutionTime) {
316  long duration = SysUtils::getCurrentMillis() - mySimBeginMillis;
317  std::ostringstream msg;
318  // print performance notice
319  msg << "Performance: " << "\n" << " Duration: " << duration << " ms" << "\n";
320  if (duration != 0) {
321  msg << " Real time factor: " << (STEPS2TIME(myStep - start) * 1000. / (SUMOReal)duration) << "\n";
322  msg.setf(std::ios::fixed , std::ios::floatfield); // use decimal format
323  msg.setf(std::ios::showpoint); // print decimal point
324  msg << " UPS: " << ((SUMOReal)myVehiclesMoved / ((SUMOReal)duration / 1000)) << "\n";
325  }
326  // print vehicle statistics
327  const std::string discardNotice = ((myVehicleControl->getLoadedVehicleNo() != myVehicleControl->getDepartedVehicleNo()) ?
328  " (Loaded: " + toString(myVehicleControl->getLoadedVehicleNo()) + ")" : "");
329  msg << "Vehicles: " << "\n"
330  << " Inserted: " << myVehicleControl->getDepartedVehicleNo() << discardNotice << "\n"
331  << " Running: " << myVehicleControl->getRunningVehicleNo() << "\n"
332  << " Waiting: " << myInserter->getWaitingVehicleNo() << "\n";
333 
334  if (myVehicleControl->getTeleportCount() > 0) {
335  // print optional teleport statistics
336  std::vector<std::string> reasons;
337  if (myVehicleControl->getCollisionCount() > 0) {
338  reasons.push_back("Collisions: " + toString(myVehicleControl->getCollisionCount()));
339  }
340  if (myVehicleControl->getTeleportsJam() > 0) {
341  reasons.push_back("Jam: " + toString(myVehicleControl->getTeleportsJam()));
342  }
343  if (myVehicleControl->getTeleportsYield() > 0) {
344  reasons.push_back("Yield: " + toString(myVehicleControl->getTeleportsYield()));
345  }
347  reasons.push_back("Wrong Lane: " + toString(myVehicleControl->getTeleportsWrongLane()));
348  }
349  msg << "Teleports: " << myVehicleControl->getTeleportCount() << " (" << joinToString(reasons, ", ") << ")\n";
350  }
351  WRITE_MESSAGE(msg.str());
352  }
354  if (OptionsCont::getOptions().getBool("vehroute-output.write-unfinished")) {
356  }
357 #ifndef NO_TRACI
359 #endif
360 }
361 
362 
363 void
365 #ifndef NO_TRACI
368  if (t != 0 && t->getTargetTime() != 0 && t->getTargetTime() < myStep) {
369  return;
370  }
371 #endif
372  // execute beginOfTimestepEvents
373  if (myLogExecutionTime) {
375  }
376  // simulation state output
377  std::vector<SUMOTime>::iterator timeIt = find(myStateDumpTimes.begin(), myStateDumpTimes.end(), myStep);
378  if (timeIt != myStateDumpTimes.end()) {
379  const int dist = (int)distance(myStateDumpTimes.begin(), timeIt);
381  }
385  }
386  // check whether the tls programs need to be switched
388 
389 #ifdef HAVE_INTERNAL
391  MSGlobals::gMesoNet->simulate(myStep);
392  } else {
393 #endif
394 
395  // assure all lanes with vehicles are 'active'
397 
398  // compute safe velocities for all vehicles for the next few lanes
399  // also register ApproachingVehicleInformation for all links
401 
402  // decide right-of-way and execute movements
406  }
407 
408  // Vehicles change Lanes (maybe)
410 
413  }
414 #ifdef HAVE_INTERNAL
415  }
416 #endif
417  loadRoutes();
418 
419  // persons
420  if (myPersonControl != 0) {
422  }
423  // insert Vehicles
428  }
430 
431  // execute endOfTimestepEvents
433 
434 #ifndef NO_TRACI
435  if (TraCIServer::getInstance() != 0) {
437  }
438 #endif
439  // update and write (if needed) detector values
440  writeOutput();
441 
442  if (myLogExecutionTime) {
446  }
447  myStep += DELTA_T;
448 }
449 
450 
455  }
456 #ifndef NO_TRACI
457  if (TraCIServer::wasClosed()) {
459  }
460  if (stopTime < 0 && OptionsCont::getOptions().getInt("remote-port") == 0) {
461 #else
462  if (stopTime < 0) {
463 #endif
466  && (myInserter->getPendingFlowCount() == 0)
467  && (myPersonControl == 0 || !myPersonControl->hasNonWaiting())) {
468  if (myPersonControl) {
470  }
473  }
474  }
475  if (stopTime >= 0 && myStep >= stopTime) {
477  }
478  return SIMSTATE_RUNNING;
479 }
480 
481 
482 std::string
484  switch (state) {
486  return "";
488  return "The final simulation step has been reached.";
490  return "All vehicles have left the simulation.";
492  return "TraCI requested termination.";
494  return "An error occured (see log).";
496  return "Too many vehicles.";
497  default:
498  return "Unknown reason.";
499  }
500 }
501 
502 
503 void
505  // clear container
506  MSEdge::clear();
507  MSLane::clear();
508  MSRoute::clear();
513 }
514 
515 
516 void
518  // update detector values
520 
521  // check state dumps
522  if (OptionsCont::getOptions().isSet("netstate-dump")) {
524  }
525 
526  // check fcd dumps
527  if (OptionsCont::getOptions().isSet("fcd-output")) {
529  }
530 
531  // check emission dumps
532  if (OptionsCont::getOptions().isSet("emission-output")) {
534  }
535 
536  // check full dumps
537  if (OptionsCont::getOptions().isSet("full-output")) {
539  }
540 
541  // check queue dumps
542  if (OptionsCont::getOptions().isSet("queue-output")) {
544  }
545 
546  // check vtk dumps
547  if (OptionsCont::getOptions().isSet("vtk-output")) {
548 
549  if (MSNet::getInstance()->getVehicleControl().getRunningVehicleNo() > 0) {
550  std::string timestep = time2string(myStep);
551  timestep = timestep.substr(0, timestep.length() - 3);
552  std::string output = OptionsCont::getOptions().getString("vtk-output");
553  std::string filename = output + "_" + timestep + ".vtp";
554 
555  OutputDevice_File dev = OutputDevice_File(filename, false);
556 
557  //build a huge mass of xml files
559 
560  }
561 
562  }
563 
564  // summary output
565  if (OptionsCont::getOptions().isSet("summary-output")) {
566  OutputDevice& od = OutputDevice::getDeviceByOption("summary-output");
567  unsigned int departedVehiclesNumber = myVehicleControl->getDepartedVehicleNo();
568  const SUMOReal meanWaitingTime = departedVehiclesNumber != 0 ? myVehicleControl->getTotalDepartureDelay() / (SUMOReal) departedVehiclesNumber : -1.;
569  unsigned int endedVehicleNumber = myVehicleControl->getEndedVehicleNo();
570  const SUMOReal meanTravelTime = endedVehicleNumber != 0 ? myVehicleControl->getTotalTravelTime() / (SUMOReal) endedVehicleNumber : -1.;
572  .writeAttr("inserted", myVehicleControl->getDepartedVehicleNo()).writeAttr("running", myVehicleControl->getRunningVehicleNo())
573  .writeAttr("waiting", myInserter->getWaitingVehicleNo()).writeAttr("ended", myVehicleControl->getEndedVehicleNo())
574  .writeAttr("meanWaitingTime", meanWaitingTime).writeAttr("meanTravelTime", meanTravelTime);
575  if (myLogExecutionTime) {
576  od.writeAttr("duration", mySimStepDuration);
577  }
578  od.closeTag();
579  }
580 
581  // write detector values
583 
584  // write link states
585  if (OptionsCont::getOptions().isSet("link-output")) {
586  OutputDevice& od = OutputDevice::getDeviceByOption("link-output");
587  od.openTag("timestep");
589  const std::vector<MSEdge*>& edges = myEdges->getEdges();
590  for (std::vector<MSEdge*>::const_iterator i = edges.begin(); i != edges.end(); ++i) {
591  const std::vector<MSLane*>& lanes = (*i)->getLanes();
592  for (std::vector<MSLane*>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
593  const std::vector<MSLink*>& links = (*j)->getLinkCont();
594  for (std::vector<MSLink*>::const_iterator k = links.begin(); k != links.end(); ++k) {
595  (*k)->writeApproaching(od, (*j)->getID());
596  }
597  }
598  }
599  od.closeTag();
600  }
601 }
602 
603 
604 bool
606  return myLogExecutionTime;
607 }
608 
609 
612  if (myPersonControl == 0) {
614  }
615  return *myPersonControl;
616 }
617 
618 
621  if (myEdgeWeights == 0) {
623  }
624  return *myEdgeWeights;
625 }
626 
627 
628 void
630  std::cout << "Step #" << time2string(myStep);
631 }
632 
633 
634 void
636  if (myLogExecutionTime) {
637  std::ostringstream oss;
638  oss.setf(std::ios::fixed , std::ios::floatfield); // use decimal format
639  oss.setf(std::ios::showpoint); // print decimal point
640  oss << std::setprecision(OUTPUT_ACCURACY);
641  if (mySimStepDuration != 0) {
642  oss << " (" << mySimStepDuration << "ms ~= "
643  << (1000. / (SUMOReal) mySimStepDuration) << "*RT, ~"
645  } else {
646  oss << " (0ms ?*RT. ?";
647  }
648  oss << "UPS, vehicles"
649  << " TOT " << myVehicleControl->getDepartedVehicleNo()
650  << " ACT " << myVehicleControl->getRunningVehicleNo()
651  << ") ";
652  std::string prev = "Step #" + time2string(myStep - DELTA_T);
653  std::cout << oss.str().substr(0, 78 - prev.length());
654  }
655  std::cout << '\r';
656 }
657 
658 
659 void
661  if (find(myVehicleStateListeners.begin(), myVehicleStateListeners.end(), listener) == myVehicleStateListeners.end()) {
662  myVehicleStateListeners.push_back(listener);
663  }
664 }
665 
666 
667 void
669  std::vector<VehicleStateListener*>::iterator i = find(myVehicleStateListeners.begin(), myVehicleStateListeners.end(), listener);
670  if (i != myVehicleStateListeners.end()) {
671  myVehicleStateListeners.erase(i);
672  }
673 }
674 
675 
676 void
678  for (std::vector<VehicleStateListener*>::iterator i = myVehicleStateListeners.begin(); i != myVehicleStateListeners.end(); ++i) {
679  (*i)->vehicleStateChanged(vehicle, to);
680  }
681 }
682 
683 
684 
685 // ------ Insertion and retrieval of bus stops ------
686 bool
688  return myBusStopDict.add(busStop->getID(), busStop);
689 }
690 
691 
692 MSBusStop*
693 MSNet::getBusStop(const std::string& id) const {
694  return myBusStopDict.get(id);
695 }
696 
697 
698 std::string
699 MSNet::getBusStopID(const MSLane* lane, const SUMOReal pos) const {
700  const std::map<std::string, MSBusStop*>& vals = myBusStopDict.getMyMap();
701  for (std::map<std::string, MSBusStop*>::const_iterator it = vals.begin(); it != vals.end(); ++it) {
702  MSBusStop* stop = it->second;
703  if (&stop->getLane() == lane && fabs(stop->getEndLanePosition() - pos) < POSITION_EPS) {
704  return stop->getID();
705  }
706  }
707  return "";
708 }
709 
710 
712 MSNet::getRouterTT(const std::vector<MSEdge*>& prohibited) const {
713  if (!myRouterTTInitialized) {
714  myRouterTTInitialized = true;
715  const std::string routingAlgorithm = OptionsCont::getOptions().getString("routing-algorithm");
716  if (routingAlgorithm == "dijkstra") {
719  } else {
720  if (routingAlgorithm != "astar") {
721  WRITE_WARNING("TraCI and Triggers cannot use routing algorithm '" + routingAlgorithm + "'. using 'astar' instead.");
722  }
725  }
726  }
727  if (myRouterTTDijkstra != 0) {
728  myRouterTTDijkstra->prohibit(prohibited);
729  return *myRouterTTDijkstra;
730  } else {
731  assert(myRouterTTAStar != 0);
732  myRouterTTAStar->prohibit(prohibited);
733  return *myRouterTTAStar;
734  }
735 }
736 
737 
739 MSNet::getRouterEffort(const std::vector<MSEdge*>& prohibited) const {
740  if (myRouterEffort == 0) {
743  }
744  myRouterEffort->prohibit(prohibited);
745  return *myRouterEffort;
746 }
747 
748 
749 const NamedRTree&
751  if (!myLanesRTree.first) {
752  MSLane::fill(myLanesRTree.second);
753  myLanesRTree.first = true;
754  }
755  return myLanesRTree.second;
756 }
757 
758 
759 /****************************************************************************/
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:256
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:635
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
Interface for objects listening to vehicle state changes.
Definition: MSNet.h:444
long mySimStepEnd
Definition: MSNet.h:571
void loadNext(SUMOTime step)
loads the next routes
void removeVehicleStateListener(VehicleStateListener *listener)
Removes a vehicle states listener.
Definition: MSNet.cpp:668
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:550
static SUMOReal getEffort(const MSEdge *const e, const SUMOVehicle *const v, SUMOReal t)
Returns the effort to pass an edge.
Definition: MSNet.cpp:122
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:505
The simulation contains too many vehicles (.
Definition: MSNet.h:106
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:869
MSVehicleControl * myVehicleControl
Controls vehicle building and deletion;.
Definition: MSNet.h:534
bool retrieveExistingTravelTime(const MSEdge *const e, const SUMOVehicle *const v, SUMOReal t, SUMOReal &value) const
Returns a travel time for an edge and time if stored.
void updateDetectors(const SUMOTime step)
Computes detector values.
std::vector< SUMOTime > myStateDumpTimes
Times at which a state shall be written.
Definition: MSNet.h:586
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)
int simulate(SUMOTime start, SUMOTime stop)
Simulates from timestep start to stop.
Definition: MSNet.cpp:263
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:70
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:536
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:154
MSEdgeControl * myEdges
Controls edges, performs vehicle movement;.
Definition: MSNet.h:538
The final simulation step has been performed.
Definition: MSNet.h:98
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:588
bool myLogExecutionTime
Information whether the simulation duration shall be logged.
Definition: MSNet.h:565
Storage for geometrical objects.
static const std::string STAGE_LANECHANGE
Definition: MSNet.h:620
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:71
bool retrieveExistingEffort(const MSEdge *const e, const SUMOVehicle *const v, SUMOReal t, SUMOReal &value) const
Returns an effort for an edge and time if stored.
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:210
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:739
std::string getBusStopID(const MSLane *lane, const SUMOReal pos) const
Returns the bus stop close to the given position.
Definition: MSNet.cpp:699
void addVehicleStateListener(VehicleStateListener *listener)
Adds a vehicle states listener.
Definition: MSNet.cpp:660
SimulationState
Possible states of a simulation - running or stopped with different reasons.
Definition: MSNet.h:94
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:196
The simulated network and simulation perfomer.
Definition: MSNet.h:89
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:67
SUMOLong myVehiclesMoved
The overall number of vehicle movements.
Definition: MSNet.h:577
ShapeContainer * myShapeContainer
A container for geometrical shapes;.
Definition: MSNet.h:554
std::pair< bool, NamedRTree > myLanesRTree
An RTree structure holding lane IDs.
Definition: MSNet.h:614
const MSLane & getLane() const
Returns the lane this bus stop is located at.
Definition: MSBusStop.cpp:59
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:687
static bool gCheck4Accidents
Definition: MSGlobals.h:76
#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:73
void prohibit(const std::vector< E * > &toProhibit)
long mySimStepBegin
The last simulation step begin, end and duration.
Definition: MSNet.h:571
static void close()
request termination of connection
The simulation does not contain further vehicles.
Definition: MSNet.h:100
unsigned int getLoadedVehicleNo() const
Returns the number of build vehicles.
An error occured during the simulation step.
Definition: MSNet.h:104
static void clear()
Clears the dictionary (delete all known routes, too)
Definition: MSRoute.cpp:159
void writeOutput()
Write netstate, summary and detector output.
Definition: MSNet.cpp:517
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:544
Representation of a vehicle.
Definition: SUMOVehicle.h:63
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:56
SUMORouteLoaderControl * myRouteLoaders
Route loader for dynamic loading of routes.
Definition: MSNet.h:523
void closeSimulation(SUMOTime start)
Closes the simulation (all files, connections, etc.)
Definition: MSNet.cpp:314
bool myLogStepNumber
Information whether the number of the simulation step shall be logged.
Definition: MSNet.h:568
A lane area vehicles can halt at.
Definition: MSBusStop.h:63
An output device that encapsulates an ofstream.
static void clear()
Clears the dictionary.
Definition: MSEdge.cpp:511
SUMOTime getTargetTime()
Definition: TraCIServer.h:80
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:263
static SUMOReal getTravelTime(const MSEdge *const e, const SUMOVehicle *const v, SUMOReal t)
Returns the travel time to pass an edge.
Definition: MSNet.cpp:136
MSDetectorControl * myDetectorControl
Controls detectors;.
Definition: MSNet.h:546
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:542
static void write(OutputDevice &of, SUMOTime timestep)
Produce a VTK output to use with Tools like ParaView.
Definition: MSVTKExport.cpp:57
The connection to a client was closed by the client.
Definition: MSNet.h:102
DijkstraRouterTT_ByProxi< MSEdge, SUMOVehicle, prohibited_withRestrictions< MSEdge, SUMOVehicle > > * myRouterTTDijkstra
Definition: MSNet.h:608
The simulation is running.
Definition: MSNet.h:96
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:629
MSBusStop * getBusStop(const std::string &id) const
Returns the named bus stop.
Definition: MSNet.cpp:693
static void cleanup()
properly deletes all trigger instances
Definition: MSTrigger.cpp:46
AStarRouterTT_ByProxi< MSEdge, SUMOVehicle, prohibited_withRestrictions< MSEdge, SUMOVehicle > > * myRouterTTAStar
Definition: MSNet.h:609
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:52
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:417
bool hasNonWaiting() const
checks whether any person is still engaged in walking / stopping
static MSVehicleTransfer * getInstance()
Returns the instance of this object.
static const std::string STAGE_MOVEMENTS
Definition: MSNet.h:619
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:600
static MSNet * myInstance
Unique instance of MSNet.
Definition: MSNet.h:520
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:504
bool myRouterTTInitialized
Definition: MSNet.h:607
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:452
MSJunctionControl * myJunctions
Controls junctions, realizes right-of-way rules;.
Definition: MSNet.h:540
virtual MSPersonControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:611
static void clear()
Clears the dictionary.
Definition: MSLane.cpp:852
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
static TraCIServer * getInstance()
Definition: TraCIServer.h:83
MSEventControl * myBeginOfTimestepEvents
Controls events executed at the begin of a time step;.
Definition: MSNet.h:548
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:556
MSNet(MSVehicleControl *vc, MSEventControl *beginOfTimestepEvents, MSEventControl *endOfTimestepEvents, MSEventControl *insertionEvents, ShapeContainer *shapeCont=0)
Constructor.
Definition: MSNet.cpp:162
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:712
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:677
const NamedRTree & getLanesRTree() const
Returns an RTree that contains lane IDs.
Definition: MSNet.cpp:750
static void cleanup()
cleanup remaining data structures
long mySimBeginMillis
The overall simulation duration.
Definition: MSNet.h:574
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:152
virtual ~MSNet()
Destructor.
Definition: MSNet.cpp:229
const std::vector< MSEdge * > & getEdges() const
Returns loaded edges.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
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:98
static std::string getStateMessage(SimulationState state)
Returns the message to show if a certain state occurs.
Definition: MSNet.cpp:483
SUMOReal getMinimumTravelTime(const SUMOVehicle *const veh) const
returns the minimum travel time for the given vehicle
Definition: MSEdge.h:312
bool logSimulationDuration() const
Returns whether duration shall be logged.
Definition: MSNet.cpp:605
#define DELTA_T
Definition: SUMOTime.h:50
SUMOTime myStep
Current time step.
Definition: MSNet.h:526
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:206
NamedObjectCont< MSBusStop * > myBusStopDict
Dictionary of bus stops.
Definition: MSNet.h:597
void simulationStep()
Performs a single simulation step.
Definition: MSNet.cpp:364
static long getCurrentMillis()
Returns the current time in milliseconds.
Definition: SysUtils.cpp:48
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:308
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:197
static const std::string STAGE_INSERTIONS
Definition: MSNet.h:621
MSEventControl * myInsertionEvents
Controls insertion events;.
Definition: MSNet.h:552
int myTooManyVehicles
Storage for maximum vehicle number.
Definition: MSNet.h:594
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:535
long mySimStepDuration
Definition: MSNet.h:571
static bool wasClosed()
check whether close was requested
Stores time-dependant events and executes them at the proper time.
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:58
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:620
DijkstraRouterEffort_ByProxi< MSEdge, SUMOVehicle, prohibited_withRestrictions< MSEdge, SUMOVehicle > > * myRouterEffort
Definition: MSNet.h:610
static const std::string STAGE_EVENTS
string constants for simstep stages
Definition: MSNet.h:618