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-2019 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 /****************************************************************************/
19 // A vehicle route
20 /****************************************************************************/
21 #ifndef MSRoute_h
22 #define MSRoute_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #include <config.h>
29 
30 #include <string>
31 #include <map>
32 #include <vector>
33 #include <algorithm>
34 #include <utils/common/Named.h>
36 #include <utils/common/RGBColor.h>
39 #ifdef HAVE_FOX
40 #include <fx.h>
41 #include <FXThread.h>
42 #endif
43 
44 
45 // ===========================================================================
46 // class declarations
47 // ===========================================================================
48 class MSEdge;
49 class BinaryInputDevice;
51 
52 
53 // ===========================================================================
54 // types definitions
55 // ===========================================================================
56 typedef std::vector<const MSEdge*> ConstMSEdgeVector;
57 typedef std::vector<MSEdge*> MSEdgeVector;
58 typedef ConstMSEdgeVector::const_iterator MSRouteIterator;
59 
60 
61 // ===========================================================================
62 // class definitions
63 // ===========================================================================
67 class MSRoute : public Named, public Parameterised {
68 public:
70  MSRoute(const std::string& id, const ConstMSEdgeVector& edges,
71  const bool isPermanent, const RGBColor* const c,
72  const std::vector<SUMOVehicleParameter::Stop>& stops);
73 
75  virtual ~MSRoute();
76 
78  MSRouteIterator begin() const;
79 
81  MSRouteIterator end() const;
82 
84  int size() const;
85 
87  const MSEdge* getLastEdge() const;
88 
90  void addReference() const;
91 
93  void release() const;
94 
101  int writeEdgeIDs(OutputDevice& os, const MSEdge* const from, const MSEdge* const upTo = 0) 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);
120 
121  const ConstMSEdgeVector& getEdges() const {
122  return myEdges;
123  }
124 
138  double getDistanceBetween(double fromPos, double toPos, const MSEdge* fromEdge, const MSEdge* toEdge, bool includeInternal = true, int routePosition = 0) const;
139 
151  double getDistanceBetween(double fromPos, double toPos, const MSRouteIterator& fromEdge, const MSRouteIterator& toEdge, bool includeInternal = true) const;
152 
154  const RGBColor& getColor() const;
155 
160  double getCosts() const {
161  return myCosts;
162  }
163 
168  double getSavings() const {
169  return mySavings;
170  }
171 
176  void setCosts(double costs) {
177  myCosts = costs;
178  }
183  void setSavings(double savings) {
184  mySavings = savings;
185  }
186 
188  const std::vector<SUMOVehicleParameter::Stop>& getStops() const;
189 
190 public:
200  static bool dictionary(const std::string& id, const MSRoute* route);
201 
212  static bool dictionary(const std::string& id, RandomDistributor<const MSRoute*>* const routeDist, const bool permanent = true);
213 
222  static const MSRoute* dictionary(const std::string& id, std::mt19937* rng = 0);
223 
231  static RandomDistributor<const MSRoute*>* distDictionary(const std::string& id);
232 
234  static void clear();
235 
237  static void checkDist(const std::string& id);
238 
239  static void insertIDs(std::vector<std::string>& into);
240 
241 private:
244 
246  const bool myAmPermanent;
247 
249  mutable int myReferenceCounter;
250 
252  const RGBColor* const myColor;
253 
255  double myCosts;
256 
258  double mySavings;
259 
261  std::vector<SUMOVehicleParameter::Stop> myStops;
262 
263 private:
265  typedef std::map<std::string, const MSRoute*> RouteDict;
266 
268  static RouteDict myDict;
269 
271  typedef std::map<std::string, std::pair<RandomDistributor<const MSRoute*>*, bool> > RouteDistDict;
272 
274  static RouteDistDict myDistDict;
275 
276 #ifdef HAVE_FOX
277  static FXMutex myDictMutex;
279 #endif
280 private:
282  MSRoute& operator=(const MSRoute& s);
283 
284 };
285 
286 
287 #endif
288 
289 /****************************************************************************/
290 
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSRoute.h:50
std::map< std::string, const MSRoute * > RouteDict
Definition of the dictionary container.
Definition: MSRoute.h:265
const ConstMSEdgeVector & getEdges() const
Definition: MSRoute.h:121
void release() const
deletes the route if there are no further references to it
Definition: MSRoute.cpp:101
Represents a generic random distribution.
MSRoute & operator=(const MSRoute &s)
const RGBColor & getColor() const
Returns the color.
Definition: MSRoute.cpp:366
const MSEdge * getLastEdge() const
returns the destination edge
Definition: MSRoute.cpp:88
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:73
double getCosts() const
Returns the costs of the route.
Definition: MSRoute.h:160
static RandomDistributor< const MSRoute * > * distDictionary(const std::string &id)
Returns the named route distribution.
Definition: MSRoute.cpp:157
void setCosts(double costs)
Sets the costs of the route.
Definition: MSRoute.h:176
int size() const
Returns the number of edges to pass.
Definition: MSRoute.cpp:82
double mySavings
The estimated savings when rerouting.
Definition: MSRoute.h:258
static void dict_saveState(OutputDevice &out)
Saves all known routes into the given stream.
Definition: MSRoute.cpp:257
static void insertIDs(std::vector< std::string > &into)
Definition: MSRoute.cpp:203
A road/street connecting two junctions.
Definition: MSEdge.h:76
static void clear()
Clears the dictionary (delete all known routes, too)
Definition: MSRoute.cpp:170
double getSavings() const
Returns the estimated savings due to using this route (compare to the route before rerouting) ...
Definition: MSRoute.h:168
static RouteDistDict myDistDict
The dictionary container.
Definition: MSRoute.h:274
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:52
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:58
std::map< std::string, std::pair< RandomDistributor< const MSRoute * > *, bool > > RouteDistDict
Definition of the dictionary container.
Definition: MSRoute.h:271
virtual ~MSRoute()
Destructor.
Definition: MSRoute.cpp:64
std::vector< MSEdge * > MSEdgeVector
Definition: MSRoute.h:57
An upper class for objects with additional parameters.
Definition: Parameterised.h:43
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:218
std::vector< SUMOVehicleParameter::Stop > myStops
List of the stops on the parsed route.
Definition: MSRoute.h:261
Base class for objects which have an id.
Definition: Named.h:57
const bool myAmPermanent
whether the route may be deleted after the last vehicle abandoned it
Definition: MSRoute.h:246
const MSEdge * operator[](int index) const
Definition: MSRoute.cpp:251
void setSavings(double savings)
Sets the savings of the route.
Definition: MSRoute.h:183
bool containsAnyOf(const MSEdgeVector &edgelist) const
Definition: MSRoute.cpp:239
ConstMSEdgeVector myEdges
The list of edges to pass.
Definition: MSRoute.h:243
void addReference() const
increments the reference counter for the route
Definition: MSRoute.cpp:95
int myReferenceCounter
Information by how many vehicles the route is used.
Definition: MSRoute.h:249
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:70
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:72
Encapsulates binary reading operations on a file.
static void checkDist(const std::string &id)
Checks the distribution whether it is permanent and deletes it if not.
Definition: MSRoute.cpp:186
const std::vector< SUMOVehicleParameter::Stop > & getStops() const
Returns the stops.
Definition: MSRoute.cpp:375
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:76
static RouteDict myDict
The dictionary container.
Definition: MSRoute.h:268
bool contains(const MSEdge *const edge) const
Definition: MSRoute.h:103
const RGBColor *const myColor
The color.
Definition: MSRoute.h:252
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.
Definition: MSRoute.cpp:114
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:277
double myCosts
The assigned or calculated costs.
Definition: MSRoute.h:255