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.org/sumo
3 // Copyright (C) 2002-2020 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 <utils/common/Named.h>
33 #include <utils/common/RGBColor.h>
36 #ifdef HAVE_FOX
37 #include <fx.h>
38 #include <FXThread.h>
39 #endif
40 
41 
42 // ===========================================================================
43 // class declarations
44 // ===========================================================================
45 class MSEdge;
46 class OutputDevice;
47 
48 
49 // ===========================================================================
50 // types definitions
51 // ===========================================================================
52 typedef std::vector<const MSEdge*> ConstMSEdgeVector;
53 typedef std::vector<MSEdge*> MSEdgeVector;
54 typedef ConstMSEdgeVector::const_iterator MSRouteIterator;
55 
56 
57 // ===========================================================================
58 // class definitions
59 // ===========================================================================
63 class MSRoute : public Named, public Parameterised {
64 public:
66  MSRoute(const std::string& id, const ConstMSEdgeVector& edges,
67  const bool isPermanent, const RGBColor* const c,
68  const std::vector<SUMOVehicleParameter::Stop>& stops);
69 
71  virtual ~MSRoute();
72 
74  MSRouteIterator begin() const;
75 
77  MSRouteIterator end() const;
78 
80  int size() const;
81 
83  const MSEdge* getLastEdge() const;
84 
86  void addReference() const;
87 
89  void release() const;
90 
97  int writeEdgeIDs(OutputDevice& os, const MSEdge* const from, const MSEdge* const upTo = 0) const;
98 
99  bool contains(const MSEdge* const edge) const {
100  return std::find(myEdges.begin(), myEdges.end(), edge) != myEdges.end();
101  }
102 
103  bool containsAnyOf(const MSEdgeVector& edgelist) const;
104 
105  const MSEdge* operator[](int index) const;
106 
109 
114  static void dict_saveState(OutputDevice& out);
115 
117  static void dict_clearState();
119 
120  const ConstMSEdgeVector& getEdges() const {
121  return myEdges;
122  }
123 
137  double getDistanceBetween(double fromPos, double toPos, const MSEdge* fromEdge, const MSEdge* toEdge, bool includeInternal = true, int routePosition = 0) const;
138 
150  double getDistanceBetween(double fromPos, double toPos, const MSRouteIterator& fromEdge, const MSRouteIterator& toEdge, bool includeInternal = true) const;
151 
153  const RGBColor& getColor() const;
154 
156  SUMOTime getPeriod() const {
157  return myPeriod;
158  }
159 
164  double getCosts() const {
165  return myCosts;
166  }
167 
172  double getSavings() const {
173  return mySavings;
174  }
175 
177  void setPeriod(SUMOTime period) {
178  myPeriod = period;
179  }
180 
185  void setCosts(double costs) {
186  myCosts = costs;
187  }
192  void setSavings(double savings) {
193  mySavings = savings;
194  }
195 
196  bool mustReroute() const {
197  return myReroute;
198  }
199 
200  void setReroute(bool reroute = true) {
201  myReroute = reroute;
202  }
203 
205  const std::vector<SUMOVehicleParameter::Stop>& getStops() const;
206 
207 public:
217  static bool dictionary(const std::string& id, const MSRoute* route);
218 
229  static bool dictionary(const std::string& id, RandomDistributor<const MSRoute*>* const routeDist, const bool permanent = true);
230 
239  static const MSRoute* dictionary(const std::string& id, std::mt19937* rng = 0);
240 
242  static bool hasRoute(const std::string& id);
243 
251  static RandomDistributor<const MSRoute*>* distDictionary(const std::string& id);
252 
254  static void clear();
255 
257  static void checkDist(const std::string& id);
258 
259  static void insertIDs(std::vector<std::string>& into);
260 
261 private:
264 
266  const bool myAmPermanent;
267 
269  mutable int myReferenceCounter;
270 
272  const RGBColor* const myColor;
273 
276 
278  double myCosts;
279 
281  double mySavings;
282 
284  bool myReroute;
285 
287  std::vector<SUMOVehicleParameter::Stop> myStops;
288 
289 private:
291  typedef std::map<std::string, const MSRoute*> RouteDict;
292 
295 
297  typedef std::map<std::string, std::pair<RandomDistributor<const MSRoute*>*, bool> > RouteDistDict;
298 
301 
302 #ifdef HAVE_FOX
304  static FXMutex myDictMutex;
305 #endif
306 private:
309 
310 };
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:46
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:54
std::vector< MSEdge * > MSEdgeVector
Definition: MSRoute.h:53
long long int SUMOTime
Definition: SUMOTime.h:31
A road/street connecting two junctions.
Definition: MSEdge.h:77
static void dict_clearState()
Decrement all route references before quick-loading state.
Definition: MSRoute.cpp:286
bool myReroute
Whether this route is incomplete and requires rerouting.
Definition: MSRoute.h:284
double myCosts
The assigned or calculated costs.
Definition: MSRoute.h:278
void addReference() const
increments the reference counter for the route
Definition: MSRoute.cpp:94
void setReroute(bool reroute=true)
Definition: MSRoute.h:200
int size() const
Returns the number of edges to pass.
Definition: MSRoute.cpp:81
static RouteDistDict myDistDict
The dictionary container.
Definition: MSRoute.h:300
static void dict_saveState(OutputDevice &out)
Saves all known routes into the given stream.
Definition: MSRoute.cpp:265
const RGBColor *const myColor
The color.
Definition: MSRoute.h:272
MSRoute & operator=(const MSRoute &s)
static RouteDict myDict
The dictionary container.
Definition: MSRoute.h:294
std::vector< SUMOVehicleParameter::Stop > myStops
List of the stops on the parsed route.
Definition: MSRoute.h:287
const std::vector< SUMOVehicleParameter::Stop > & getStops() const
Returns the stops.
Definition: MSRoute.cpp:397
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:75
int myReferenceCounter
Information by how many vehicles the route is used.
Definition: MSRoute.h:269
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.
Definition: MSRoute.cpp:113
void setCosts(double costs)
Sets the costs of the route.
Definition: MSRoute.h:185
double getSavings() const
Returns the estimated savings due to using this route (compare to the route before rerouting)
Definition: MSRoute.h:172
static bool hasRoute(const std::string &id)
returns whether a route with the given id exists
Definition: MSRoute.cpp:156
virtual ~MSRoute()
Destructor.
Definition: MSRoute.cpp:63
const MSEdge * operator[](int index) const
Definition: MSRoute.cpp:259
bool contains(const MSEdge *const edge) const
Definition: MSRoute.h:99
void release() const
deletes the route if there are no further references to it
Definition: MSRoute.cpp:100
const MSEdge * getLastEdge() const
returns the destination edge
Definition: MSRoute.cpp:87
SUMOTime myPeriod
The period when repeating this route.
Definition: MSRoute.h:275
MSRoute(const std::string &id, const ConstMSEdgeVector &edges, const bool isPermanent, const RGBColor *const c, const std::vector< SUMOVehicleParameter::Stop > &stops)
Constructor.
Definition: MSRoute.cpp:49
ConstMSEdgeVector myEdges
The list of edges to pass.
Definition: MSRoute.h:263
std::map< std::string, const MSRoute * > RouteDict
Definition of the dictionary container.
Definition: MSRoute.h:291
std::map< std::string, std::pair< RandomDistributor< const MSRoute * > *, bool > > RouteDistDict
Definition of the dictionary container.
Definition: MSRoute.h:297
static RandomDistributor< const MSRoute * > * distDictionary(const std::string &id)
Returns the named route distribution.
Definition: MSRoute.cpp:165
static void insertIDs(std::vector< std::string > &into)
Definition: MSRoute.cpp:211
double getDistanceBetween(double fromPos, double toPos, const MSEdge *fromEdge, const MSEdge *toEdge, bool includeInternal=true, int routePosition=0) const
Compute the distance between 2 given edges on this route, including the length of internal lanes....
Definition: MSRoute.cpp:299
bool containsAnyOf(const MSEdgeVector &edgelist) const
Definition: MSRoute.cpp:247
int writeEdgeIDs(OutputDevice &os, const MSEdge *const from, const MSEdge *const upTo=0) const
Output the edge ids up to but not including the id of the given edge.
Definition: MSRoute.cpp:226
const RGBColor & getColor() const
Returns the color.
Definition: MSRoute.cpp:388
void setPeriod(SUMOTime period)
sets the period
Definition: MSRoute.h:177
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:69
const bool myAmPermanent
whether the route may be deleted after the last vehicle abandoned it
Definition: MSRoute.h:266
bool mustReroute() const
Definition: MSRoute.h:196
static void checkDist(const std::string &id)
Checks the distribution whether it is permanent and deletes it if not.
Definition: MSRoute.cpp:194
double mySavings
The estimated savings when rerouting.
Definition: MSRoute.h:281
const ConstMSEdgeVector & getEdges() const
Definition: MSRoute.h:120
static void clear()
Clears the dictionary (delete all known routes, too)
Definition: MSRoute.cpp:178
SUMOTime getPeriod() const
returns the period
Definition: MSRoute.h:156
void setSavings(double savings)
Sets the savings of the route.
Definition: MSRoute.h:192
double getCosts() const
Returns the costs of the route.
Definition: MSRoute.h:164
Base class for objects which have an id.
Definition: Named.h:53
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:60
An upper class for objects with additional parameters.
Definition: Parameterised.h:39