Eclipse SUMO - Simulation of Urban MObility
GUINet.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
20 // A MSNet extended by some values for usage within the gui
21 /****************************************************************************/
22 #pragma once
23 #include <config.h>
24 
25 #include <string>
26 #include <utility>
27 #include <microsim/MSNet.h>
29 #include <utils/geom/Boundary.h>
30 #include <utils/geom/Position.h>
40 
41 
42 // ===========================================================================
43 // class declarations
44 // ===========================================================================
45 class MSEdgeControl;
46 class MSJunctionControl;
47 class MSTLLogicControl;
49 class MSLink;
50 class GUIJunctionWrapper;
51 class GUIDetectorWrapper;
52 class GUICalibrator;
54 class RGBColor;
55 class GUIEdge;
56 class OutputDevice;
57 class GUIVehicle;
58 class GUIVehicleControl;
59 class MSVehicleControl;
61 class Command;
62 
63 
64 // ===========================================================================
65 // class definitions
66 // ===========================================================================
82 class GUINet : public MSNet, public GUIGlObject {
83 
84  friend class GUITrafficLightLogicWrapper; // see createTLWrapper
85 
86 public:
94  GUINet(MSVehicleControl* vc, MSEventControl* beginOfTimestepEvents,
95  MSEventControl* endOfTimestepEvents,
96  MSEventControl* insertionEvents);
97 
98 
100  ~GUINet();
101 
102 
106  bool isGUINet() const override {
107  return true;
108  }
109 
110 
112 
113 
122 
131 
137  Boundary getCenteringBoundary() const override;
138 
143  void drawGL(const GUIVisualizationSettings& s) const override;
145 
146 
148  const Boundary& getBoundary() const;
149 
151  Position getJunctionPosition(const std::string& name) const;
152 
154  bool vehicleExists(const std::string& name) const;
155 
157  void guiSimulationStep();
158 
161  void simulationStep();
162 
165 
169  int getWholeDuration() const;
170 
171 
175  int getSimDuration() const;
176 
177 
179  double getRTFactor() const;
180 
182  double getUPS() const;
183 
185  double getMeanRTFactor(int duration) const;
186 
188  double getMeanUPS() const;
189 
190  // Returns the duration of the last step's visualisation part (in ms)
191  //int getVisDuration() const;
192 
194  int getIdleDuration() const;
195 
197  void setSimDuration(int val);
198 
199  // Sets the duration of the last step's visualisation part
200  //void setVisDuration(int val);
201 
203  void setIdleDuration(int val);
204  //}
205 
206  double getAvgRouteLength() const {
208  }
209  double getAvgDuration() const {
211  }
212  double getAvgWaitingTime() const {
214  }
215  double getAvgTimeLoss() const {
217  }
218  double getAvgDepartDelay() const {
220  }
221  double getAvgTripSpeed() const {
223  }
224  double getAvgWalkRouteLength() const {
226  }
227  double getAvgWalkDuration() const {
229  }
230  double getAvgWalkTimeLoss() const {
232  }
233 
243 
244 
254 
255 
258  int getLinkTLID(const MSLink* const link) const;
259 
262  int getLinkTLIndex(const MSLink* const link) const;
263 
264 
266 
267 
268  /* @brief Returns the gl-ids of all junctions within the net
269  * @param[in] includeInternal Whether to include ids of internal junctions
270  */
271  std::vector<GUIGlID> getJunctionIDs(bool includeInternal) const;
272 
274  std::vector<GUIGlID> getTLSIDs() const;
276 
277 
279  void initGUIStructures();
280 
281 
286  return myGrid;
287  }
288 
289 
293  const SUMORTree& getVisualisationSpeedUp(bool secondary = false) const {
294  return secondary ? myGrid2 : myGrid;
295  }
296 
299 
306 
313 
315  double getEdgeData(const MSEdge* edge, const std::string& attr);
316 
318  double getMeanData(const MSLane* lane, const std::string& id, const std::string& attr);
319 
321  bool loadEdgeData(const std::string& file);
322 
324  std::vector<std::string> getEdgeDataAttrs() const;
325 
327  std::vector<std::string> getMeanDataIDs() const;
328 
330  std::vector<std::string> getMeanDataAttrs(const std::string& meanDataID) const;
331 
332 #ifdef HAVE_OSG
333  void updateColor(const GUIVisualizationSettings& s);
334 #endif
335 
337  void lock();
338 
340  void unlock();
341 
346  static GUINet* getGUIInstance();
347 
349  void createTLWrapper(MSTrafficLightLogic* tll) override;
350 
352  bool isSelected(const MSTrafficLightLogic* tll) const override;
353 
355  void updateGUI() const override;
356 
358  void addHotkey(int key, Command* press, Command* release = nullptr);
359 
361  void flushOutputsAtEnd();
362 
363  virtual bool skipFinalReset() const override {
364  return mySkipFinalReset;
365  }
366 
367 private:
369  void initTLMap();
370 
371  friend class GUIOSGBuilder;
372 
373 protected:
376 
379 
382 
384  std::vector<GUIEdge*> myEdgeWrapper;
385 
387  std::vector<GUIJunctionWrapper*> myJunctionWrapper;
388 
390  std::vector<GUIDetectorWrapper*> myDetectorWrapper;
391 
393  std::vector<GUICalibrator*> myCalibratorWrapper;
394 
396  typedef std::map<const MSLink*, std::string> Links2LogicMap;
399 
400 
402  typedef std::map<MSTrafficLightLogic*, GUITrafficLightLogicWrapper*> Logics2WrapperMap;
405 
406 
408  int myLastSimDuration, /*myLastVisDuration, */myLastIdleDuration;
409 
412 
414  std::map<std::string, MSEdgeWeightsStorage*> myLoadedEdgeData;
415 
416  bool mySkipFinalReset = false;
417 
420  public:
421  DiscoverAttributes(const std::string& file):
424  void myStartElement(int element, const SUMOSAXAttributes& attrs);
425  std::vector<std::string> getEdgeAttrs();
429  private:
430  std::set<std::string> edgeAttrs;
431  };
432 
434  public:
437 
440 
449  void addEdgeWeight(const std::string& id, double val, double beg, double end) const;
450  void addEdgeRelWeight(const std::string& from, const std::string& to, double val, double beg, double end) const;
451 
452  private:
455 
456  };
457 
458 private:
460  mutable FXMutex myLock;
461 
462 };
long long int SUMOTime
Definition: GUI.h:35
#define SUMOTime_MAX
Definition: SUMOTime.h:34
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:39
Base (microsim) event class.
Definition: Command.h:50
Changes the speed allowed on a set of lanes (gui version)
Definition: GUICalibrator.h:42
A road/street connecting two junctions (gui-version)
Definition: GUIEdge.h:51
The popup menu of a globject.
The class responsible for building and deletion of vehicles (gui-version)
class for discovering edge attributes
Definition: GUINet.h:419
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Callback method for an opening tag to implement by derived classes.
Definition: GUINet.cpp:634
SUMOTime firstIntervalBegin
Definition: GUINet.h:426
DiscoverAttributes(const std::string &file)
Definition: GUINet.h:421
std::set< std::string > edgeAttrs
Definition: GUINet.h:430
std::vector< std::string > getEdgeAttrs()
Definition: GUINet.cpp:654
MSEdgeWeightsStorage * myWeightStorage
The storage that edges shall be added to.
Definition: GUINet.h:454
void addEdgeWeight(const std::string &id, double val, double beg, double end) const
Adds an effort for a given edge and time period.
Definition: GUINet.cpp:661
~EdgeFloatTimeLineRetriever_GUI()
Destructor.
Definition: GUINet.h:439
void addEdgeRelWeight(const std::string &from, const std::string &to, double val, double beg, double end) const
Definition: GUINet.cpp:673
EdgeFloatTimeLineRetriever_GUI(MSEdgeWeightsStorage *weightStorage)
Constructor.
Definition: GUINet.h:436
A MSNet extended by some values for usage within the gui.
Definition: GUINet.h:82
double getAvgTripSpeed() const
Definition: GUINet.h:221
const SUMORTree & getVisualisationSpeedUp(bool secondary=false) const
Returns the RTree used for visualisation speed-up.
Definition: GUINet.h:293
double getAvgRouteLength() const
Definition: GUINet.h:206
double getAvgDuration() const
Definition: GUINet.h:209
int getWholeDuration() const
Returns the duration of the last step (sim+visualisation+idle) (in ms)
Definition: GUINet.cpp:378
Boundary getCenteringBoundary() const override
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GUINet.cpp:566
void setIdleDuration(int val)
Sets the duration of the last step's idle part.
Definition: GUINet.cpp:456
GUIVehicleControl * getGUIVehicleControl()
Returns the vehicle control.
Definition: GUINet.cpp:582
void unlock()
release exclusive access to the simulation state
Definition: GUINet.cpp:594
double getUPS() const
Returns the update per seconds rate.
Definition: GUINet.cpp:407
bool loadEdgeData(const std::string &file)
load edgeData from file
Definition: GUINet.cpp:697
void drawGL(const GUIVisualizationSettings &s) const override
Draws the object.
Definition: GUINet.cpp:561
virtual bool skipFinalReset() const override
gui may prevent final meanData reset to keep live data visible
Definition: GUINet.h:363
long myLastVehicleMovementCount
Definition: GUINet.h:410
std::vector< GUIGlID > getJunctionIDs(bool includeInternal) const
Definition: GUINet.cpp:240
std::map< const MSLink *, std::string > Links2LogicMap
Definition of a link-to-logic-id map.
Definition: GUINet.h:396
MSTransportableControl & getPersonControl() override
Returns the person control.
Definition: GUINet.cpp:130
FXMutex myLock
The mutex used to avoid concurrent updates of the vehicle buffer.
Definition: GUINet.h:460
void flushOutputsAtEnd()
flush outputs once the simulation has reached its end
Definition: GUINet.cpp:786
bool mySkipFinalReset
Definition: GUINet.h:416
SUMORTree & getVisualisationSpeedUp()
Returns the RTree used for visualisation speed-up.
Definition: GUINet.h:285
bool isSelected(const MSTrafficLightLogic *tll) const override
return wheter the given logic (or rather it's wrapper) is selected in the GUI
Definition: GUINet.cpp:760
~GUINet()
Destructor.
Definition: GUINet.cpp:94
long myOverallVehicleCount
Definition: GUINet.h:410
void simulationStep()
Performs a single simulation step (locking the simulation)
Definition: GUINet.cpp:233
int getSimDuration() const
Returns the duration of the last step's simulation part (in ms)
Definition: GUINet.cpp:384
SUMORTree myGrid2
The visualization speed-up for secondary shapes.
Definition: GUINet.h:378
void initGUIStructures()
Initialises gui wrappers.
Definition: GUINet.cpp:267
long myOverallSimDuration
Definition: GUINet.h:411
std::vector< std::string > getEdgeDataAttrs() const
return list of loaded edgeData attributes
Definition: GUINet.cpp:728
const Boundary & getBoundary() const
returns the bounder of the network
Definition: GUINet.cpp:124
double getRTFactor() const
Returns the simulation speed as a factor to real time.
Definition: GUINet.cpp:398
void registerRenderedObject(GUIGlObject *o)
add object into rtree
Definition: GUINet.cpp:367
std::vector< GUIEdge * > myEdgeWrapper
Wrapped MS-edges.
Definition: GUINet.h:384
std::map< MSTrafficLightLogic *, GUITrafficLightLogicWrapper * > Logics2WrapperMap
Definition of a traffic light-to-wrapper map.
Definition: GUINet.h:402
double getAvgWalkDuration() const
Definition: GUINet.h:227
int getLinkTLID(const MSLink *const link) const
Definition: GUINet.cpp:198
void setSimDuration(int val)
Sets the duration of the last step's simulation part.
Definition: GUINet.cpp:440
std::vector< GUICalibrator * > myCalibratorWrapper
A calibrator dictionary.
Definition: GUINet.h:393
std::vector< std::string > getMeanDataIDs() const
return list of loaded edgeData ids (being computed in the current simulation)
Definition: GUINet.cpp:738
bool isGUINet() const override
Returns whether this is a GUI Net.
Definition: GUINet.h:106
double getMeanUPS() const
Returns the update per seconds rate.
Definition: GUINet.cpp:425
double getMeanData(const MSLane *lane, const std::string &id, const std::string &attr)
retrieve live lane/edge weight for the given meanData id and attribute
Definition: GUINet.cpp:622
void initTLMap()
Initialises the tl-logic map and wrappers.
Definition: GUINet.cpp:148
int getLinkTLIndex(const MSLink *const link) const
Definition: GUINet.cpp:213
Boundary myBoundary
The networks boundary.
Definition: GUINet.h:381
double getAvgWalkTimeLoss() const
Definition: GUINet.h:230
std::vector< GUIGlID > getTLSIDs() const
Returns the gl-ids of all traffic light logics within the net.
Definition: GUINet.cpp:252
std::map< std::string, MSEdgeWeightsStorage * > myLoadedEdgeData
loaded edge data for visualization
Definition: GUINet.h:414
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent) override
Returns an own parameter window.
Definition: GUINet.cpp:477
Logics2WrapperMap myLogics2Wrapper
The traffic light-to-wrapper map.
Definition: GUINet.h:404
int getIdleDuration() const
Returns the duration of the last step's idle part (in ms)
Definition: GUINet.cpp:434
double getMeanRTFactor(int duration) const
Returns the simulation speed as a factor to real time.
Definition: GUINet.cpp:416
void createTLWrapper(MSTrafficLightLogic *tll) override
creates a wrapper for the given logic
Definition: GUINet.cpp:157
bool vehicleExists(const std::string &name) const
returns the information whether the vehicle still exists
Definition: GUINet.cpp:192
std::vector< GUIDetectorWrapper * > myDetectorWrapper
A detector dictionary.
Definition: GUINet.h:390
void addHotkey(int key, Command *press, Command *release=nullptr)
register custom hotkey action
Definition: GUINet.cpp:776
double getAvgWalkRouteLength() const
Definition: GUINet.h:224
void lock()
grant exclusive access to the simulation state
Definition: GUINet.cpp:588
std::vector< GUIJunctionWrapper * > myJunctionWrapper
Wrapped MS-junctions.
Definition: GUINet.h:387
void updateGUI() const override
update view after simulation.loadState
Definition: GUINet.cpp:766
static GUINet * getGUIInstance()
Returns the pointer to the unique instance of GUINet (singleton).
Definition: GUINet.cpp:572
double getAvgTimeLoss() const
Definition: GUINet.h:215
double getAvgDepartDelay() const
Definition: GUINet.h:218
double getEdgeData(const MSEdge *edge, const std::string &attr)
retrieve loaded edged weight for the given attribute and the current simulation time
Definition: GUINet.cpp:605
double getAvgWaitingTime() const
Definition: GUINet.h:212
std::vector< std::string > getMeanDataAttrs(const std::string &meanDataID) const
return list of available attributes for the given meanData id
Definition: GUINet.cpp:749
int myLastSimDuration
The step durations (simulation, /*visualisation, *‍/idle)
Definition: GUINet.h:408
Position getJunctionPosition(const std::string &name) const
returns the position of a junction
Definition: GUINet.cpp:185
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent) override
Returns an own popup-menu.
Definition: GUINet.cpp:462
int myLastIdleDuration
Definition: GUINet.h:408
friend class GUIOSGBuilder
Definition: GUINet.h:371
void guiSimulationStep()
Some further steps needed for gui processing.
Definition: GUINet.cpp:226
MSTransportableControl & getContainerControl() override
Returns the container control.
Definition: GUINet.cpp:139
GUINet(MSVehicleControl *vc, MSEventControl *beginOfTimestepEvents, MSEventControl *endOfTimestepEvents, MSEventControl *insertionEvents)
Constructor.
Definition: GUINet.cpp:83
GUIMEVehicleControl * getGUIMEVehicleControl()
Returns the vehicle control.
Definition: GUINet.cpp:599
Links2LogicMap myLinks2Logic
The link-to-logic-id map.
Definition: GUINet.h:398
LayeredRTree myGrid
The visualization speed-up.
Definition: GUINet.h:375
A window containing a gl-object's parameter.
The class responsible for building and deletion of vehicles (gui-version)
A MSVehicle extended by some values for usage within the gui.
Definition: GUIVehicle.h:51
Stores the information about how to visualize structures.
A RT-tree for efficient storing of SUMO's GL-objects in layers.
Definition: LayeredRTree.h:46
static double getAvgWalkRouteLength()
static double getAvgTimeLoss()
static double getAvgDepartDelay()
static double getAvgRouteLength()
accessors for GUINet-Parameters
static double getAvgWaitingTime()
static double getAvgDuration()
static double getAvgWalkDuration()
static double getAvgWalkTimeLoss()
Stores edges and lanes, performs moving of vehicle.
Definition: MSEdgeControl.h:78
A road/street connecting two junctions.
Definition: MSEdge.h:77
A storage for edge travel times and efforts.
Stores time-dependant events and executes them at the proper time.
Container for junctions; performs operations on all stored junctions.
Representation of a lane in the micro simulation.
Definition: MSLane.h:84
The simulated network and simulation perfomer.
Definition: MSNet.h:89
A class that stores and controls tls and switching of their programs.
The parent class for traffic light logics.
The class responsible for building and deletion of vehicles.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
Interface for a class which obtains read weights for named edges.
A RT-tree for efficient storing of SUMO's GL-objects.
Definition: SUMORTree.h:66
Encapsulated SAX-Attributes.
SAX-handler base for SUMO-files.