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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
21 // The simulated network and simulation performer
22 /****************************************************************************/
23 #ifndef MSNet_h
24 #define MSNet_h
25 
26 
27 // ===========================================================================
28 // included modules
29 // ===========================================================================
30 #include <config.h>
31 
32 #include <typeinfo>
33 #include <vector>
34 #include <map>
35 #include <string>
36 #include <fstream>
37 #include <iostream>
38 #include <cmath>
39 #include <iomanip>
40 #include <utils/common/SUMOTime.h>
46 #include "MSJunction.h"
47 
48 
49 // ===========================================================================
50 // class declarations
51 // ===========================================================================
52 class MSEdge;
53 class MSEdgeControl;
54 class MSEventControl;
55 class MSVehicleControl;
56 class MSJunctionControl;
57 class MSInsertionControl;
60 class MSVehicle;
61 class MSRoute;
62 class MSLane;
63 class MSTLLogicControl;
65 class MSDetectorControl;
66 class ShapeContainer;
67 class BinaryInputDevice;
69 class SUMOVehicle;
70 class MSStoppingPlace;
71 template<class E, class L, class N, class V>
73 template<class E, class L, class N, class V>
75 
76 
77 // ===========================================================================
78 // class definitions
79 // ===========================================================================
84 class MSNet {
85 public:
106  };
107 
110 
111 
112 public:
117  static MSNet* getInstance();
118 
119 
123  static bool hasInstance() {
124  return myInstance != nullptr;
125  }
126 
127 
142  MSNet(MSVehicleControl* vc, MSEventControl* beginOfTimestepEvents,
143  MSEventControl* endOfTimestepEvents,
144  MSEventControl* insertionEvents,
145  ShapeContainer* shapeCont = 0);
146 
147 
149  virtual ~MSNet();
150 
151 
167  void closeBuilding(const OptionsCont& oc, MSEdgeControl* edges, MSJunctionControl* junctions,
168  SUMORouteLoaderControl* routeLoaders, MSTLLogicControl* tlc,
169  std::vector<SUMOTime> stateDumpTimes, std::vector<std::string> stateDumpFiles,
170  bool hasInternalLinks, bool hasNeighs, bool lefthand,
171  double version);
172 
173 
177  bool hasPermissions() const {
178  return myHavePermissions;
179  }
180 
181 
184  myHavePermissions = true;
185  }
186 
187 
193  void addRestriction(const std::string& id, const SUMOVehicleClass svc, const double speed);
194 
195 
201  const std::map<SUMOVehicleClass, double>* getRestrictions(const std::string& id) const;
202 
203 
207  static void clearAll();
208 
209 
218 
219 
223  void simulationStep();
224 
225 
227  void loadRoutes();
228 
229 
234  const std::string generateStatistics(SUMOTime start);
235 
236 
243  void closeSimulation(SUMOTime start);
244 
245 
251  SimulationState simulationState(SUMOTime stopTime) const;
252 
253 
257  static std::string getStateMessage(SimulationState state);
258 
259 
263  inline SUMOTime getCurrentTimeStep() const {
264  return myStep;
265  }
266 
267 
271  inline void setCurrentTimeStep(const SUMOTime step) {
272  myStep = step;
273  }
274 
275 
279  void writeOutput();
280 
281 
285  bool logSimulationDuration() const;
286 
287 
288 
290 
291 
296  void preSimStepOutput() const;
297 
298 
303  void postSimStepOutput() const;
304  //}
305 
306 
307 
310 
317  return *myVehicleControl;
318  }
319 
320 
330 
333  bool hasPersons() const {
334  return myPersonControl != 0;
335  }
336 
346 
349  bool hasContainers() const {
350  return myContainerControl != 0;
351  }
352 
353 
360  return *myEdges;
361  }
362 
363 
370  return *myInserter;
371  }
372 
373 
380  return *myDetectorControl;
381  }
382 
383 
390  return *myLogics;
391  }
392 
393 
400  return *myJunctions;
401  }
402 
403 
411  }
412 
413 
420  return myEndOfTimestepEvents;
421  }
422 
423 
430  return myInsertionEvents;
431  }
432 
433 
440  return *myShapeContainer;
441  }
442 
450 
453 
464  bool addStoppingPlace(const SumoXMLTag category, MSStoppingPlace* stop);
465 
466 
472  MSStoppingPlace* getStoppingPlace(const std::string& id, const SumoXMLTag category) const;
473 
480  std::string getStoppingPlaceID(const MSLane* lane, const double pos, const SumoXMLTag category) const;
482 
483 
485  void writeChargingStationOutput() const;
486 
489 
492 
519  };
520 
521 
526  public:
529 
531  virtual ~VehicleStateListener() { }
532 
538  virtual void vehicleStateChanged(const SUMOVehicle* const vehicle, VehicleState to, const std::string& info = "") = 0;
539 
540  };
541 
542 
547 
548 
553 
554 
561  void informVehicleStateListener(const SUMOVehicle* const vehicle, VehicleState to, const std::string& info = "");
563 
564 
565 
573  static double getTravelTime(const MSEdge* const e, const SUMOVehicle* const v, double t);
574 
575 
583  static double getEffort(const MSEdge* const e, const SUMOVehicle* const v, double t);
584 
585 
586  /* @brief get the router, initialize on first use
587  * @param[in] prohibited The vector of forbidden edges (optional)
588  */
590  const MSEdgeVector& prohibited = MSEdgeVector()) const;
592  const MSEdgeVector& prohibited = MSEdgeVector()) const;
593  MSPedestrianRouter& getPedestrianRouter(const MSEdgeVector& prohibited = MSEdgeVector()) const;
594  MSIntermodalRouter& getIntermodalRouter(const int routingMode = 0, const MSEdgeVector& prohibited = MSEdgeVector()) const;
595 
596  static void adaptIntermodalRouter(MSIntermodalRouter& router);
597 
598 
602  const NamedRTree& getLanesRTree() const;
603 
605  bool hasInternalLinks() const {
606  return myHasInternalLinks;
607  }
608 
610  bool hasElevation() const {
611  return myHasElevation;
612  }
613 
615  bool lefthand() const {
616  return myLefthand;
617  }
618 
620  double getNetworkVersion() const {
621  return myVersion;
622  }
623 
625  bool warnOnce(const std::string& typeAndID);
626 
627  void interrupt() {
628  myAmInterrupted = true;
629  }
630 
631  bool isInterrupted() const {
632  return myAmInterrupted;
633  }
634 
635 protected:
637  bool checkElevation();
638 
639 
640 protected:
642  static MSNet* myInstance;
643 
646 
649 
652 
655 
656 
657 
660 
688 
689 
690 
693 
696 
699 
702 
705 
707  long long int myVehiclesMoved;
708  //}
709 
710 
711 
714 
716  std::vector<SUMOTime> myStateDumpTimes;
718  std::vector<std::string> myStateDumpFiles;
722  std::string myStateDumpPrefix;
723  std::string myStateDumpSuffix;
725 
726 
727 
730 
732  std::map<std::string, std::map<SUMOVehicleClass, double> > myRestrictions;
733 
736 
739 
742 
744  double myVersion;
745 
747  std::map<SumoXMLTag, NamedObjectCont<MSStoppingPlace*> > myStoppingPlaces;
748 
750  std::vector<VehicleStateListener*> myVehicleStateListeners;
751 
753  std::map<std::string, bool> myWarnedOnce;
754 
755  /* @brief The router instance for routing by trigger and by traci
756  * @note MSDevice_Routing has its own instance since it uses a different weight function
757  * @note we provide one member for every switchable router type
758  * because the class structure makes it inconvenient to use a superclass*/
761  mutable MSPedestrianRouter* myPedestrianRouter;
762  mutable std::map<int, MSIntermodalRouter*> myIntermodalRouter;
763 
764 
766  mutable std::pair<bool, NamedRTree> myLanesRTree;
767 
768 
770  static const std::string STAGE_EVENTS;
771  static const std::string STAGE_MOVEMENTS;
772  static const std::string STAGE_LANECHANGE;
773  static const std::string STAGE_INSERTIONS;
774 
775 private:
777  MSNet(const MSNet&);
778 
780  MSNet& operator=(const MSNet&);
781 
782 
783 };
784 
785 
786 #endif
787 
788 /****************************************************************************/
789 
std::string myStateDumpSuffix
Definition: MSNet.h:723
The vehicle has departed (was inserted into the network)
Definition: MSNet.h:498
SumoXMLTag
Numbers representing SUMO-XML - element names.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79
long long int SUMOTime
Definition: SUMOTime.h:36
Interface for objects listening to vehicle state changes.
Definition: MSNet.h:525
bool hasPersons() const
Returns whether persons are simulated.
Definition: MSNet.h:333
void informVehicleStateListener(const SUMOVehicle *const vehicle, VehicleState to, const std::string &info="")
Informs all added listeners about a vehicle&#39;s state change.
Definition: MSNet.cpp:855
void removeVehicleStateListener(VehicleStateListener *listener)
Removes a vehicle states listener.
Definition: MSNet.cpp:846
MSPedestrianRouter * myPedestrianRouter
Definition: MSNet.h:761
MSEventControl * myEndOfTimestepEvents
Controls events executed at the end of a time step;.
Definition: MSNet.h:680
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:869
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:878
A lane area vehicles can halt at.
bool hasPermissions() const
Returns whether the network has specific vehicle class permissions.
Definition: MSNet.h:177
bool warnOnce(const std::string &typeAndID)
return whether a warning regarding the given object shall be issued
Definition: MSNet.cpp:1014
const NamedRTree & getLanesRTree() const
Returns an RTree that contains lane IDs.
Definition: MSNet.cpp:990
MSVehicleControl * myVehicleControl
Controls vehicle building and deletion;.
Definition: MSNet.h:662
std::vector< SUMOTime > myStateDumpTimes
Times at which a state shall be written.
Definition: MSNet.h:716
SimulationState simulate(SUMOTime start, SUMOTime stop)
Simulates from timestep start to stop.
Definition: MSNet.cpp:312
SUMOAbstractRouter< MSEdge, SUMOVehicle > * myRouterEffort
Definition: MSNet.h:760
bool logSimulationDuration() const
Returns whether duration shall be logged.
Definition: MSNet.cpp:770
MSIntermodalRouter & getIntermodalRouter(const int routingMode=0, const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:944
std::map< SumoXMLTag, NamedObjectCont< MSStoppingPlace * > > myStoppingPlaces
Dictionary of bus / container stops.
Definition: MSNet.h:747
A RT-tree for efficient storing of SUMO&#39;s Named objects.
Definition: NamedRTree.h:65
virtual void createTLWrapper(MSTrafficLightLogic *)
creates a wrapper for the given logic (see GUINet)
Definition: MSNet.h:488
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:165
bool myHavePermissions
Whether the network contains edges which not all vehicles may pass.
Definition: MSNet.h:729
MSEdgeControl * myEdges
Controls edges, performs vehicle movement;.
Definition: MSNet.h:668
void setCurrentTimeStep(const SUMOTime step)
Sets the current simulation step (used by state loading)
Definition: MSNet.h:271
The final simulation step has been performed.
Definition: MSNet.h:95
double myVersion
the network version
Definition: MSNet.h:744
std::vector< std::string > myStateDumpFiles
The names for the state files.
Definition: MSNet.h:718
bool myLogExecutionTime
Information whether the simulation duration shall be logged.
Definition: MSNet.h:695
Storage for geometrical objects.
static const std::string STAGE_LANECHANGE
Definition: MSNet.h:772
Detectors container; responsible for string and output generation.
bool myLefthand
Whether the network was built for left-hand traffic.
Definition: MSNet.h:741
A storage for edge travel times and efforts.
std::map< int, MSIntermodalRouter * > myIntermodalRouter
Definition: MSNet.h:762
void addVehicleStateListener(VehicleStateListener *listener)
Adds a vehicle states listener.
Definition: MSNet.cpp:838
SimulationState
Possible states of a simulation - running or stopped with different reasons.
Definition: MSNet.h:89
bool addStoppingPlace(const SumoXMLTag category, MSStoppingPlace *stop)
Adds a stopping place.
Definition: MSNet.cpp:863
The simulated network and simulation perfomer.
Definition: MSNet.h:84
void interrupt()
Definition: MSNet.h:627
ShapeContainer * myShapeContainer
A container for geometrical shapes;.
Definition: MSNet.h:684
std::pair< bool, NamedRTree > myLanesRTree
An RTree structure holding lane IDs.
Definition: MSNet.h:766
Container for junctions; performs operations on all stored junctions.
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition: MSNet.cpp:784
The vehicles starts to stop.
Definition: MSNet.h:512
void writeChargingStationOutput() const
write charging station output
Definition: MSNet.cpp:892
A class that stores and controls tls and switching of their programs.
A road/street connecting two junctions.
Definition: MSEdge.h:75
long long int myVehiclesMoved
The overall number of vehicle movements.
Definition: MSNet.h:707
The simulation does not contain further vehicles.
Definition: MSNet.h:97
An error occurred during the simulation step.
Definition: MSNet.h:101
bool myAmInterrupted
whether an interrupt occured
Definition: MSNet.h:654
void writeOutput()
Write netstate, summary and detector output.
Definition: MSNet.cpp:645
The vehicle got a new route.
Definition: MSNet.h:506
The vehicle arrived at his destination (is deleted)
Definition: MSNet.h:504
The vehicles starts to park.
Definition: MSNet.h:508
The vehicle is involved in a collision.
Definition: MSNet.h:516
SimulationState simulationState(SUMOTime stopTime) const
Called after a simulation step, this method returns the current simulation state. ...
Definition: MSNet.cpp:559
static bool hasInstance()
Returns whether the network was already constructed.
Definition: MSNet.h:123
MSInsertionControl * myInserter
Controls vehicle insertion;.
Definition: MSNet.h:674
Representation of a vehicle.
Definition: SUMOVehicle.h:60
The vehicle had to brake harder than permitted.
Definition: MSNet.h:518
SUMORouteLoaderControl * myRouteLoaders
Route loader for dynamic loading of routes.
Definition: MSNet.h:645
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:776
static double getTravelTime(const MSEdge *const e, const SUMOVehicle *const v, double t)
Returns the travel time to pass an edge.
Definition: MSNet.cpp:148
ShapeContainer & getShapeContainer()
Returns the shapes container.
Definition: MSNet.h:439
void closeSimulation(SUMOTime start)
Closes the simulation (all files, connections, etc.)
Definition: MSNet.cpp:423
std::map< std::string, std::map< SUMOVehicleClass, double > > myRestrictions
The vehicle class specific speed restrictions.
Definition: MSNet.h:732
bool myLogStepNumber
Information whether the number of the simulation step shall be logged.
Definition: MSNet.h:698
MSTLLogicControl & getTLSControl()
Returns the tls logics control.
Definition: MSNet.h:389
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:316
bool isInterrupted() const
Definition: MSNet.h:631
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
Definition: MSNet.h:409
MSDetectorControl * myDetectorControl
Controls detectors;.
Definition: MSNet.h:676
void setPermissionsFound()
Labels the network to contain vehicle class permissions.
Definition: MSNet.h:183
void postSimStepOutput() const
Prints the statistics of the step at its end.
Definition: MSNet.cpp:808
bool hasContainers() const
Returns whether containers are simulated.
Definition: MSNet.h:349
Stores edges and lanes, performs moving of vehicle.
Definition: MSEdgeControl.h:67
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:302
MSTLLogicControl * myLogics
Controls tls logics, realizes waiting on tls rules;.
Definition: MSNet.h:672
The connection to a client was closed by the client.
Definition: MSNet.h:99
The simulation is running.
Definition: MSNet.h:93
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:263
std::map< std::string, bool > myWarnedOnce
container to record warnings that shall only be issued once
Definition: MSNet.h:753
void addRestriction(const std::string &id, const SUMOVehicleClass svc, const double speed)
Adds a restriction for an edge type.
Definition: MSNet.cpp:296
virtual void vehicleStateChanged(const SUMOVehicle *const vehicle, VehicleState to, const std::string &info="")=0
Called if a vehicle changes its state.
MSNet & operator=(const MSNet &)
Invalidated assignment operator.
The vehicle started to teleport.
Definition: MSNet.h:500
bool hasInternalLinks() const
return whether the network contains internal links
Definition: MSNet.h:605
The vehicle ends to park.
Definition: MSNet.h:510
MSDetectorControl & getDetectorControl()
Returns the detector control.
Definition: MSNet.h:379
bool hasElevation() const
return whether the network contains elevation data
Definition: MSNet.h:610
MSPedestrianRouter & getPedestrianRouter(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:934
bool lefthand() const
return whether the network was built for lefthand traffic
Definition: MSNet.h:615
SUMOTime myStateDumpPeriod
The period for writing state.
Definition: MSNet.h:720
Inserts vehicles into the network when their departure time is reached.
long myTraCIStepDuration
The last simulation step duration.
Definition: MSNet.h:701
int myMaxTeleports
Maximum number of teleports.
Definition: MSNet.h:651
PedestrianRouter< MSEdge, MSLane, MSJunction, MSVehicle > MSPedestrianRouter
Definition: MSNet.h:108
VehicleState
Definition of a vehicle state.
Definition: MSNet.h:494
MSEventControl * getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
Definition: MSNet.h:419
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:771
VehicleStateListener()
Constructor.
Definition: MSNet.h:528
The vehicle was built, but has not yet departed.
Definition: MSNet.h:496
std::vector< VehicleStateListener * > myVehicleStateListeners
Container for vehicle state listener.
Definition: MSNet.h:750
static MSNet * myInstance
Unique instance of MSNet.
Definition: MSNet.h:642
static void clearAll()
Clears all dictionaries.
Definition: MSNet.cpp:620
The simulation is loading.
Definition: MSNet.h:91
MSTransportableControl * myContainerControl
Controls container building and deletion;.
Definition: MSNet.h:666
MSJunctionControl * myJunctions
Controls junctions, realizes right-of-way rules;.
Definition: MSNet.h:670
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition: MSNet.h:369
MSTransportableControl * myPersonControl
Controls person building and deletion;.
Definition: MSNet.h:664
bool checkElevation()
check all lanes for elevation data
Definition: MSNet.cpp:1000
An external interrupt occured.
Definition: MSNet.h:103
void preSimStepOutput() const
Prints the current step number.
Definition: MSNet.cpp:802
MSEventControl * myBeginOfTimestepEvents
Controls events executed at the begin of a time step;.
Definition: MSNet.h:678
A storage for options typed value containers)
Definition: OptionsCont.h:92
virtual ~VehicleStateListener()
Destructor.
Definition: MSNet.h:531
MSEdgeWeightsStorage * myEdgeWeights
The net&#39;s knowledge about edge efforts/travel times;.
Definition: MSNet.h:686
The simulation had too many teleports.
Definition: MSNet.h:105
MSNet(MSVehicleControl *vc, MSEventControl *beginOfTimestepEvents, MSEventControl *endOfTimestepEvents, MSEventControl *insertionEvents, ShapeContainer *shapeCont=0)
Constructor.
Definition: MSNet.cpp:173
The vehicle ends to stop.
Definition: MSNet.h:514
MSEventControl * getInsertionEvents()
Returns the event control for insertion events.
Definition: MSNet.h:429
long mySimBeginMillis
The overall simulation duration.
Definition: MSNet.h:704
virtual ~MSNet()
Destructor.
Definition: MSNet.cpp:254
bool myHasElevation
Whether the network contains elevation data.
Definition: MSNet.h:738
The parent class for traffic light logics.
std::string myStateDumpPrefix
name components for periodic state
Definition: MSNet.h:722
static std::string getStateMessage(SimulationState state)
Returns the message to show if a certain state occurs.
Definition: MSNet.cpp:595
double getNetworkVersion() const
return the network version
Definition: MSNet.h:620
MSEdgeControl & getEdgeControl()
Returns the edge control.
Definition: MSNet.h:359
IntermodalRouter< MSEdge, MSLane, MSJunction, SUMOVehicle > MSIntermodalRouter
Definition: MSNet.h:109
MSJunctionControl & getJunctionControl()
Returns the junctions control.
Definition: MSNet.h:399
SUMOTime myStep
Current time step.
Definition: MSNet.h:648
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:903
The class responsible for building and deletion of vehicles.
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:71
void simulationStep()
Performs a single simulation step.
Definition: MSNet.cpp:441
void loadRoutes()
loads routes for the next few steps
Definition: MSNet.cpp:362
static const std::string STAGE_INSERTIONS
Definition: MSNet.h:773
MSEventControl * myInsertionEvents
Controls insertion events;.
Definition: MSNet.h:682
Representation of a lane in the micro simulation.
Definition: MSLane.h:78
long mySimStepDuration
Definition: MSNet.h:701
Encapsulates binary reading operations on a file.
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterEffort(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:923
Stores time-dependant events and executes them at the proper time.
The vehicle ended being teleported.
Definition: MSNet.h:502
bool myHasInternalLinks
Whether the network contains internal links/lanes/edges.
Definition: MSNet.h:735
SUMOAbstractRouter< MSEdge, SUMOVehicle > * myRouterTT
Definition: MSNet.h:759
static void adaptIntermodalRouter(MSIntermodalRouter &router)
Definition: MSNet.cpp:970
const std::string generateStatistics(SUMOTime start)
Writes performance output and running vehicle stats.
Definition: MSNet.cpp:368
static double getEffort(const MSEdge *const e, const SUMOVehicle *const v, double t)
Returns the effort to pass an edge.
Definition: MSNet.cpp:134
MSEdgeWeightsStorage & getWeightsStorage()
Returns the net&#39;s internal edge travel times/efforts container.
Definition: MSNet.cpp:793
static const std::string STAGE_EVENTS
string constants for simstep stages
Definition: MSNet.h:770