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 /****************************************************************************/
18 // A vehicle route
19 /****************************************************************************/
20 #ifndef MSRoute_h
21 #define MSRoute_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #include <config.h>
28 
29 #include <string>
30 #include <map>
31 #include <vector>
32 #include <algorithm>
33 #include <utils/common/Named.h>
35 #include <utils/common/RGBColor.h>
38 #ifdef HAVE_FOX
39 #include <fx.h>
40 #include <FXThread.h>
41 #endif
42 
43 
44 // ===========================================================================
45 // class declarations
46 // ===========================================================================
47 class MSEdge;
48 class BinaryInputDevice;
50 
51 
52 // ===========================================================================
53 // types definitions
54 // ===========================================================================
55 typedef std::vector<const MSEdge*> ConstMSEdgeVector;
56 typedef std::vector<MSEdge*> MSEdgeVector;
57 typedef ConstMSEdgeVector::const_iterator MSRouteIterator;
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 
74  virtual ~MSRoute();
75 
77  MSRouteIterator begin() const;
78 
80  MSRouteIterator end() const;
81 
83  int size() const;
84 
86  const MSEdge* getLastEdge() const;
87 
89  void addReference() const;
90 
92  void release() const;
93 
100  int writeEdgeIDs(OutputDevice& os, const MSEdge* const from, const MSEdge* const upTo = 0) const;
101 
102  bool contains(const MSEdge* const edge) const {
103  return std::find(myEdges.begin(), myEdges.end(), edge) != myEdges.end();
104  }
105 
106  bool containsAnyOf(const MSEdgeVector& edgelist) const;
107 
108  const MSEdge* operator[](int index) const;
109 
112 
117  static void dict_saveState(OutputDevice& out);
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 
159  double getCosts() const {
160  return myCosts;
161  }
162 
167  double getSavings() const {
168  return mySavings;
169  }
170 
175  void setCosts(double costs) {
176  myCosts = costs;
177  }
182  void setSavings(double savings) {
183  mySavings = savings;
184  }
185 
187  const std::vector<SUMOVehicleParameter::Stop>& getStops() const;
188 
189 public:
199  static bool dictionary(const std::string& id, const MSRoute* route);
200 
211  static bool dictionary(const std::string& id, RandomDistributor<const MSRoute*>* const routeDist, const bool permanent = true);
212 
221  static const MSRoute* dictionary(const std::string& id, std::mt19937* rng = 0);
222 
230  static RandomDistributor<const MSRoute*>* distDictionary(const std::string& id);
231 
233  static void clear();
234 
236  static void checkDist(const std::string& id);
237 
238  static void insertIDs(std::vector<std::string>& into);
239 
240 private:
243 
245  const bool myAmPermanent;
246 
248  mutable int myReferenceCounter;
249 
251  const RGBColor* const myColor;
252 
254  double myCosts;
255 
257  double mySavings;
258 
260  std::vector<SUMOVehicleParameter::Stop> myStops;
261 
262 private:
264  typedef std::map<std::string, const MSRoute*> RouteDict;
265 
268 
270  typedef std::map<std::string, std::pair<RandomDistributor<const MSRoute*>*, bool> > RouteDistDict;
271 
274 
275 #ifdef HAVE_FOX
276  static FXMutex myDictMutex;
278 #endif
279 private:
281  MSRoute& operator=(const MSRoute& s);
282 
283 };
284 
285 
286 #endif
287 
288 /****************************************************************************/
289 
MSRoute::checkDist
static void checkDist(const std::string &id)
Checks the distribution whether it is permanent and deletes it if not.
Definition: MSRoute.cpp:185
MSRoute::myDict
static RouteDict myDict
The dictionary container.
Definition: MSRoute.h:267
MSRoute::myColor
const RGBColor *const myColor
The color.
Definition: MSRoute.h:251
MSRoute::release
void release() const
deletes the route if there are no further references to it
Definition: MSRoute.cpp:100
Parameterised
An upper class for objects with additional parameters.
Definition: Parameterised.h:42
Named
Base class for objects which have an id.
Definition: Named.h:56
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:63
MSRoute::end
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:75
MSRouteIterator
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:57
MSRoute::mySavings
double mySavings
The estimated savings when rerouting.
Definition: MSRoute.h:257
MSRoute::RouteDict
std::map< std::string, const MSRoute * > RouteDict
Definition of the dictionary container.
Definition: MSRoute.h:264
MSRoute::getLastEdge
const MSEdge * getLastEdge() const
returns the destination edge
Definition: MSRoute.cpp:87
ConstMSEdgeVector
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:75
MSRoute::setCosts
void setCosts(double costs)
Sets the costs of the route.
Definition: MSRoute.h:175
MSRoute::getEdges
const ConstMSEdgeVector & getEdges() const
Definition: MSRoute.h:120
MSRoute::getColor
const RGBColor & getColor() const
Returns the color.
Definition: MSRoute.cpp:367
MSRoute::operator=
MSRoute & operator=(const MSRoute &s)
MSRoute
Definition: MSRoute.h:66
MSRoute::insertIDs
static void insertIDs(std::vector< std::string > &into)
Definition: MSRoute.cpp:202
RGBColor.h
SUMOVehicleParameter.h
MSRoute::getCosts
double getCosts() const
Returns the costs of the route.
Definition: MSRoute.h:159
MSRoute::MSRoute
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:51
MSRoute::size
int size() const
Returns the number of edges to pass.
Definition: MSRoute.cpp:81
RGBColor
Definition: RGBColor.h:39
RandomDistributor.h
MSRoute::distDictionary
static RandomDistributor< const MSRoute * > * distDictionary(const std::string &id)
Returns the named route distribution.
Definition: MSRoute.cpp:156
Parameterised.h
Named.h
MSRoute::myStops
std::vector< SUMOVehicleParameter::Stop > myStops
List of the stops on the parsed route.
Definition: MSRoute.h:260
MSRoute::~MSRoute
virtual ~MSRoute()
Destructor.
Definition: MSRoute.cpp:63
MSRoute::clear
static void clear()
Clears the dictionary (delete all known routes, too)
Definition: MSRoute.cpp:169
MSRoute::dict_saveState
static void dict_saveState(OutputDevice &out)
Saves all known routes into the given stream.
Definition: MSRoute.cpp:256
MSRoute::operator[]
const MSEdge * operator[](int index) const
Definition: MSRoute.cpp:250
MSRoute::getSavings
double getSavings() const
Returns the estimated savings due to using this route (compare to the route before rerouting)
Definition: MSRoute.h:167
MSEdge
A road/street connecting two junctions.
Definition: MSEdge.h:78
ConstMSEdgeVector
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSRoute.h:49
RandomDistributor< const MSRoute * >
MSRoute::myDistDict
static RouteDistDict myDistDict
The dictionary container.
Definition: MSRoute.h:273
MSRoute::myReferenceCounter
int myReferenceCounter
Information by how many vehicles the route is used.
Definition: MSRoute.h:248
MSRoute::writeEdgeIDs
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:217
MSRoute::RouteDistDict
std::map< std::string, std::pair< RandomDistributor< const MSRoute * > *, bool > > RouteDistDict
Definition of the dictionary container.
Definition: MSRoute.h:270
MSEdgeVector
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:74
MSRoute::getStops
const std::vector< SUMOVehicleParameter::Stop > & getStops() const
Returns the stops.
Definition: MSRoute.cpp:376
MSRoute::begin
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:69
MSRoute::dictionary
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.
Definition: MSRoute.cpp:113
config.h
MSRoute::myAmPermanent
const bool myAmPermanent
whether the route may be deleted after the last vehicle abandoned it
Definition: MSRoute.h:245
MSEdgeVector
std::vector< MSEdge * > MSEdgeVector
Definition: MSRoute.h:56
MSRoute::setSavings
void setSavings(double savings)
Sets the savings of the route.
Definition: MSRoute.h:182
MSRoute::addReference
void addReference() const
increments the reference counter for the route
Definition: MSRoute.cpp:94
MSRoute::containsAnyOf
bool containsAnyOf(const MSEdgeVector &edgelist) const
Definition: MSRoute.cpp:238
MSRoute::myEdges
ConstMSEdgeVector myEdges
The list of edges to pass.
Definition: MSRoute.h:242
MSRoute::contains
bool contains(const MSEdge *const edge) const
Definition: MSRoute.h:102
MSRoute::getDistanceBetween
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:278
MSRoute::myCosts
double myCosts
The assigned or calculated costs.
Definition: MSRoute.h:254
BinaryInputDevice
Encapsulates binary reading operations on a file.
Definition: BinaryInputDevice.h:57