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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
21 // A vehicle route
22 /****************************************************************************/
23 #ifndef MSRoute_h
24 #define MSRoute_h
25 
26 
27 // ===========================================================================
28 // included modules
29 // ===========================================================================
30 #ifdef _MSC_VER
31 #include <windows_config.h>
32 #else
33 #include <config.h>
34 #endif
35 
36 #include <string>
37 #include <map>
38 #include <vector>
39 #include <algorithm>
40 #include <utils/common/Named.h>
42 #include <utils/common/RGBColor.h>
45 #ifdef HAVE_FOX
46 #include <fx.h>
47 #include <FXThread.h>
48 #endif
49 
50 
51 // ===========================================================================
52 // class declarations
53 // ===========================================================================
54 class MSEdge;
55 class BinaryInputDevice;
57 
58 
59 // ===========================================================================
60 // types definitions
61 // ===========================================================================
62 typedef std::vector<const MSEdge*> ConstMSEdgeVector;
63 typedef std::vector<MSEdge*> MSEdgeVector;
64 typedef ConstMSEdgeVector::const_iterator MSRouteIterator;
65 
66 
67 // ===========================================================================
68 // class definitions
69 // ===========================================================================
73 class MSRoute : public Named, public Parameterised {
74 public:
76  MSRoute(const std::string& id, const ConstMSEdgeVector& edges,
77  const bool isPermanent, const RGBColor* const c,
78  const std::vector<SUMOVehicleParameter::Stop>& stops);
79 
81  virtual ~MSRoute();
82 
84  MSRouteIterator begin() const;
85 
87  MSRouteIterator end() const;
88 
90  int size() const;
91 
93  const MSEdge* getLastEdge() const;
94 
96  void addReference() const;
97 
99  void release() const;
100 
107  int writeEdgeIDs(OutputDevice& os, const MSEdge* const from, const MSEdge* const upTo = 0) const;
108 
109  bool contains(const MSEdge* const edge) const {
110  return std::find(myEdges.begin(), myEdges.end(), edge) != myEdges.end();
111  }
112 
113  bool containsAnyOf(const MSEdgeVector& edgelist) const;
114 
115  const MSEdge* operator[](int index) const;
116 
119 
124  static void dict_saveState(OutputDevice& out);
126 
127  const ConstMSEdgeVector& getEdges() const {
128  return myEdges;
129  }
130 
143  double getDistanceBetween(double fromPos, double toPos, const MSEdge* fromEdge, const MSEdge* toEdge, bool includeInternal = true) const;
144 
156  double getDistanceBetween(double fromPos, double toPos, const MSRouteIterator& fromEdge, const MSRouteIterator& toEdge, bool includeInternal = true) const;
157 
159  const RGBColor& getColor() const;
160 
165  double getCosts() const {
166  return myCosts;
167  }
168 
173  void setCosts(double costs) {
174  myCosts = costs;
175  }
176 
178  const std::vector<SUMOVehicleParameter::Stop>& getStops() const;
179 
180 public:
190  static bool dictionary(const std::string& id, const MSRoute* route);
191 
202  static bool dictionary(const std::string& id, RandomDistributor<const MSRoute*>* const routeDist, const bool permanent = true);
203 
212  static const MSRoute* dictionary(const std::string& id, std::mt19937* rng = 0);
213 
221  static RandomDistributor<const MSRoute*>* distDictionary(const std::string& id);
222 
224  static void clear();
225 
227  static void checkDist(const std::string& id);
228 
229  static void insertIDs(std::vector<std::string>& into);
230 
231 private:
234 
236  const bool myAmPermanent;
237 
239  mutable int myReferenceCounter;
240 
242  const RGBColor* const myColor;
243 
245  double myCosts;
246 
248  std::vector<SUMOVehicleParameter::Stop> myStops;
249 
250 private:
252  typedef std::map<std::string, const MSRoute*> RouteDict;
253 
255  static RouteDict myDict;
256 
258  typedef std::map<std::string, std::pair<RandomDistributor<const MSRoute*>*, bool> > RouteDistDict;
259 
261  static RouteDistDict myDistDict;
262 
263 #ifdef HAVE_FOX
264  static FXMutex myDictMutex;
266 #endif
267 private:
269  MSRoute& operator=(const MSRoute& s);
270 
271 };
272 
273 
274 #endif
275 
276 /****************************************************************************/
277 
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSRoute.h:56
std::map< std::string, const MSRoute * > RouteDict
Definition of the dictionary container.
Definition: MSRoute.h:252
const ConstMSEdgeVector & getEdges() const
Definition: MSRoute.h:127
void release() const
deletes the route if there are no further references to it
Definition: MSRoute.cpp:104
Represents a generic random distribution.
MSRoute & operator=(const MSRoute &s)
double getDistanceBetween(double fromPos, double toPos, const MSEdge *fromEdge, const MSEdge *toEdge, bool includeInternal=true) const
Compute the distance between 2 given edges on this route, including the length of internal lanes...
Definition: MSRoute.cpp:280
const RGBColor & getColor() const
Returns the color.
Definition: MSRoute.cpp:357
const MSEdge * getLastEdge() const
returns the destination edge
Definition: MSRoute.cpp:91
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:78
double getCosts() const
Returns the costs of the route.
Definition: MSRoute.h:165
static RandomDistributor< const MSRoute * > * distDictionary(const std::string &id)
Returns the named route distribution.
Definition: MSRoute.cpp:160
void setCosts(double costs)
Sets the costs of the route.
Definition: MSRoute.h:173
int size() const
Returns the number of edges to pass.
Definition: MSRoute.cpp:85
static void dict_saveState(OutputDevice &out)
Saves all known routes into the given stream.
Definition: MSRoute.cpp:260
static void insertIDs(std::vector< std::string > &into)
Definition: MSRoute.cpp:206
A road/street connecting two junctions.
Definition: MSEdge.h:80
static void clear()
Clears the dictionary (delete all known routes, too)
Definition: MSRoute.cpp:173
static RouteDistDict myDistDict
The dictionary container.
Definition: MSRoute.h:261
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:58
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:64
std::map< std::string, std::pair< RandomDistributor< const MSRoute * > *, bool > > RouteDistDict
Definition of the dictionary container.
Definition: MSRoute.h:258
virtual ~MSRoute()
Destructor.
Definition: MSRoute.cpp:67
std::vector< MSEdge * > MSEdgeVector
Definition: MSRoute.h:63
An upper class for objects with additional parameters.
Definition: Parameterised.h:50
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:221
std::vector< SUMOVehicleParameter::Stop > myStops
List of the stops on the parsed route.
Definition: MSRoute.h:248
Base class for objects which have an id.
Definition: Named.h:54
const bool myAmPermanent
whether the route may be deleted after the last vehicle abandoned it
Definition: MSRoute.h:236
const MSEdge * operator[](int index) const
Definition: MSRoute.cpp:254
bool containsAnyOf(const MSEdgeVector &edgelist) const
Definition: MSRoute.cpp:242
ConstMSEdgeVector myEdges
The list of edges to pass.
Definition: MSRoute.h:233
void addReference() const
increments the reference counter for the route
Definition: MSRoute.cpp:98
int myReferenceCounter
Information by how many vehicles the route is used.
Definition: MSRoute.h:239
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:73
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:77
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:189
const std::vector< SUMOVehicleParameter::Stop > & getStops() const
Returns the stops.
Definition: MSRoute.cpp:366
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:79
static RouteDict myDict
The dictionary container.
Definition: MSRoute.h:255
bool contains(const MSEdge *const edge) const
Definition: MSRoute.h:109
const RGBColor *const myColor
The color.
Definition: MSRoute.h:242
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.
Definition: MSRoute.cpp:117
double myCosts
The assigned or calculated costs.
Definition: MSRoute.h:245