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 
162  const RGBColor& getColor() const;
163 
165  SUMOTime getPeriod() const {
166  return myPeriod;
167  }
168 
173  double getCosts() const {
174  return myCosts;
175  }
176 
181  double getSavings() const {
182  return mySavings;
183  }
184 
187  return myReplacedTime;
188  }
189 
191  int getReplacedIndex() const {
192  return myReplacedIndex;
193  }
194 
196  void setPeriod(SUMOTime period) {
197  myPeriod = period;
198  }
199 
204  void setCosts(double costs) {
205  myCosts = costs;
206  }
211  void setSavings(double savings) {
212  mySavings = savings;
213  }
214 
215  bool mustReroute() const {
216  return myReroute;
217  }
218 
219  void setReroute(bool reroute = true) {
220  myReroute = reroute;
221  }
222 
224  const std::vector<SUMOVehicleParameter::Stop>& getStops() const;
225 
226 public:
236  static bool dictionary(const std::string& id, ConstMSRoutePtr route);
237 
248  static bool dictionary(const std::string& id, RandomDistributor<ConstMSRoutePtr>* const routeDist, const bool permanent = true);
249 
258  static ConstMSRoutePtr dictionary(const std::string& id, SumoRNG* rng = 0);
259 
261  static bool hasRoute(const std::string& id);
262 
270  static RandomDistributor<ConstMSRoutePtr>* distDictionary(const std::string& id);
271 
273  static void clear();
274 
276  static void checkDist(const std::string& id);
277 
278  static void insertIDs(std::vector<std::string>& into);
279 
280 private:
283 
285  const bool myAmPermanent;
286 
288  const RGBColor* const myColor;
289 
292 
294  double myCosts;
295 
297  double mySavings;
298 
300  bool myReroute;
301 
303  std::vector<SUMOVehicleParameter::Stop> myStops;
304 
307 
310 
311 private:
313  typedef std::map<std::string, ConstMSRoutePtr> RouteDict;
314 
317 
319  typedef std::map<std::string, std::pair<RandomDistributor<ConstMSRoutePtr>*, bool> > RouteDistDict;
320 
323 
324 #ifdef HAVE_FOX
326  static FXMutex myDictMutex;
327 #endif
328 private:
331 
332 };
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:300
double myCosts
The assigned or calculated costs.
Definition: MSRoute.h:294
void setReroute(bool reroute=true)
Definition: MSRoute.h:219
int size() const
Returns the number of edges to pass.
Definition: MSRoute.cpp:85
static RouteDistDict myDistDict
The dictionary container.
Definition: MSRoute.h:322
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:288
MSRoute & operator=(const MSRoute &s)
static RouteDict myDict
The dictionary container.
Definition: MSRoute.h:316
std::vector< SUMOVehicleParameter::Stop > myStops
List of the stops on the parsed route.
Definition: MSRoute.h:303
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:191
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:204
double getSavings() const
Returns the estimated savings due to using this route (compare to the route before rerouting)
Definition: MSRoute.h:181
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:313
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:306
SUMOTime myPeriod
The period when repeating this route.
Definition: MSRoute.h:291
ConstMSEdgeVector myEdges
The list of edges to pass.
Definition: MSRoute.h:282
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:309
std::map< std::string, std::pair< RandomDistributor< ConstMSRoutePtr > *, bool > > RouteDistDict
Definition of the dictionary container.
Definition: MSRoute.h:319
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:196
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:285
SUMOTime getReplacedTime() const
Returns the time at which this route was replaced (or -1)
Definition: MSRoute.h:186
bool mustReroute() const
Definition: MSRoute.h:215
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:297
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:165
void setSavings(double savings)
Sets the savings of the route.
Definition: MSRoute.h:211
double getCosts() const
Returns the costs of the route.
Definition: MSRoute.h:173
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