SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSNet.h
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-2013 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 #ifndef MSNet_h
27 #define MSNet_h
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 <typeinfo>
40 #include <vector>
41 #include <map>
42 #include <string>
43 #include <fstream>
44 #include <iostream>
45 #include <cmath>
46 #include <iomanip>
47 #include "MSVehicleControl.h"
48 #include "MSEventControl.h"
49 #include <utils/geom/Boundary.h>
50 #include <utils/geom/Position.h>
51 #include <utils/common/SUMOTime.h>
60 
61 
62 // ===========================================================================
63 // class declarations
64 // ===========================================================================
65 class MSEdge;
66 class MSEdgeControl;
67 class MSJunctionControl;
68 class MSInsertionControl;
70 class MSPersonControl;
71 class MSVehicle;
72 class MSRoute;
73 class MSLane;
74 class MSTLLogicControl;
75 class MSDetectorControl;
76 class ShapeContainer;
77 class BinaryInputDevice;
79 class SUMOVehicle;
80 
81 
82 // ===========================================================================
83 // class definitions
84 // ===========================================================================
89 class MSNet {
90 public:
107  };
108 
109 
110 public:
115  static MSNet* getInstance();
116 
117 
132  MSNet(MSVehicleControl* vc, MSEventControl* beginOfTimestepEvents,
133  MSEventControl* endOfTimestepEvents, MSEventControl* insertionEvents,
134  ShapeContainer* shapeCont = 0);
135 
136 
138  virtual ~MSNet();
139 
140 
152  void closeBuilding(MSEdgeControl* edges, MSJunctionControl* junctions,
153  SUMORouteLoaderControl* routeLoaders, MSTLLogicControl* tlc,
154  std::vector<SUMOTime> stateDumpTimes, std::vector<std::string> stateDumpFiles);
155 
156 
160  static void clearAll();
161 
162 
170  int simulate(SUMOTime start, SUMOTime stop);
171 
172 
176  void simulationStep();
177 
178 
180  void loadRoutes();
181 
182 
190  void closeSimulation(SUMOTime start);
191 
192 
198  SimulationState simulationState(SUMOTime stopTime) const;
199 
200 
204  static std::string getStateMessage(SimulationState state);
205 
206 
211 
212 
216  void writeOutput();
217 
218 
222  bool logSimulationDuration() const;
223 
224 
225 
227 
228 
233  void preSimStepOutput() const;
234 
235 
240  void postSimStepOutput() const;
241  //}
242 
243 
244 
247 
254  return *myVehicleControl;
255  }
256 
257 
267 
268 
275  return *myEdges;
276  }
277 
278 
285  return *myInserter;
286  }
287 
288 
295  return *myDetectorControl;
296  }
297 
298 
305  return *myLogics;
306  }
307 
308 
315  return *myJunctions;
316  }
317 
318 
325  return *myBeginOfTimestepEvents;
326  }
327 
328 
335  return *myEndOfTimestepEvents;
336  }
337 
338 
345  return *myInsertionEvents;
346  }
347 
348 
355  return *myShapeContainer;
356  }
357 
358 
366 
367 
368 
371 
383  bool addBusStop(MSBusStop* busStop);
384 
385 
390  MSBusStop* getBusStop(const std::string& id) const;
391 
392 
398  std::string getBusStopID(const MSLane* lane, const SUMOReal pos) const;
400 
401 
402 
405 
428  };
429 
430 
435  public:
438 
440  virtual ~VehicleStateListener() { }
441 
446  virtual void vehicleStateChanged(const SUMOVehicle* const vehicle, VehicleState to) = 0;
447 
448  };
449 
450 
454  void addVehicleStateListener(VehicleStateListener* listener);
455 
456 
460  void removeVehicleStateListener(VehicleStateListener* listener);
461 
462 
468  void informVehicleStateListener(const SUMOVehicle* const vehicle, VehicleState to);
470 
471 
472 
480  static SUMOReal getTravelTime(const MSEdge* const e, const SUMOVehicle* const v, SUMOReal t);
481 
482 
490  static SUMOReal getEffort(const MSEdge* const e, const SUMOVehicle* const v, SUMOReal t);
491 
492 
493  /* @brief get the router, initialize on first use
494  * @param[in] prohibited The vector of forbidden edges (optional)
495  */
497  const std::vector<MSEdge*>& prohibited = std::vector<MSEdge*>()) const;
499  const std::vector<MSEdge*>& prohibited = std::vector<MSEdge*>()) const;
500 
501 
505  const NamedRTree& getLanesRTree() const;
506 
507 
508 protected:
510  static MSNet* myInstance;
511 
514 
517 
518 
519 
522 
548 
549 
550 
553 
556 
559 
562 
565 
568  //}
569 
570 
571 
574 
576  std::vector<SUMOTime> myStateDumpTimes;
578  std::vector<std::string> myStateDumpFiles;
580 
581 
582 
585 
588 
590  std::vector<VehicleStateListener*> myVehicleStateListeners;
591 
592 
593  /* @brief The router instance for routing by trigger and by traci
594  * @note MSDevice_Routing has its own instance since it uses a different weight function
595  * @note we provide one member for every switchable router type
596  * because the class structure makes it inconvenient to use a superclass*/
597  mutable bool myRouterTTInitialized;
601 
602 
604  mutable std::pair<bool, NamedRTree> myLanesRTree;
605 
606 
607 private:
609  MSNet(const MSNet&);
610 
612  MSNet& operator=(const MSNet&);
613 
614 
615 };
616 
617 
618 #endif
619 
620 /****************************************************************************/
621 
The vehicle has departed (was inserted into the network)
Definition: MSNet.h:411
void postSimStepOutput() const
Prints the statistics of the step at its end.
Definition: MSNet.cpp:626
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
Interface for objects listening to vehicle state changes.
Definition: MSNet.h:434
long mySimStepEnd
Definition: MSNet.h:561
void removeVehicleStateListener(VehicleStateListener *listener)
Removes a vehicle states listener.
Definition: MSNet.cpp:659
MSEventControl * myEndOfTimestepEvents
Controls events executed at the end of a time step;.
Definition: MSNet.h:540
static SUMOReal getEffort(const MSEdge *const e, const SUMOVehicle *const v, SUMOReal t)
Returns the effort to pass an edge.
Definition: MSNet.cpp:118
The simulation contains too many vehicles (.
Definition: MSNet.h:106
MSEventControl & getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
Definition: MSNet.h:334
MSVehicleControl * myVehicleControl
Controls vehicle building and deletion;.
Definition: MSNet.h:524
std::vector< SUMOTime > myStateDumpTimes
Times at which a state shall be written.
Definition: MSNet.h:576
int simulate(SUMOTime start, SUMOTime stop)
Simulates from timestep start to stop.
Definition: MSNet.cpp:259
virtual void vehicleStateChanged(const SUMOVehicle *const vehicle, VehicleState to)=0
Called if a vehicle changes its state.
A RT-tree for efficient storing of SUMO&#39;s Named objects.
Definition: NamedRTree.h:60
MSPersonControl * myPersonControl
Controls person building and deletion;.
Definition: MSNet.h:526
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:150
MSEdgeControl * myEdges
Controls edges, performs vehicle movement;.
Definition: MSNet.h:528
The final simulation step has been performed.
Definition: MSNet.h:98
std::vector< std::string > myStateDumpFiles
The names for the state files.
Definition: MSNet.h:578
bool myLogExecutionTime
Information whether the simulation duration shall be logged.
Definition: MSNet.h:555
Storage for geometrical objects.
Detectors container; responsible for string and output generation.
A storage for edge travel times and efforts.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step (in s)
Definition: MSNet.cpp:502
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterEffort(const std::vector< MSEdge * > &prohibited=std::vector< MSEdge * >()) const
Definition: MSNet.cpp:730
std::string getBusStopID(const MSLane *lane, const SUMOReal pos) const
Returns the bus stop close to the given position.
Definition: MSNet.cpp:690
void addVehicleStateListener(VehicleStateListener *listener)
Adds a vehicle states listener.
Definition: MSNet.cpp:651
SimulationState
Possible states of a simulation - running or stopped with different reasons.
Definition: MSNet.h:94
The simulated network and simulation perfomer.
Definition: MSNet.h:89
SUMOLong myVehiclesMoved
The overall number of vehicle movements.
Definition: MSNet.h:567
ShapeContainer * myShapeContainer
A container for geometrical shapes;.
Definition: MSNet.h:544
std::pair< bool, NamedRTree > myLanesRTree
An RTree structure holding lane IDs.
Definition: MSNet.h:604
Container for junctions; performs operations on all stored junctions.
bool addBusStop(MSBusStop *busStop)
Adds a bus stop.
Definition: MSNet.cpp:678
The vehicles starts to stop.
Definition: MSNet.h:425
A class that stores and controls tls and switching of their programs.
A road/street connecting two junctions.
Definition: MSEdge.h:73
long mySimStepBegin
The last simulation step begin, end and duration.
Definition: MSNet.h:561
The simulation does not contain further vehicles.
Definition: MSNet.h:100
An error occured during the simulation step.
Definition: MSNet.h:104
void writeOutput()
Write netstate, summary and detector output.
Definition: MSNet.cpp:508
The vehicle got a new route.
Definition: MSNet.h:419
The vehicle arrived at his destination (is deleted)
Definition: MSNet.h:417
The vehicles starts to park.
Definition: MSNet.h:421
MSInsertionControl * myInserter
Controls vehicle insertion;.
Definition: MSNet.h:534
Representation of a vehicle.
Definition: SUMOVehicle.h:63
SUMORouteLoaderControl * myRouteLoaders
Route loader for dynamic loading of routes.
Definition: MSNet.h:513
ShapeContainer & getShapeContainer()
Returns the shapes container.
Definition: MSNet.h:354
void closeSimulation(SUMOTime start)
Closes the simulation (all files, connections, etc.)
Definition: MSNet.cpp:310
bool myLogStepNumber
Information whether the number of the simulation step shall be logged.
Definition: MSNet.h:558
MSTLLogicControl & getTLSControl()
Returns the tls logics control.
Definition: MSNet.h:304
A lane area vehicles can halt at.
Definition: MSBusStop.h:63
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:253
static SUMOReal getTravelTime(const MSEdge *const e, const SUMOVehicle *const v, SUMOReal t)
Returns the travel time to pass an edge.
Definition: MSNet.cpp:132
MSDetectorControl * myDetectorControl
Controls detectors;.
Definition: MSNet.h:536
Stores edges and lanes, performs moving of vehicle.
Definition: MSEdgeControl.h:73
MSTLLogicControl * myLogics
Controls tls logics, realizes waiting on tls rules;.
Definition: MSNet.h:532
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:598
The simulation is running.
Definition: MSNet.h:96
MSNet & operator=(const MSNet &)
Invalidated assignment operator.
The vehicle started to teleport.
Definition: MSNet.h:413
#define SUMOLong
Definition: config.h:212
void preSimStepOutput() const
Prints the current step number.
Definition: MSNet.cpp:620
MSBusStop * getBusStop(const std::string &id) const
Returns the named bus stop.
Definition: MSNet.cpp:684
The vehicle ends to park.
Definition: MSNet.h:423
AStarRouterTT_ByProxi< MSEdge, SUMOVehicle, prohibited_withRestrictions< MSEdge, SUMOVehicle > > * myRouterTTAStar
Definition: MSNet.h:599
MSDetectorControl & getDetectorControl()
Returns the detector control.
Definition: MSNet.h:294
Inserts vehicles into the network when their departure time is reached.
VehicleState
Definition of a vehicle state.
Definition: MSNet.h:407
VehicleStateListener()
Constructor.
Definition: MSNet.h:437
The vehicle was built, but has not yet departed.
Definition: MSNet.h:409
std::vector< VehicleStateListener * > myVehicleStateListeners
Container for vehicle state listener.
Definition: MSNet.h:590
static MSNet * myInstance
Unique instance of MSNet.
Definition: MSNet.h:510
MSEventControl & getInsertionEvents()
Returns the event control for insertion events.
Definition: MSNet.h:344
static void clearAll()
Clears all dictionaries.
Definition: MSNet.cpp:489
bool myRouterTTInitialized
Definition: MSNet.h:597
SimulationState simulationState(SUMOTime stopTime) const
Called after a simulation step, this method returns the current simulation state. ...
Definition: MSNet.cpp:437
MSJunctionControl * myJunctions
Controls junctions, realizes right-of-way rules;.
Definition: MSNet.h:530
virtual MSPersonControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:602
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition: MSNet.h:284
MSEventControl * myBeginOfTimestepEvents
Controls events executed at the begin of a time step;.
Definition: MSNet.h:538
virtual ~VehicleStateListener()
Destructor.
Definition: MSNet.h:440
MSEdgeWeightsStorage * myEdgeWeights
The net&#39;s knowledge about edge efforts/travel times;.
Definition: MSNet.h:546
MSNet(MSVehicleControl *vc, MSEventControl *beginOfTimestepEvents, MSEventControl *endOfTimestepEvents, MSEventControl *insertionEvents, ShapeContainer *shapeCont=0)
Constructor.
Definition: MSNet.cpp:158
The vehicle ends to stop.
Definition: MSNet.h:427
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const std::vector< MSEdge * > &prohibited=std::vector< MSEdge * >()) const
Definition: MSNet.cpp:703
int SUMOTime
Definition: SUMOTime.h:43
void informVehicleStateListener(const SUMOVehicle *const vehicle, VehicleState to)
Informs all added listeners about a vehicle&#39;s state change.
Definition: MSNet.cpp:668
const NamedRTree & getLanesRTree() const
Returns an RTree that contains lane IDs.
Definition: MSNet.cpp:741
long mySimBeginMillis
The overall simulation duration.
Definition: MSNet.h:564
virtual ~MSNet()
Destructor.
Definition: MSNet.cpp:225
#define SUMOReal
Definition: config.h:215
static std::string getStateMessage(SimulationState state)
Returns the message to show if a certain state occurs.
Definition: MSNet.cpp:468
MSEdgeControl & getEdgeControl()
Returns the edge control.
Definition: MSNet.h:274
bool logSimulationDuration() const
Returns whether duration shall be logged.
Definition: MSNet.cpp:596
MSJunctionControl & getJunctionControl()
Returns the junctions control.
Definition: MSNet.h:314
SUMOTime myStep
Current time step.
Definition: MSNet.h:516
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:202
NamedObjectCont< MSBusStop * > myBusStopDict
Dictionary of bus stops.
Definition: MSNet.h:587
void simulationStep()
Performs a single simulation step.
Definition: MSNet.cpp:349
MSEventControl & getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
Definition: MSNet.h:324
void loadRoutes()
loads routes for the next few steps
Definition: MSNet.cpp:304
MSEventControl * myInsertionEvents
Controls insertion events;.
Definition: MSNet.h:542
int myTooManyVehicles
Storage for maximum vehicle number.
Definition: MSNet.h:584
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
long mySimStepDuration
Definition: MSNet.h:561
Encapsulates binary reading operations on a file.
Stores time-dependant events and executes them at the proper time.
The vehicle ended being teleported.
Definition: MSNet.h:415
MSEdgeWeightsStorage & getWeightsStorage()
Returns the net&#39;s internal edge travel times/efforts container.
Definition: MSNet.cpp:611
DijkstraRouterEffort_ByProxi< MSEdge, SUMOVehicle, prohibited_withRestrictions< MSEdge, SUMOVehicle > > * myRouterEffort
Definition: MSNet.h:600