Eclipse SUMO - Simulation of Urban MObility
MSRoute.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2002-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 /****************************************************************************/
22 // A vehicle route
23 /****************************************************************************/
24 #pragma once
25 #include <config.h>
26 
27 #include <string>
28 #include <map>
29 #include <vector>
30 #include <algorithm>
31 #include <memory>
32 #include <utils/common/Named.h>
34 #include <utils/common/RGBColor.h>
37 #ifdef HAVE_FOX
39 #include <FXThread.h>
40 #endif
41 
42 
43 // ===========================================================================
44 // class declarations
45 // ===========================================================================
46 class MSEdge;
47 class MSRoute;
48 class OutputDevice;
49 
50 
51 // ===========================================================================
52 // types definitions
53 // ===========================================================================
54 typedef std::vector<const MSEdge*> ConstMSEdgeVector;
55 typedef std::vector<MSEdge*> MSEdgeVector;
56 typedef ConstMSEdgeVector::const_iterator MSRouteIterator;
57 typedef std::shared_ptr<const MSRoute> ConstMSRoutePtr;
58 
59 
60 // ===========================================================================
61 // class definitions
62 // ===========================================================================
66 class MSRoute : public Named, public Parameterised {
67 public:
69  MSRoute(const std::string& id, const ConstMSEdgeVector& edges,
70  const bool isPermanent, const RGBColor* const c,
71  const std::vector<SUMOVehicleParameter::Stop>& stops,
72  SUMOTime replacedTime = -1,
73  int replacedIndex = 0);
74 
76  virtual ~MSRoute();
77 
79  MSRouteIterator begin() const;
80 
82  MSRouteIterator end() const;
83 
85  int size() const;
86 
88  const MSEdge* getLastEdge() const;
89 
91  void checkRemoval() const;
92 
101  int writeEdgeIDs(OutputDevice& os, int firstIndex = 0, int lastIndex = -1, bool withInternal = false, SUMOVehicleClass svc = SVC_IGNORING) const;
102 
103  bool contains(const MSEdge* const edge) const {
104  return std::find(myEdges.begin(), myEdges.end(), edge) != myEdges.end();
105  }
106 
107  bool containsAnyOf(const MSEdgeVector& edgelist) const;
108 
109  const MSEdge* operator[](int index) const;
110 
113 
118  static void dict_saveState(OutputDevice& out);
119 
121  static void dict_clearState();
123 
124  const ConstMSEdgeVector& getEdges() const {
125  return myEdges;
126  }
127 
146  double getDistanceBetween(double fromPos, double toPos, const MSLane* fromLane, const MSLane* toLane, int routePosition = 0) const;
147 
159  double getDistanceBetween(double fromPos, double toPos, const MSRouteIterator& fromEdge, const MSRouteIterator& toEdge, bool includeInternal = true) const;
160 
161 
163  const RGBColor& getColor() const;
164 
166  SUMOTime getPeriod() const {
167  return myPeriod;
168  }
169 
174  double getCosts() const {
175  return myCosts;
176  }
177 
182  double getSavings() const {
183  return mySavings;
184  }
185 
188  return myReplacedTime;
189  }
190 
192  int getReplacedIndex() const {
193  return myReplacedIndex;
194  }
195 
197  void setPeriod(SUMOTime period) {
198  myPeriod = period;
199  }
200 
205  void setCosts(double costs) {
206  myCosts = costs;
207  }
212  void setSavings(double savings) {
213  mySavings = savings;
214  }
215 
216  bool mustReroute() const {
217  return myReroute;
218  }
219 
220  void setReroute(bool reroute = true) {
221  myReroute = reroute;
222  }
223 
225  const std::vector<SUMOVehicleParameter::Stop>& getStops() const;
226 
227 public:
237  static bool dictionary(const std::string& id, ConstMSRoutePtr route);
238 
249  static bool dictionary(const std::string& id, RandomDistributor<ConstMSRoutePtr>* const routeDist, const bool permanent = true);
250 
259  static ConstMSRoutePtr dictionary(const std::string& id, SumoRNG* rng = 0);
260 
262  static bool hasRoute(const std::string& id);
263 
271  static RandomDistributor<ConstMSRoutePtr>* distDictionary(const std::string& id);
272 
274  static void clear();
275 
277  static void checkDist(const std::string& id);
278 
279  static void insertIDs(std::vector<std::string>& into);
280 
281 private:
284 
286  const bool myAmPermanent;
287 
289  const RGBColor* const myColor;
290 
293 
295  double myCosts;
296 
298  double mySavings;
299 
301  bool myReroute;
302 
304  std::vector<SUMOVehicleParameter::Stop> myStops;
305 
308 
311 
312 private:
314  typedef std::map<std::string, ConstMSRoutePtr> RouteDict;
315 
318 
320  typedef std::map<std::string, std::pair<RandomDistributor<ConstMSRoutePtr>*, bool> > RouteDistDict;
321 
324 
325 #ifdef HAVE_FOX
327  static FXMutex myDictMutex;
328 #endif
329 private:
332 
333 };
long long int SUMOTime
Definition: GUI.h:35
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:74
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:73
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSRoute.h:48
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:56
std::vector< MSEdge * > MSEdgeVector
Definition: MSRoute.h:55
std::shared_ptr< const MSRoute > ConstMSRoutePtr
Definition: MSRoute.h:57
std::shared_ptr< const MSRoute > ConstMSRoutePtr
Definition: Route.h:31
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
A road/street connecting two junctions.
Definition: MSEdge.h:77
Representation of a lane in the micro simulation.
Definition: MSLane.h:84
static void dict_clearState()
Decrement all route references before quick-loading state.
Definition: MSRoute.cpp:301
bool myReroute
Whether this route is incomplete and requires rerouting.
Definition: MSRoute.h:301
double myCosts
The assigned or calculated costs.
Definition: MSRoute.h:295
void setReroute(bool reroute=true)
Definition: MSRoute.h:220
int size() const
Returns the number of edges to pass.
Definition: MSRoute.cpp:85
static RouteDistDict myDistDict
The dictionary container.
Definition: MSRoute.h:323
static void dict_saveState(OutputDevice &out)
Saves all known routes into the given stream.
Definition: MSRoute.cpp:261
const RGBColor *const myColor
The color.
Definition: MSRoute.h:289
MSRoute & operator=(const MSRoute &s)
static RouteDict myDict
The dictionary container.
Definition: MSRoute.h:317
std::vector< SUMOVehicleParameter::Stop > myStops
List of the stops on the parsed route.
Definition: MSRoute.h:304
const std::vector< SUMOVehicleParameter::Stop > & getStops() const
Returns the stops.
Definition: MSRoute.cpp:404
int getReplacedIndex() const
Returns the index at which this route was replaced.
Definition: MSRoute.h:192
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:79
int writeEdgeIDs(OutputDevice &os, int firstIndex=0, int lastIndex=-1, bool withInternal=false, SUMOVehicleClass svc=SVC_IGNORING) const
Output the edge ids up to but not including the id of the given edge.
Definition: MSRoute.cpp:219
void setCosts(double costs)
Sets the costs of the route.
Definition: MSRoute.h:205
double getSavings() const
Returns the estimated savings due to using this route (compare to the route before rerouting)
Definition: MSRoute.h:182
static bool hasRoute(const std::string &id)
returns whether a route with the given id exists
Definition: MSRoute.cpp:152
std::map< std::string, ConstMSRoutePtr > RouteDict
Definition of the dictionary container.
Definition: MSRoute.h:314
virtual ~MSRoute()
Destructor.
Definition: MSRoute.cpp:67
void checkRemoval() const
removes the route from the internal dict if it is not marked as permanent
Definition: MSRoute.cpp:98
const MSEdge * operator[](int index) const
Definition: MSRoute.cpp:255
bool contains(const MSEdge *const edge) const
Definition: MSRoute.h:103
const MSEdge * getLastEdge() const
returns the destination edge
Definition: MSRoute.cpp:91
SUMOTime myReplacedTime
The time where this route was replaced with an alternative route (or -1)
Definition: MSRoute.h:307
SUMOTime myPeriod
The period when repeating this route.
Definition: MSRoute.h:292
ConstMSEdgeVector myEdges
The list of edges to pass.
Definition: MSRoute.h:283
static void insertIDs(std::vector< std::string > &into)
Definition: MSRoute.cpp:204
bool containsAnyOf(const MSEdgeVector &edgelist) const
Definition: MSRoute.cpp:243
int myReplacedIndex
The index where this route was replaced with an alternative route.
Definition: MSRoute.h:310
std::map< std::string, std::pair< RandomDistributor< ConstMSRoutePtr > *, bool > > RouteDistDict
Definition of the dictionary container.
Definition: MSRoute.h:320
static bool dictionary(const std::string &id, ConstMSRoutePtr route)
Adds a route to the dictionary.
Definition: MSRoute.cpp:109
const RGBColor & getColor() const
Returns the color.
Definition: MSRoute.cpp:395
static RandomDistributor< ConstMSRoutePtr > * distDictionary(const std::string &id)
Returns the named route distribution.
Definition: MSRoute.cpp:161
void setPeriod(SUMOTime period)
sets the period
Definition: MSRoute.h:197
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:73
double getDistanceBetween(double fromPos, double toPos, const MSLane *fromLane, const MSLane *toLane, int routePosition=0) const
Compute the distance between 2 given edges on this route, optionally including the length of internal...
Definition: MSRoute.cpp:311
const bool myAmPermanent
whether the route may be deleted after the last vehicle abandoned it
Definition: MSRoute.h:286
SUMOTime getReplacedTime() const
Returns the time at which this route was replaced (or -1)
Definition: MSRoute.h:187
bool mustReroute() const
Definition: MSRoute.h:216
static void checkDist(const std::string &id)
Checks the distribution whether it is permanent and deletes it if not.
Definition: MSRoute.cpp:187
double mySavings
The estimated savings when rerouting.
Definition: MSRoute.h:298
const ConstMSEdgeVector & getEdges() const
Definition: MSRoute.h:124
MSRoute(const std::string &id, const ConstMSEdgeVector &edges, const bool isPermanent, const RGBColor *const c, const std::vector< SUMOVehicleParameter::Stop > &stops, SUMOTime replacedTime=-1, int replacedIndex=0)
Constructor.
Definition: MSRoute.cpp:49
static void clear()
Clears the dictionary (delete all known routes, too)
Definition: MSRoute.cpp:174
SUMOTime getPeriod() const
returns the period
Definition: MSRoute.h:166
void setSavings(double savings)
Sets the savings of the route.
Definition: MSRoute.h:212
double getCosts() const
Returns the costs of the route.
Definition: MSRoute.h:174
Base class for objects which have an id.
Definition: Named.h:54
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
An upper class for objects with additional parameters.
Definition: Parameterised.h:41