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 #include "MSParkingArea.h"
48 #include "MSStoppingPlace.h"
49 
50 
51 // ===========================================================================
52 // class declarations
53 // ===========================================================================
54 class MSEdge;
55 class MSEdgeControl;
56 class MSEventControl;
57 class MSVehicleControl;
58 class MSJunctionControl;
59 class MSInsertionControl;
62 class MSVehicle;
63 class MSRoute;
64 class MSLane;
65 class MSTLLogicControl;
67 class MSDetectorControl;
68 class ShapeContainer;
69 class BinaryInputDevice;
71 class SUMOVehicle;
72 template<class E, class L, class N, class V>
74 template<class E, class L, class N, class V>
76 
77 
78 // ===========================================================================
79 // class definitions
80 // ===========================================================================
85 class MSNet {
86 public:
105  };
106 
109 
110 
111 public:
116  static MSNet* getInstance();
117 
118 
122  static bool hasInstance() {
123  return myInstance != nullptr;
124  }
125 
126 
141  MSNet(MSVehicleControl* vc, MSEventControl* beginOfTimestepEvents,
142  MSEventControl* endOfTimestepEvents,
143  MSEventControl* insertionEvents,
144  ShapeContainer* shapeCont = 0);
145 
146 
148  virtual ~MSNet();
149 
150 
166  void closeBuilding(const OptionsCont& oc, MSEdgeControl* edges, MSJunctionControl* junctions,
167  SUMORouteLoaderControl* routeLoaders, MSTLLogicControl* tlc,
168  std::vector<SUMOTime> stateDumpTimes, std::vector<std::string> stateDumpFiles,
169  bool hasInternalLinks, bool hasNeighs, bool lefthand,
170  double version);
171 
172 
176  bool hasPermissions() const {
177  return myHavePermissions;
178  }
179 
180 
183  myHavePermissions = true;
184  }
185 
186 
192  void addRestriction(const std::string& id, const SUMOVehicleClass svc, const double speed);
193 
194 
200  const std::map<SUMOVehicleClass, double>* getRestrictions(const std::string& id) const;
201 
202 
206  static void clearAll();
207 
208 
217 
218 
222  void simulationStep();
223 
224 
226  void loadRoutes();
227 
228 
236  void closeSimulation(SUMOTime start);
237 
238 
244  SimulationState simulationState(SUMOTime stopTime) const;
245 
246 
250  static std::string getStateMessage(SimulationState state);
251 
252 
256  inline SUMOTime getCurrentTimeStep() const {
257  return myStep;
258  }
259 
260 
264  inline void setCurrentTimeStep(const SUMOTime step) {
265  myStep = step;
266  }
267 
268 
272  void writeOutput();
273 
274 
278  bool logSimulationDuration() const;
279 
280 
281 
283 
284 
289  void preSimStepOutput() const;
290 
291 
296  void postSimStepOutput() const;
297  //}
298 
299 
300 
303 
310  return *myVehicleControl;
311  }
312 
313 
323 
326  bool hasPersons() const {
327  return myPersonControl != 0;
328  }
329 
339 
342  bool hasContainers() const {
343  return myContainerControl != 0;
344  }
345 
346 
353  return *myEdges;
354  }
355 
356 
363  return *myInserter;
364  }
365 
366 
373  return *myDetectorControl;
374  }
375 
376 
383  return *myLogics;
384  }
385 
386 
393  return *myJunctions;
394  }
395 
396 
404  }
405 
406 
413  return myEndOfTimestepEvents;
414  }
415 
416 
423  return myInsertionEvents;
424  }
425 
426 
433  return *myShapeContainer;
434  }
435 
443 
446 
457  bool addStoppingPlace(const SumoXMLTag category, MSStoppingPlace* stop);
458 
459 
465  MSStoppingPlace* getStoppingPlace(const std::string& id, const SumoXMLTag category) const;
466 
473  std::string getStoppingPlaceID(const MSLane* lane, const double pos, const SumoXMLTag category) const;
475 
476 
478  void writeChargingStationOutput() const;
479 
482 
485 
512  };
513 
514 
519  public:
522 
524  virtual ~VehicleStateListener() { }
525 
531  virtual void vehicleStateChanged(const SUMOVehicle* const vehicle, VehicleState to, const std::string& info = "") = 0;
532 
533  };
534 
535 
540 
541 
546 
547 
554  void informVehicleStateListener(const SUMOVehicle* const vehicle, VehicleState to, const std::string& info = "");
556 
557 
558 
566  static double getTravelTime(const MSEdge* const e, const SUMOVehicle* const v, double t);
567 
568 
576  static double getEffort(const MSEdge* const e, const SUMOVehicle* const v, double t);
577 
578 
579  /* @brief get the router, initialize on first use
580  * @param[in] prohibited The vector of forbidden edges (optional)
581  */
583  const MSEdgeVector& prohibited = MSEdgeVector()) const;
585  const MSEdgeVector& prohibited = MSEdgeVector()) const;
586  MSPedestrianRouter& getPedestrianRouter(const MSEdgeVector& prohibited = MSEdgeVector()) const;
587  MSIntermodalRouter& getIntermodalRouter(const int routingMode = 0, const MSEdgeVector& prohibited = MSEdgeVector()) const;
588 
589  static void adaptIntermodalRouter(MSIntermodalRouter& router);
590 
591 
595  const NamedRTree& getLanesRTree() const;
596 
598  bool hasInternalLinks() const {
599  return myHasInternalLinks;
600  }
601 
603  bool hasElevation() const {
604  return myHasElevation;
605  }
606 
608  bool lefthand() const {
609  return myLefthand;
610  }
611 
613  double getNetworkVersion() const {
614  return myVersion;
615  }
616 
618  bool warnOnce(const std::string& typeAndID);
619 
620 
621 protected:
623  bool checkElevation();
624 
625 
626 protected:
628  static MSNet* myInstance;
629 
632 
635 
638 
639 
640 
643 
671 
672 
673 
676 
679 
682 
685 
688 
690  long long int myVehiclesMoved;
691  //}
692 
693 
694 
697 
699  std::vector<SUMOTime> myStateDumpTimes;
701  std::vector<std::string> myStateDumpFiles;
705  std::string myStateDumpPrefix;
706  std::string myStateDumpSuffix;
708 
709 
710 
713 
715  std::map<std::string, std::map<SUMOVehicleClass, double> > myRestrictions;
716 
719 
722 
725 
727  double myVersion;
728 
730  std::map<SumoXMLTag, NamedObjectCont<MSStoppingPlace*> > myStoppingPlaces;
731 
733  std::vector<VehicleStateListener*> myVehicleStateListeners;
734 
736  std::map<std::string, bool> myWarnedOnce;
737 
738  /* @brief The router instance for routing by trigger and by traci
739  * @note MSDevice_Routing has its own instance since it uses a different weight function
740  * @note we provide one member for every switchable router type
741  * because the class structure makes it inconvenient to use a superclass*/
744  mutable MSPedestrianRouter* myPedestrianRouter;
745  mutable std::map<int, MSIntermodalRouter*> myIntermodalRouter;
746 
747 
749  mutable std::pair<bool, NamedRTree> myLanesRTree;
750 
751 
753  static const std::string STAGE_EVENTS;
754  static const std::string STAGE_MOVEMENTS;
755  static const std::string STAGE_LANECHANGE;
756  static const std::string STAGE_INSERTIONS;
757 
758 private:
760  MSNet(const MSNet&);
761 
763  MSNet& operator=(const MSNet&);
764 
765 
766 };
767 
768 
769 #endif
770 
771 /****************************************************************************/
772 
std::string myStateDumpSuffix
Definition: MSNet.h:706
The vehicle has departed (was inserted into the network)
Definition: MSNet.h:491
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:518
bool hasPersons() const
Returns whether persons are simulated.
Definition: MSNet.h:326
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:827
void removeVehicleStateListener(VehicleStateListener *listener)
Removes a vehicle states listener.
Definition: MSNet.cpp:818
MSPedestrianRouter * myPedestrianRouter
Definition: MSNet.h:744
MSEventControl * myEndOfTimestepEvents
Controls events executed at the end of a time step;.
Definition: MSNet.h:663
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:841
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:850
A lane area vehicles can halt at.
bool hasPermissions() const
Returns whether the network has specific vehicle class permissions.
Definition: MSNet.h:176
bool warnOnce(const std::string &typeAndID)
return whether a warning regarding the given object shall be issued
Definition: MSNet.cpp:985
const NamedRTree & getLanesRTree() const
Returns an RTree that contains lane IDs.
Definition: MSNet.cpp:961
MSVehicleControl * myVehicleControl
Controls vehicle building and deletion;.
Definition: MSNet.h:645
std::vector< SUMOTime > myStateDumpTimes
Times at which a state shall be written.
Definition: MSNet.h:699
SimulationState simulate(SUMOTime start, SUMOTime stop)
Simulates from timestep start to stop.
Definition: MSNet.cpp:308
SUMOAbstractRouter< MSEdge, SUMOVehicle > * myRouterEffort
Definition: MSNet.h:743
bool logSimulationDuration() const
Returns whether duration shall be logged.
Definition: MSNet.cpp:742
MSIntermodalRouter & getIntermodalRouter(const int routingMode=0, const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:916
std::map< SumoXMLTag, NamedObjectCont< MSStoppingPlace * > > myStoppingPlaces
Dictionary of bus / container stops.
Definition: MSNet.h:730
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:481
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:160
bool myHavePermissions
Whether the network contains edges which not all vehicles may pass.
Definition: MSNet.h:712
MSEdgeControl * myEdges
Controls edges, performs vehicle movement;.
Definition: MSNet.h:651
void setCurrentTimeStep(const SUMOTime step)
Sets the current simulation step (used by state loading)
Definition: MSNet.h:264
The final simulation step has been performed.
Definition: MSNet.h:96
double myVersion
the network version
Definition: MSNet.h:727
std::vector< std::string > myStateDumpFiles
The names for the state files.
Definition: MSNet.h:701
bool myLogExecutionTime
Information whether the simulation duration shall be logged.
Definition: MSNet.h:678
Storage for geometrical objects.
static const std::string STAGE_LANECHANGE
Definition: MSNet.h:755
Detectors container; responsible for string and output generation.
bool myLefthand
Whether the network was built for left-hand traffic.
Definition: MSNet.h:724
A storage for edge travel times and efforts.
std::map< int, MSIntermodalRouter * > myIntermodalRouter
Definition: MSNet.h:745
void addVehicleStateListener(VehicleStateListener *listener)
Adds a vehicle states listener.
Definition: MSNet.cpp:810
SimulationState
Possible states of a simulation - running or stopped with different reasons.
Definition: MSNet.h:90
bool addStoppingPlace(const SumoXMLTag category, MSStoppingPlace *stop)
Adds a stopping place.
Definition: MSNet.cpp:835
The simulated network and simulation perfomer.
Definition: MSNet.h:85
ShapeContainer * myShapeContainer
A container for geometrical shapes;.
Definition: MSNet.h:667
std::pair< bool, NamedRTree > myLanesRTree
An RTree structure holding lane IDs.
Definition: MSNet.h:749
Container for junctions; performs operations on all stored junctions.
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition: MSNet.cpp:756
The vehicles starts to stop.
Definition: MSNet.h:505
void writeChargingStationOutput() const
write charging station output
Definition: MSNet.cpp:864
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:690
The simulation does not contain further vehicles.
Definition: MSNet.h:98
An error occurred during the simulation step.
Definition: MSNet.h:102
void writeOutput()
Write netstate, summary and detector output.
Definition: MSNet.cpp:625
The vehicle got a new route.
Definition: MSNet.h:499
The vehicle arrived at his destination (is deleted)
Definition: MSNet.h:497
The vehicles starts to park.
Definition: MSNet.h:501
The vehicle is involved in a collision.
Definition: MSNet.h:509
SimulationState simulationState(SUMOTime stopTime) const
Called after a simulation step, this method returns the current simulation state. ...
Definition: MSNet.cpp:545
static bool hasInstance()
Returns whether the network was already constructed.
Definition: MSNet.h:122
MSInsertionControl * myInserter
Controls vehicle insertion;.
Definition: MSNet.h:657
Representation of a vehicle.
Definition: SUMOVehicle.h:60
The vehicle had to brake harder than permitted.
Definition: MSNet.h:511
SUMORouteLoaderControl * myRouteLoaders
Route loader for dynamic loading of routes.
Definition: MSNet.h:631
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:748
static double getTravelTime(const MSEdge *const e, const SUMOVehicle *const v, double t)
Returns the travel time to pass an edge.
Definition: MSNet.cpp:143
ShapeContainer & getShapeContainer()
Returns the shapes container.
Definition: MSNet.h:432
void closeSimulation(SUMOTime start)
Closes the simulation (all files, connections, etc.)
Definition: MSNet.cpp:363
std::map< std::string, std::map< SUMOVehicleClass, double > > myRestrictions
The vehicle class specific speed restrictions.
Definition: MSNet.h:715
bool myLogStepNumber
Information whether the number of the simulation step shall be logged.
Definition: MSNet.h:681
MSTLLogicControl & getTLSControl()
Returns the tls logics control.
Definition: MSNet.h:382
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:309
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
Definition: MSNet.h:402
MSDetectorControl * myDetectorControl
Controls detectors;.
Definition: MSNet.h:659
void setPermissionsFound()
Labels the network to contain vehicle class permissions.
Definition: MSNet.h:182
void postSimStepOutput() const
Prints the statistics of the step at its end.
Definition: MSNet.cpp:780
bool hasContainers() const
Returns whether containers are simulated.
Definition: MSNet.h:342
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:298
MSTLLogicControl * myLogics
Controls tls logics, realizes waiting on tls rules;.
Definition: MSNet.h:655
The connection to a client was closed by the client.
Definition: MSNet.h:100
The simulation is running.
Definition: MSNet.h:94
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:256
std::map< std::string, bool > myWarnedOnce
container to record warnings that shall only be issued once
Definition: MSNet.h:736
void addRestriction(const std::string &id, const SUMOVehicleClass svc, const double speed)
Adds a restriction for an edge type.
Definition: MSNet.cpp:292
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:493
bool hasInternalLinks() const
return whether the network contains internal links
Definition: MSNet.h:598
The vehicle ends to park.
Definition: MSNet.h:503
MSDetectorControl & getDetectorControl()
Returns the detector control.
Definition: MSNet.h:372
bool hasElevation() const
return whether the network contains elevation data
Definition: MSNet.h:603
MSPedestrianRouter & getPedestrianRouter(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:906
bool lefthand() const
return whether the network was built for lefthand traffic
Definition: MSNet.h:608
SUMOTime myStateDumpPeriod
The period for writing state.
Definition: MSNet.h:703
Inserts vehicles into the network when their departure time is reached.
long myTraCIStepDuration
The last simulation step duration.
Definition: MSNet.h:684
int myMaxTeleports
Maximum number of teleports.
Definition: MSNet.h:637
PedestrianRouter< MSEdge, MSLane, MSJunction, MSVehicle > MSPedestrianRouter
Definition: MSNet.h:107
VehicleState
Definition of a vehicle state.
Definition: MSNet.h:487
MSEventControl * getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
Definition: MSNet.h:412
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:213
static const std::string STAGE_MOVEMENTS
Definition: MSNet.h:754
VehicleStateListener()
Constructor.
Definition: MSNet.h:521
The vehicle was built, but has not yet departed.
Definition: MSNet.h:489
std::vector< VehicleStateListener * > myVehicleStateListeners
Container for vehicle state listener.
Definition: MSNet.h:733
static MSNet * myInstance
Unique instance of MSNet.
Definition: MSNet.h:628
static void clearAll()
Clears all dictionaries.
Definition: MSNet.cpp:601
The simulation is loading.
Definition: MSNet.h:92
MSTransportableControl * myContainerControl
Controls container building and deletion;.
Definition: MSNet.h:649
MSJunctionControl * myJunctions
Controls junctions, realizes right-of-way rules;.
Definition: MSNet.h:653
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition: MSNet.h:362
MSTransportableControl * myPersonControl
Controls person building and deletion;.
Definition: MSNet.h:647
bool checkElevation()
check all lanes for elevation data
Definition: MSNet.cpp:971
void preSimStepOutput() const
Prints the current step number.
Definition: MSNet.cpp:774
MSEventControl * myBeginOfTimestepEvents
Controls events executed at the begin of a time step;.
Definition: MSNet.h:661
A storage for options typed value containers)
Definition: OptionsCont.h:92
virtual ~VehicleStateListener()
Destructor.
Definition: MSNet.h:524
MSEdgeWeightsStorage * myEdgeWeights
The net&#39;s knowledge about edge efforts/travel times;.
Definition: MSNet.h:669
The simulation had too many teleports.
Definition: MSNet.h:104
MSNet(MSVehicleControl *vc, MSEventControl *beginOfTimestepEvents, MSEventControl *endOfTimestepEvents, MSEventControl *insertionEvents, ShapeContainer *shapeCont=0)
Constructor.
Definition: MSNet.cpp:168
The vehicle ends to stop.
Definition: MSNet.h:507
MSEventControl * getInsertionEvents()
Returns the event control for insertion events.
Definition: MSNet.h:422
long mySimBeginMillis
The overall simulation duration.
Definition: MSNet.h:687
virtual ~MSNet()
Destructor.
Definition: MSNet.cpp:250
bool myHasElevation
Whether the network contains elevation data.
Definition: MSNet.h:721
The parent class for traffic light logics.
std::string myStateDumpPrefix
name components for periodic state
Definition: MSNet.h:705
static std::string getStateMessage(SimulationState state)
Returns the message to show if a certain state occurs.
Definition: MSNet.cpp:578
double getNetworkVersion() const
return the network version
Definition: MSNet.h:613
MSEdgeControl & getEdgeControl()
Returns the edge control.
Definition: MSNet.h:352
IntermodalRouter< MSEdge, MSLane, MSJunction, SUMOVehicle > MSIntermodalRouter
Definition: MSNet.h:108
MSJunctionControl & getJunctionControl()
Returns the junctions control.
Definition: MSNet.h:392
SUMOTime myStep
Current time step.
Definition: MSNet.h:634
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:875
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:430
void loadRoutes()
loads routes for the next few steps
Definition: MSNet.cpp:357
static const std::string STAGE_INSERTIONS
Definition: MSNet.h:756
MSEventControl * myInsertionEvents
Controls insertion events;.
Definition: MSNet.h:665
Representation of a lane in the micro simulation.
Definition: MSLane.h:71
long mySimStepDuration
Definition: MSNet.h:684
Encapsulates binary reading operations on a file.
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterEffort(const MSEdgeVector &prohibited=MSEdgeVector()) const
Definition: MSNet.cpp:895
Stores time-dependant events and executes them at the proper time.
The vehicle ended being teleported.
Definition: MSNet.h:495
bool myHasInternalLinks
Whether the network contains internal links/lanes/edges.
Definition: MSNet.h:718
SUMOAbstractRouter< MSEdge, SUMOVehicle > * myRouterTT
Definition: MSNet.h:742
static void adaptIntermodalRouter(MSIntermodalRouter &router)
Definition: MSNet.cpp:941
static double getEffort(const MSEdge *const e, const SUMOVehicle *const v, double t)
Returns the effort to pass an edge.
Definition: MSNet.cpp:129
MSEdgeWeightsStorage & getWeightsStorage()
Returns the net&#39;s internal edge travel times/efforts container.
Definition: MSNet.cpp:765
static const std::string STAGE_EVENTS
string constants for simstep stages
Definition: MSNet.h:753