SUMO - Simulation of Urban MObility
MSNet.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
23 // The simulated network and simulation performer
24 /****************************************************************************/
25 #ifndef MSNet_h
26 #define MSNet_h
27 
28 
29 // ===========================================================================
30 // included modules
31 // ===========================================================================
32 #ifdef _MSC_VER
33 #include <windows_config.h>
34 #else
35 #include <config.h>
36 #endif
37 
38 #include <typeinfo>
39 #include <vector>
40 #include <map>
41 #include <string>
42 #include <fstream>
43 #include <iostream>
44 #include <cmath>
45 #include <iomanip>
46 #include <utils/common/SUMOTime.h>
54 #include "MSJunction.h"
55 #include "MSParkingArea.h"
56 #include "MSStoppingPlace.h"
57 
58 
59 // ===========================================================================
60 // class declarations
61 // ===========================================================================
62 class MSEdge;
63 class MSJunction;
64 class MSEdgeControl;
65 class MSEventControl;
66 class MSVehicleControl;
67 class MSJunctionControl;
68 class MSInsertionControl;
71 class MSVehicle;
72 class MSRoute;
73 class MSLane;
74 class MSTLLogicControl;
75 class MSDetectorControl;
76 class ShapeContainer;
77 class BinaryInputDevice;
80 
81 typedef std::vector<MSEdge*> MSEdgeVector;
82 
83 // ===========================================================================
84 // class definitions
85 // ===========================================================================
90 class MSNet {
91 public:
110  };
111 
112  //typedef PedestrianRouterDijkstra<MSEdge, MSLane> MSPedestrianRouterDijkstra;
115 
116 
117 public:
122  static MSNet* getInstance();
123 
124 
139  MSNet(MSVehicleControl* vc, MSEventControl* beginOfTimestepEvents,
140  MSEventControl* endOfTimestepEvents, MSEventControl* insertionEvents,
141  ShapeContainer* shapeCont = 0);
142 
143 
145  virtual ~MSNet();
146 
147 
163  void closeBuilding(const OptionsCont& oc, MSEdgeControl* edges, MSJunctionControl* junctions,
164  SUMORouteLoaderControl* routeLoaders, MSTLLogicControl* tlc,
165  std::vector<SUMOTime> stateDumpTimes, std::vector<std::string> stateDumpFiles,
166  bool hasInternalLinks, bool hasNeighs, bool lefthand,
167  double version);
168 
169 
173  bool hasPermissions() const {
174  return myHavePermissions;
175  }
176 
177 
180  myHavePermissions = true;
181  }
182 
183 
189  void addRestriction(const std::string& id, const SUMOVehicleClass svc, const double speed);
190 
191 
197  const std::map<SUMOVehicleClass, double>* getRestrictions(const std::string& id) const;
198 
199 
203  static void clearAll();
204 
205 
214 
215 
219  void simulationStep();
220 
221 
223  void loadRoutes();
224 
225 
233  void closeSimulation(SUMOTime start);
234 
235 
241  SimulationState simulationState(SUMOTime stopTime) const;
242 
243 
247  static std::string getStateMessage(SimulationState state);
248 
249 
253  inline SUMOTime getCurrentTimeStep() const {
254  return myStep;
255  }
256 
257 
261  inline void setCurrentTimeStep(const SUMOTime step) {
262  myStep = step;
263  }
264 
265 
269  void writeOutput();
270 
271 
275  bool logSimulationDuration() const;
276 
277 
278 
280 
281 
286  void preSimStepOutput() const;
287 
288 
293  void postSimStepOutput() const;
294  //}
295 
296 
297 
300 
307  return *myVehicleControl;
308  }
309 
310 
320 
323  bool hasPersons() const {
324  return myPersonControl != 0;
325  }
326 
336 
339  bool hasContainers() const {
340  return myContainerControl != 0;
341  }
342 
343 
350  return *myEdges;
351  }
352 
353 
360  return *myInserter;
361  }
362 
363 
370  return *myDetectorControl;
371  }
372 
373 
380  return *myLogics;
381  }
382 
383 
390  return *myJunctions;
391  }
392 
393 
401  }
402 
403 
410  return myEndOfTimestepEvents;
411  }
412 
413 
420  return myInsertionEvents;
421  }
422 
423 
430  return *myShapeContainer;
431  }
432 
440 
443 
454  bool addStoppingPlace(const SumoXMLTag category, MSStoppingPlace* stop);
455 
456 
462  MSStoppingPlace* getStoppingPlace(const std::string& id, const SumoXMLTag category) const;
463 
470  std::string getStoppingPlaceID(const MSLane* lane, const double pos, const SumoXMLTag category) const;
472 
473 
475  void writeChargingStationOutput() const;
476 
477 
480 
503  };
504 
505 
510  public:
513 
515  virtual ~VehicleStateListener() { }
516 
521  virtual void vehicleStateChanged(const SUMOVehicle* const vehicle, VehicleState to) = 0;
522 
523  };
524 
525 
530 
531 
536 
537 
543  void informVehicleStateListener(const SUMOVehicle* const vehicle, VehicleState to);
545 
546 
547 
555  static double getTravelTime(const MSEdge* const e, const SUMOVehicle* const v, double t);
556 
557 
565  static double getEffort(const MSEdge* const e, const SUMOVehicle* const v, double t);
566 
567 
568  /* @brief get the router, initialize on first use
569  * @param[in] prohibited The vector of forbidden edges (optional)
570  */
572  const MSEdgeVector& prohibited = MSEdgeVector()) const;
574  const MSEdgeVector& prohibited = MSEdgeVector()) const;
575  MSPedestrianRouterDijkstra& getPedestrianRouter(const MSEdgeVector& prohibited = MSEdgeVector()) const;
576  MSIntermodalRouter& getIntermodalRouter(const MSEdgeVector& prohibited = MSEdgeVector()) const;
577 
578  static void adaptIntermodalRouter(MSIntermodalRouter& router);
579 
580 
584  const NamedRTree& getLanesRTree() const;
585 
587  bool hasInternalLinks() const {
588  return myHasInternalLinks;
589  }
590 
592  bool hasElevation() const {
593  return myHasElevation;
594  }
595 
597  bool lefthand() const {
598  return myLefthand;
599  }
600 
602  double version() const {
603  return myVersion;
604  }
605 
606 protected:
608  bool checkElevation();
609 
611  int getHaltingVehicleNumber() const;
612 
614  std::pair<double, double> getVehicleMeanSpeeds() const;
615  double getVehicleMeanSpeed() const {
616  return getVehicleMeanSpeeds().first;
617  }
619  return getVehicleMeanSpeeds().second;
620  }
621 
622 protected:
624  static MSNet* myInstance;
625 
628 
631 
634 
635 
636 
639 
667 
668 
669 
672 
675 
678 
681 
684 
686  long long int myVehiclesMoved;
687  //}
688 
689 
690 
693 
695  std::vector<SUMOTime> myStateDumpTimes;
697  std::vector<std::string> myStateDumpFiles;
701  std::string myStateDumpPrefix;
702  std::string myStateDumpSuffix;
704 
705 
706 
709 
711  std::map<std::string, std::map<SUMOVehicleClass, double> > myRestrictions;
712 
715 
718 
721 
723  double myVersion;
724 
726  std::map<SumoXMLTag, NamedObjectCont<MSStoppingPlace*> > myStoppingPlaces;
727 
729  std::vector<VehicleStateListener*> myVehicleStateListeners;
730 
731 
732  /* @brief The router instance for routing by trigger and by traci
733  * @note MSDevice_Routing has its own instance since it uses a different weight function
734  * @note we provide one member for every switchable router type
735  * because the class structure makes it inconvenient to use a superclass*/
738  mutable MSPedestrianRouterDijkstra* myPedestrianRouter;
739  mutable MSIntermodalRouter* myIntermodalRouter;
740 
741 
743  mutable std::pair<bool, NamedRTree> myLanesRTree;
744 
745 
747  static const std::string STAGE_EVENTS;
748  static const std::string STAGE_MOVEMENTS;
749  static const std::string STAGE_LANECHANGE;
750  static const std::string STAGE_INSERTIONS;
751 
752 private:
754  MSNet(const MSNet&);
755 
757  MSNet& operator=(const MSNet&);
758 
759 
760 };
761 
762 
763 #endif
764 
765 /****************************************************************************/
766 
std::string myStateDumpSuffix
Definition: MSNet.h:702
The vehicle has departed (was inserted into the network)
Definition: MSNet.h:486
SumoXMLTag
Numbers representing SUMO-XML - element names.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
Interface for objects listening to vehicle state changes.
Definition: MSNet.h:509
bool hasPersons() const
Returns whether persons are simulated.
Definition: MSNet.h:323
void removeVehicleStateListener(VehicleStateListener *listener)
Removes a vehicle states listener.
Definition: MSNet.cpp:840
MSEventControl * myEndOfTimestepEvents
Controls events executed at the end of a time step;.
Definition: MSNet.h:659
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
MSStoppingPlace * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Returns the named stopping place of the given category.
Definition: MSNet.cpp:863
std::string getStoppingPlaceID(const MSLane *lane, const double pos, const SumoXMLTag category) const
Returns the stop of the given category close to the given position.
Definition: MSNet.cpp:872
A lane area vehicles can halt at.
bool hasPermissions() const
Returns whether the network has specific vehicle class permissions.
Definition: MSNet.h:173
const NamedRTree & getLanesRTree() const
Returns an RTree that contains lane IDs.
Definition: MSNet.cpp:976
std::pair< double, double > getVehicleMeanSpeeds() const
get current absolute and relative mean vehicle speed in the network
Definition: MSNet.cpp:1013
MSVehicleControl * myVehicleControl
Controls vehicle building and deletion;.
Definition: MSNet.h:641
std::vector< MSEdge * > MSEdgeVector
Definition: MSNet.h:79
double getVehicleMeanSpeed() const
Definition: MSNet.h:615
std::vector< SUMOTime > myStateDumpTimes
Times at which a state shall be written.
Definition: MSNet.h:695
The base class for an intersection.
Definition: MSJunction.h:64
SimulationState simulate(SUMOTime start, SUMOTime stop)
Simulates from timestep start to stop.
Definition: MSNet.cpp:313
SUMOAbstractRouter< MSEdge, SUMOVehicle > * myRouterEffort
Definition: MSNet.h:737
bool logSimulationDuration() const
Returns whether duration shall be logged.
Definition: MSNet.cpp:762
virtual void vehicleStateChanged(const SUMOVehicle *const vehicle, VehicleState to)=0
Called if a vehicle changes its state.
std::map< SumoXMLTag, NamedObjectCont< MSStoppingPlace * > > myStoppingPlaces
Dictionary of bus / container stops.
Definition: MSNet.h:726
A RT-tree for efficient storing of SUMO&#39;s Named objects.
Definition: NamedRTree.h:71
MSIntermodalRouter * myIntermodalRouter
Definition: MSNet.h:739
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
MSPedestrianRouterDijkstra & getPedestrianRouter(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:928
bool myHavePermissions
Whether the network contains edges which not all vehicles may pass.
Definition: MSNet.h:708
MSEdgeControl * myEdges
Controls edges, performs vehicle movement;.
Definition: MSNet.h:647
void setCurrentTimeStep(const SUMOTime step)
Sets the current simulation step (used by state loading)
Definition: MSNet.h:261
The final simulation step has been performed.
Definition: MSNet.h:101
MSIntermodalRouter & getIntermodalRouter(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:938
double myVersion
the network version
Definition: MSNet.h:723
std::vector< std::string > myStateDumpFiles
The names for the state files.
Definition: MSNet.h:697
bool myLogExecutionTime
Information whether the simulation duration shall be logged.
Definition: MSNet.h:674
Storage for geometrical objects.
static const std::string STAGE_LANECHANGE
Definition: MSNet.h:749
Detectors container; responsible for string and output generation.
bool myLefthand
Whether the network was built for left-hand traffic.
Definition: MSNet.h:720
A storage for edge travel times and efforts.
void addVehicleStateListener(VehicleStateListener *listener)
Adds a vehicle states listener.
Definition: MSNet.cpp:832
SimulationState
Possible states of a simulation - running or stopped with different reasons.
Definition: MSNet.h:95
bool addStoppingPlace(const SumoXMLTag category, MSStoppingPlace *stop)
Adds a stopping place.
Definition: MSNet.cpp:857
MSPedestrianRouterDijkstra * myPedestrianRouter
Definition: MSNet.h:738
The simulated network and simulation perfomer.
Definition: MSNet.h:90
ShapeContainer * myShapeContainer
A container for geometrical shapes;.
Definition: MSNet.h:663
std::pair< bool, NamedRTree > myLanesRTree
An RTree structure holding lane IDs.
Definition: MSNet.h:743
Container for junctions; performs operations on all stored junctions.
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition: MSNet.cpp:776
The vehicles starts to stop.
Definition: MSNet.h:500
void writeChargingStationOutput() const
write charging station output
Definition: MSNet.cpp:886
A class that stores and controls tls and switching of their programs.
A road/street connecting two junctions.
Definition: MSEdge.h:80
double version() const
return the network version
Definition: MSNet.h:602
long long int myVehiclesMoved
The overall number of vehicle movements.
Definition: MSNet.h:686
The simulation does not contain further vehicles.
Definition: MSNet.h:103
int getHaltingVehicleNumber() const
count number of standing vehicles in the network
Definition: MSNet.cpp:1000
An error occured during the simulation step.
Definition: MSNet.h:107
void writeOutput()
Write netstate, summary and detector output.
Definition: MSNet.cpp:645
The vehicle got a new route.
Definition: MSNet.h:494
The vehicle arrived at his destination (is deleted)
Definition: MSNet.h:492
The vehicles starts to park.
Definition: MSNet.h:496
SimulationState simulationState(SUMOTime stopTime) const
Called after a simulation step, this method returns the current simulation state. ...
Definition: MSNet.cpp:560
MSInsertionControl * myInserter
Controls vehicle insertion;.
Definition: MSNet.h:653
Representation of a vehicle.
Definition: SUMOVehicle.h:66
SUMORouteLoaderControl * myRouteLoaders
Route loader for dynamic loading of routes.
Definition: MSNet.h:627
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:768
static double getTravelTime(const MSEdge *const e, const SUMOVehicle *const v, double t)
Returns the travel time to pass an edge.
Definition: MSNet.cpp:150
ShapeContainer & getShapeContainer()
Returns the shapes container.
Definition: MSNet.h:429
void closeSimulation(SUMOTime start)
Closes the simulation (all files, connections, etc.)
Definition: MSNet.cpp:372
std::map< std::string, std::map< SUMOVehicleClass, double > > myRestrictions
The vehicle class specific speed restrictions.
Definition: MSNet.h:711
bool myLogStepNumber
Information whether the number of the simulation step shall be logged.
Definition: MSNet.h:677
MSTLLogicControl & getTLSControl()
Returns the tls logics control.
Definition: MSNet.h:379
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:306
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
Definition: MSNet.h:399
MSDetectorControl * myDetectorControl
Controls detectors;.
Definition: MSNet.h:655
void setPermissionsFound()
Labels the network to contain vehicle class permissions.
Definition: MSNet.h:179
void postSimStepOutput() const
Prints the statistics of the step at its end.
Definition: MSNet.cpp:800
bool hasContainers() const
Returns whether containers are simulated.
Definition: MSNet.h:339
Stores edges and lanes, performs moving of vehicle.
Definition: MSEdgeControl.h:73
const std::map< SUMOVehicleClass, double > * getRestrictions(const std::string &id) const
Returns the restrictions for an edge type If no restrictions are present, 0 is returned.
Definition: MSNet.cpp:303
MSTLLogicControl * myLogics
Controls tls logics, realizes waiting on tls rules;.
Definition: MSNet.h:651
The connection to a client was closed by the client.
Definition: MSNet.h:105
The simulation is running.
Definition: MSNet.h:99
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:253
void addRestriction(const std::string &id, const SUMOVehicleClass svc, const double speed)
Adds a restriction for an edge type.
Definition: MSNet.cpp:297
MSNet & operator=(const MSNet &)
Invalidated assignment operator.
The vehicle started to teleport.
Definition: MSNet.h:488
bool hasInternalLinks() const
return whether the network contains internal links
Definition: MSNet.h:587
PedestrianRouterDijkstra< MSEdge, MSLane, MSJunction, MSVehicle > MSPedestrianRouterDijkstra
Definition: MSNet.h:113
The vehicle ends to park.
Definition: MSNet.h:498
MSDetectorControl & getDetectorControl()
Returns the detector control.
Definition: MSNet.h:369
bool hasElevation() const
return whether the network contains elevation data
Definition: MSNet.h:592
bool lefthand() const
return whether the network was built for lefthand traffic
Definition: MSNet.h:597
SUMOTime myStateDumpPeriod
The period for writing state.
Definition: MSNet.h:699
Inserts vehicles into the network when their departure time is reached.
long myTraCIStepDuration
The last simulation step duration.
Definition: MSNet.h:680
int myMaxTeleports
Maximum number of teleports.
Definition: MSNet.h:633
VehicleState
Definition of a vehicle state.
Definition: MSNet.h:482
MSEventControl * getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
Definition: MSNet.h:409
void closeBuilding(const OptionsCont &oc, MSEdgeControl *edges, MSJunctionControl *junctions, SUMORouteLoaderControl *routeLoaders, MSTLLogicControl *tlc, std::vector< SUMOTime > stateDumpTimes, std::vector< std::string > stateDumpFiles, bool hasInternalLinks, bool hasNeighs, bool lefthand, double version)
Closes the network&#39;s building process.
Definition: MSNet.cpp:219
static const std::string STAGE_MOVEMENTS
Definition: MSNet.h:748
VehicleStateListener()
Constructor.
Definition: MSNet.h:512
The vehicle was built, but has not yet departed.
Definition: MSNet.h:484
std::vector< VehicleStateListener * > myVehicleStateListeners
Container for vehicle state listener.
Definition: MSNet.h:729
static MSNet * myInstance
Unique instance of MSNet.
Definition: MSNet.h:624
static void clearAll()
Clears all dictionaries.
Definition: MSNet.cpp:621
The simulation is loading.
Definition: MSNet.h:97
MSTransportableControl * myContainerControl
Controls container building and deletion;.
Definition: MSNet.h:645
MSJunctionControl * myJunctions
Controls junctions, realizes right-of-way rules;.
Definition: MSNet.h:649
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition: MSNet.h:359
MSTransportableControl * myPersonControl
Controls person building and deletion;.
Definition: MSNet.h:643
bool checkElevation()
check all lanes for elevation data
Definition: MSNet.cpp:986
void preSimStepOutput() const
Prints the current step number.
Definition: MSNet.cpp:794
MSEventControl * myBeginOfTimestepEvents
Controls events executed at the begin of a time step;.
Definition: MSNet.h:657
A storage for options typed value containers)
Definition: OptionsCont.h:98
virtual ~VehicleStateListener()
Destructor.
Definition: MSNet.h:515
MSEdgeWeightsStorage * myEdgeWeights
The net&#39;s knowledge about edge efforts/travel times;.
Definition: MSNet.h:665
The simulation had too many teleports.
Definition: MSNet.h:109
MSNet(MSVehicleControl *vc, MSEventControl *beginOfTimestepEvents, MSEventControl *endOfTimestepEvents, MSEventControl *insertionEvents, ShapeContainer *shapeCont=0)
Constructor.
Definition: MSNet.cpp:175
The vehicle ends to stop.
Definition: MSNet.h:502
MSEventControl * getInsertionEvents()
Returns the event control for insertion events.
Definition: MSNet.h:419
void informVehicleStateListener(const SUMOVehicle *const vehicle, VehicleState to)
Informs all added listeners about a vehicle&#39;s state change.
Definition: MSNet.cpp:849
long mySimBeginMillis
The overall simulation duration.
Definition: MSNet.h:683
virtual ~MSNet()
Destructor.
Definition: MSNet.cpp:256
bool myHasElevation
Whether the network contains elevation data.
Definition: MSNet.h:717
std::string myStateDumpPrefix
name components for periodic state
Definition: MSNet.h:701
static std::string getStateMessage(SimulationState state)
Returns the message to show if a certain state occurs.
Definition: MSNet.cpp:598
MSEdgeControl & getEdgeControl()
Returns the edge control.
Definition: MSNet.h:349
long long int SUMOTime
Definition: TraCIDefs.h:51
IntermodalRouter< MSEdge, MSLane, MSJunction, SUMOVehicle > MSIntermodalRouter
Definition: MSNet.h:114
MSJunctionControl & getJunctionControl()
Returns the junctions control.
Definition: MSNet.h:389
double getVehicleMeanSpeedRelative() const
Definition: MSNet.h:618
SUMOTime myStep
Current time step.
Definition: MSNet.h:630
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:897
The class responsible for building and deletion of vehicles.
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:77
void simulationStep()
Performs a single simulation step.
Definition: MSNet.cpp:439
void loadRoutes()
loads routes for the next few steps
Definition: MSNet.cpp:366
static const std::string STAGE_INSERTIONS
Definition: MSNet.h:750
MSEventControl * myInsertionEvents
Controls insertion events;.
Definition: MSNet.h:661
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
long mySimStepDuration
Definition: MSNet.h:680
Encapsulates binary reading operations on a file.
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterEffort(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:917
Stores time-dependant events and executes them at the proper time.
The vehicle ended being teleported.
Definition: MSNet.h:490
bool myHasInternalLinks
Whether the network contains internal links/lanes/edges.
Definition: MSNet.h:714
SUMOAbstractRouter< MSEdge, SUMOVehicle > * myRouterTT
Definition: MSNet.h:736
static void adaptIntermodalRouter(MSIntermodalRouter &router)
Definition: MSNet.cpp:958
static double getEffort(const MSEdge *const e, const SUMOVehicle *const v, double t)
Returns the effort to pass an edge.
Definition: MSNet.cpp:136
MSEdgeWeightsStorage & getWeightsStorage()
Returns the net&#39;s internal edge travel times/efforts container.
Definition: MSNet.cpp:785
static const std::string STAGE_EVENTS
string constants for simstep stages
Definition: MSNet.h:747