SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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.dlr.de/
16 // Copyright (C) 2001-2015 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>
62 
63 
64 // ===========================================================================
65 // class declarations
66 // ===========================================================================
67 class MSEdge;
68 class MSJunction;
69 class MSEdgeControl;
70 class MSJunctionControl;
71 class MSInsertionControl;
73 class MSPersonControl;
74 class MSContainerControl;
75 class MSVehicle;
76 class MSRoute;
77 class MSLane;
78 class MSTLLogicControl;
79 class MSDetectorControl;
80 class ShapeContainer;
81 class BinaryInputDevice;
84 
85 typedef std::vector<MSEdge*> MSEdgeVector;
86 
87 // ===========================================================================
88 // class definitions
89 // ===========================================================================
94 class MSNet {
95 public:
112  };
113 
114  //typedef PedestrianRouterDijkstra<MSEdge, MSLane> MSPedestrianRouterDijkstra;
116 
117 
118 
119 public:
124  static MSNet* getInstance();
125 
126 
141  MSNet(MSVehicleControl* vc, MSEventControl* beginOfTimestepEvents,
142  MSEventControl* endOfTimestepEvents, MSEventControl* insertionEvents,
143  ShapeContainer* shapeCont = 0);
144 
145 
147  virtual ~MSNet();
148 
149 
162  void closeBuilding(MSEdgeControl* edges, MSJunctionControl* junctions,
163  SUMORouteLoaderControl* routeLoaders, MSTLLogicControl* tlc,
164  std::vector<SUMOTime> stateDumpTimes, std::vector<std::string> stateDumpFiles,
165  bool hasInternalLinks);
166 
167 
171  bool hasRestrictions() const {
172  return myHaveRestrictions;
173  }
174 
175 
178  myHaveRestrictions = true;
179  }
180 
181 
185  static void clearAll();
186 
187 
195  int simulate(SUMOTime start, SUMOTime stop);
196 
197 
201  void simulationStep();
202 
203 
205  void loadRoutes();
206 
207 
215  void closeSimulation(SUMOTime start);
216 
217 
223  SimulationState simulationState(SUMOTime stopTime) const;
224 
225 
229  static std::string getStateMessage(SimulationState state);
230 
231 
235  inline SUMOTime getCurrentTimeStep() const {
236  return myStep;
237  }
238 
239 
243  inline void setCurrentTimeStep(const SUMOTime step) {
244  myStep = step;
245  }
246 
247 
251  void writeOutput();
252 
253 
257  bool logSimulationDuration() const;
258 
259 
260 
262 
263 
268  void preSimStepOutput() const;
269 
270 
275  void postSimStepOutput() const;
276  //}
277 
278 
279 
282 
289  return *myVehicleControl;
290  }
291 
292 
302 
312 
313 
320  return *myEdges;
321  }
322 
323 
330  return *myInserter;
331  }
332 
333 
340  return *myDetectorControl;
341  }
342 
343 
350  return *myLogics;
351  }
352 
353 
360  return *myJunctions;
361  }
362 
363 
371  }
372 
373 
380  return myEndOfTimestepEvents;
381  }
382 
383 
390  return myInsertionEvents;
391  }
392 
393 
400  return *myShapeContainer;
401  }
402 
403 
411 
412 
413 
416 
428  bool addBusStop(MSBusStop* busStop);
429 
430 
435  MSBusStop* getBusStop(const std::string& id) const;
436 
437 
443  std::string getBusStopID(const MSLane* lane, const SUMOReal pos) const;
445 
446 
449 
461  bool addContainerStop(MSContainerStop* containerStop);
462 
467  MSContainerStop* getContainerStop(const std::string& id) const;
468 
474  std::string getContainerStopID(const MSLane* lane, const SUMOReal pos) const;
476 
477 
478 
481 
504  };
505 
506 
511  public:
514 
516  virtual ~VehicleStateListener() { }
517 
522  virtual void vehicleStateChanged(const SUMOVehicle* const vehicle, VehicleState to) = 0;
523 
524  };
525 
526 
530  void addVehicleStateListener(VehicleStateListener* listener);
531 
532 
536  void removeVehicleStateListener(VehicleStateListener* listener);
537 
538 
544  void informVehicleStateListener(const SUMOVehicle* const vehicle, VehicleState to);
546 
547 
548 
556  static SUMOReal getTravelTime(const MSEdge* const e, const SUMOVehicle* const v, SUMOReal t);
557 
558 
566  static SUMOReal getEffort(const MSEdge* const e, const SUMOVehicle* const v, SUMOReal t);
567 
568 
569  /* @brief get the router, initialize on first use
570  * @param[in] prohibited The vector of forbidden edges (optional)
571  */
573  const MSEdgeVector& prohibited = MSEdgeVector()) const;
575  const MSEdgeVector& prohibited = MSEdgeVector()) const;
576  MSPedestrianRouterDijkstra& getPedestrianRouter(const MSEdgeVector& prohibited = MSEdgeVector()) const;
577 
578 
582  const NamedRTree& getLanesRTree() const;
583 
585  bool hasInternalLinks() const {
586  return myHasInternalLinks;
587  }
588 
589 protected:
591  static MSNet* myInstance;
592 
595 
598 
599 
600 
603 
631 
632 
633 
636 
639 
642 
645 
648 
651  //}
652 
653 
654 
657 
659  std::vector<SUMOTime> myStateDumpTimes;
661  std::vector<std::string> myStateDumpFiles;
663 
664 
665 
668 
671 
674 
677 
680 
682  std::vector<VehicleStateListener*> myVehicleStateListeners;
683 
684 
685  /* @brief The router instance for routing by trigger and by traci
686  * @note MSDevice_Routing has its own instance since it uses a different weight function
687  * @note we provide one member for every switchable router type
688  * because the class structure makes it inconvenient to use a superclass*/
689  mutable bool myRouterTTInitialized;
693  mutable MSPedestrianRouterDijkstra* myPedestrianRouter;
694 
695 
697  mutable std::pair<bool, NamedRTree> myLanesRTree;
698 
699 
701  static const std::string STAGE_EVENTS;
702  static const std::string STAGE_MOVEMENTS;
703  static const std::string STAGE_LANECHANGE;
704  static const std::string STAGE_INSERTIONS;
705 
706 private:
708  MSNet(const MSNet&);
709 
711  MSNet& operator=(const MSNet&);
712 
713 
714 };
715 
716 
717 #endif
718 
719 /****************************************************************************/
720 
The vehicle has departed (was inserted into the network)
Definition: MSNet.h:487
Computes the shortest path through a network using the Dijkstra algorithm.
void postSimStepOutput() const
Prints the statistics of the step at its end.
Definition: MSNet.cpp:690
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
Interface for objects listening to vehicle state changes.
Definition: MSNet.h:510
long mySimStepEnd
Definition: MSNet.h:644
A lane area vehicles can halt at and load and unload containers.
void removeVehicleStateListener(VehicleStateListener *listener)
Removes a vehicle states listener.
Definition: MSNet.cpp:723
MSEventControl * myEndOfTimestepEvents
Controls events executed at the end of a time step;.
Definition: MSNet.h:623
static SUMOReal getEffort(const MSEdge *const e, const SUMOVehicle *const v, SUMOReal t)
Returns the effort to pass an edge.
Definition: MSNet.cpp:127
void setRestrictionFound()
Labels the network to contain vehicle class restrictions.
Definition: MSNet.h:177
The simulation contains too many vehicles (.
Definition: MSNet.h:111
MSVehicleControl * myVehicleControl
Controls vehicle building and deletion;.
Definition: MSNet.h:605
std::vector< MSEdge * > MSEdgeVector
Definition: MSNet.h:83
NamedObjectCont< MSContainerStop * > myContainerStopDict
Dictionary of container stops.
Definition: MSNet.h:679
std::vector< SUMOTime > myStateDumpTimes
Times at which a state shall be written.
Definition: MSNet.h:659
The base class for an intersection.
Definition: MSJunction.h:61
bool hasInternalLinks() const
return whether the network contains internal links
Definition: MSNet.h:585
PedestrianRouterDijkstra< MSEdge, MSLane, MSJunction > MSPedestrianRouterDijkstra
Definition: MSNet.h:115
std::string getContainerStopID(const MSLane *lane, const SUMOReal pos) const
Returns the container stop close to the given position.
Definition: MSNet.cpp:777
int simulate(SUMOTime start, SUMOTime stop)
Simulates from timestep start to stop.
Definition: MSNet.cpp:280
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's Named objects.
Definition: NamedRTree.h:72
Computes the shortest path through a network using the Dijkstra algorithm.
Definition: AStarRouter.h:71
MSPedestrianRouterDijkstra & getPedestrianRouter(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:828
MSPersonControl * myPersonControl
Controls person building and deletion;.
Definition: MSNet.h:607
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:159
MSEdgeControl * myEdges
Controls edges, performs vehicle movement;.
Definition: MSNet.h:611
void setCurrentTimeStep(const SUMOTime step)
Sets the current simulation step (used by state loading)
Definition: MSNet.h:243
The final simulation step has been performed.
Definition: MSNet.h:103
std::vector< std::string > myStateDumpFiles
The names for the state files.
Definition: MSNet.h:661
bool myLogExecutionTime
Information whether the simulation duration shall be logged.
Definition: MSNet.h:638
MSContainerStop * getContainerStop(const std::string &id) const
Returns the named container stop.
Definition: MSNet.cpp:772
Storage for geometrical objects.
static const std::string STAGE_LANECHANGE
Definition: MSNet.h:703
Detectors container; responsible for string and output generation.
A storage for edge travel times and efforts.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:235
std::string getBusStopID(const MSLane *lane, const SUMOReal pos) const
Returns the bus stop close to the given position.
Definition: MSNet.cpp:754
void addVehicleStateListener(VehicleStateListener *listener)
Adds a vehicle states listener.
Definition: MSNet.cpp:715
SimulationState
Possible states of a simulation - running or stopped with different reasons.
Definition: MSNet.h:99
MSPedestrianRouterDijkstra * myPedestrianRouter
Definition: MSNet.h:693
The simulated network and simulation perfomer.
Definition: MSNet.h:94
Computes the shortest path through a network using the Dijkstra algorithm.
SUMOLong myVehiclesMoved
The overall number of vehicle movements.
Definition: MSNet.h:650
DijkstraRouterTT< MSEdge, SUMOVehicle, prohibited_withRestrictions< MSEdge, SUMOVehicle > > * myRouterTTDijkstra
Definition: MSNet.h:690
ShapeContainer * myShapeContainer
A container for geometrical shapes;.
Definition: MSNet.h:627
std::pair< bool, NamedRTree > myLanesRTree
An RTree structure holding lane IDs.
Definition: MSNet.h:697
Container for junctions; performs operations on all stored junctions.
DijkstraRouterEffort< MSEdge, SUMOVehicle, prohibited_withRestrictions< MSEdge, SUMOVehicle > > * myRouterEffort
Definition: MSNet.h:692
bool addBusStop(MSBusStop *busStop)
Adds a bus stop.
Definition: MSNet.cpp:742
The vehicles starts to stop.
Definition: MSNet.h:501
A class that stores and controls tls and switching of their programs.
A road/street connecting two junctions.
Definition: MSEdge.h:81
long mySimStepBegin
The last simulation step begin, end and duration.
Definition: MSNet.h:644
The simulation does not contain further vehicles.
Definition: MSNet.h:105
An error occured during the simulation step.
Definition: MSNet.h:109
void closeBuilding(MSEdgeControl *edges, MSJunctionControl *junctions, SUMORouteLoaderControl *routeLoaders, MSTLLogicControl *tlc, std::vector< SUMOTime > stateDumpTimes, std::vector< std::string > stateDumpFiles, bool hasInternalLinks)
Closes the network's building process.
Definition: MSNet.cpp:215
void writeOutput()
Write netstate, summary and detector output.
Definition: MSNet.cpp:557
The vehicle got a new route.
Definition: MSNet.h:495
The vehicle arrived at his destination (is deleted)
Definition: MSNet.h:493
The vehicles starts to park.
Definition: MSNet.h:497
MSInsertionControl * myInserter
Controls vehicle insertion;.
Definition: MSNet.h:617
Representation of a vehicle.
Definition: SUMOVehicle.h:65
SUMORouteLoaderControl * myRouteLoaders
Route loader for dynamic loading of routes.
Definition: MSNet.h:594
ShapeContainer & getShapeContainer()
Returns the shapes container.
Definition: MSNet.h:399
void closeSimulation(SUMOTime start)
Closes the simulation (all files, connections, etc.)
Definition: MSNet.cpp:331
bool myLogStepNumber
Information whether the number of the simulation step shall be logged.
Definition: MSNet.h:641
MSTLLogicControl & getTLSControl()
Returns the tls logics control.
Definition: MSNet.h:349
A lane area vehicles can halt at.
Definition: MSBusStop.h:64
virtual MSContainerControl & getContainerControl()
Returns the container control.
Definition: MSNet.cpp:666
bool addContainerStop(MSContainerStop *containerStop)
Adds a container stop.
Definition: MSNet.cpp:767
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:288
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
Definition: MSNet.h:369
static SUMOReal getTravelTime(const MSEdge *const e, const SUMOVehicle *const v, SUMOReal t)
Returns the travel time to pass an edge.
Definition: MSNet.cpp:141
MSDetectorControl * myDetectorControl
Controls detectors;.
Definition: MSNet.h:619
Stores edges and lanes, performs moving of vehicle.
Definition: MSEdgeControl.h:74
MSTLLogicControl * myLogics
Controls tls logics, realizes waiting on tls rules;.
Definition: MSNet.h:615
The connection to a client was closed by the client.
Definition: MSNet.h:107
The simulation is running.
Definition: MSNet.h:101
MSNet & operator=(const MSNet &)
Invalidated assignment operator.
The vehicle started to teleport.
Definition: MSNet.h:489
#define SUMOLong
Definition: config.h:215
void preSimStepOutput() const
Prints the current step number.
Definition: MSNet.cpp:684
MSBusStop * getBusStop(const std::string &id) const
Returns the named bus stop.
Definition: MSNet.cpp:748
The vehicle ends to park.
Definition: MSNet.h:499
bool myHaveRestrictions
Whether the network contains edges which not all vehicles may pass.
Definition: MSNet.h:667
MSDetectorControl & getDetectorControl()
Returns the detector control.
Definition: MSNet.h:339
bool hasRestrictions() const
Returns whether the network has vehicle class restrictions.
Definition: MSNet.h:171
MSContainerControl * myContainerControl
Controls container building and deletion;.
Definition: MSNet.h:609
Inserts vehicles into the network when their departure time is reached.
VehicleState
Definition of a vehicle state.
Definition: MSNet.h:483
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:790
MSEventControl * getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
Definition: MSNet.h:379
static const std::string STAGE_MOVEMENTS
Definition: MSNet.h:702
VehicleStateListener()
Constructor.
Definition: MSNet.h:513
The vehicle was built, but has not yet departed.
Definition: MSNet.h:485
std::vector< VehicleStateListener * > myVehicleStateListeners
Container for vehicle state listener.
Definition: MSNet.h:682
static MSNet * myInstance
Unique instance of MSNet.
Definition: MSNet.h:591
static void clearAll()
Clears all dictionaries.
Definition: MSNet.cpp:541
bool myRouterTTInitialized
Definition: MSNet.h:689
SimulationState simulationState(SUMOTime stopTime) const
Called after a simulation step, this method returns the current simulation state. ...
Definition: MSNet.cpp:485
MSJunctionControl * myJunctions
Controls junctions, realizes right-of-way rules;.
Definition: MSNet.h:613
virtual MSPersonControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:658
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition: MSNet.h:329
MSEventControl * myBeginOfTimestepEvents
Controls events executed at the begin of a time step;.
Definition: MSNet.h:621
virtual ~VehicleStateListener()
Destructor.
Definition: MSNet.h:516
MSEdgeWeightsStorage * myEdgeWeights
The net's knowledge about edge efforts/travel times;.
Definition: MSNet.h:629
MSNet(MSVehicleControl *vc, MSEventControl *beginOfTimestepEvents, MSEventControl *endOfTimestepEvents, MSEventControl *insertionEvents, ShapeContainer *shapeCont=0)
Constructor.
Definition: MSNet.cpp:167
The vehicle ends to stop.
Definition: MSNet.h:503
int SUMOTime
Definition: SUMOTime.h:43
MSEventControl * getInsertionEvents()
Returns the event control for insertion events.
Definition: MSNet.h:389
void informVehicleStateListener(const SUMOVehicle *const vehicle, VehicleState to)
Informs all added listeners about a vehicle's state change.
Definition: MSNet.cpp:732
const NamedRTree & getLanesRTree() const
Returns an RTree that contains lane IDs.
Definition: MSNet.cpp:838
long mySimBeginMillis
The overall simulation duration.
Definition: MSNet.h:647
virtual ~MSNet()
Destructor.
Definition: MSNet.cpp:240
#define SUMOReal
Definition: config.h:218
static std::string getStateMessage(SimulationState state)
Returns the message to show if a certain state occurs.
Definition: MSNet.cpp:520
MSEdgeControl & getEdgeControl()
Returns the edge control.
Definition: MSNet.h:319
bool logSimulationDuration() const
Returns whether duration shall be logged.
Definition: MSNet.cpp:652
MSJunctionControl & getJunctionControl()
Returns the junctions control.
Definition: MSNet.h:359
AStarRouter< MSEdge, SUMOVehicle, prohibited_withRestrictions< MSEdge, SUMOVehicle > > * myRouterTTAStar
Definition: MSNet.h:691
SUMOTime myStep
Current time step.
Definition: MSNet.h:597
The class responsible for building and deletion of vehicles.
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:78
NamedObjectCont< MSBusStop * > myBusStopDict
Dictionary of bus stops.
Definition: MSNet.h:676
void simulationStep()
Performs a single simulation step.
Definition: MSNet.cpp:387
void loadRoutes()
loads routes for the next few steps
Definition: MSNet.cpp:325
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterEffort(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:817
static const std::string STAGE_INSERTIONS
Definition: MSNet.h:704
MSEventControl * myInsertionEvents
Controls insertion events;.
Definition: MSNet.h:625
int myTooManyVehicles
Storage for maximum vehicle number.
Definition: MSNet.h:673
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
long mySimStepDuration
Definition: MSNet.h:644
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:491
bool myHasInternalLinks
Whether the network contains internal links/lanes/edges.
Definition: MSNet.h:670
MSEdgeWeightsStorage & getWeightsStorage()
Returns the net's internal edge travel times/efforts container.
Definition: MSNet.cpp:675
static const std::string STAGE_EVENTS
string constants for simstep stages
Definition: MSNet.h:701