SUMO - Simulation of Urban MObility
MSRoute.h
Go to the documentation of this file.
1 /****************************************************************************/
11 // A vehicle route
12 /****************************************************************************/
13 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
14 // Copyright (C) 2002-2016 DLR (http://www.dlr.de/) and contributors
15 /****************************************************************************/
16 //
17 // This file is part of SUMO.
18 // SUMO is free software: you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation, either version 3 of the License, or
21 // (at your option) any later version.
22 //
23 /****************************************************************************/
24 #ifndef MSRoute_h
25 #define MSRoute_h
26 
27 
28 // ===========================================================================
29 // included modules
30 // ===========================================================================
31 #ifdef _MSC_VER
32 #include <windows_config.h>
33 #else
34 #include <config.h>
35 #endif
36 
37 #include <string>
38 #include <map>
39 #include <vector>
40 #include <algorithm>
41 #include <utils/common/Named.h>
43 #include <utils/common/RGBColor.h>
46 #ifdef HAVE_FOX
47 #include <fx.h>
48 #include <FXThread.h>
49 #endif
50 
51 
52 // ===========================================================================
53 // class declarations
54 // ===========================================================================
55 class MSEdge;
56 class BinaryInputDevice;
58 
59 
60 // ===========================================================================
61 // types definitions
62 // ===========================================================================
63 typedef std::vector<const MSEdge*> ConstMSEdgeVector;
64 typedef std::vector<MSEdge*> MSEdgeVector;
65 typedef ConstMSEdgeVector::const_iterator MSRouteIterator;
66 
67 
68 // ===========================================================================
69 // class definitions
70 // ===========================================================================
74 class MSRoute : public Named, public Parameterised {
75 public:
77  MSRoute(const std::string& id, const ConstMSEdgeVector& edges,
78  const bool isPermanent, const RGBColor* const c,
79  const std::vector<SUMOVehicleParameter::Stop>& stops);
80 
82  virtual ~MSRoute();
83 
85  MSRouteIterator begin() const;
86 
88  MSRouteIterator end() const;
89 
91  int size() const;
92 
94  const MSEdge* getLastEdge() const;
95 
97  void addReference() const;
98 
100  void release() const;
101 
108  int writeEdgeIDs(OutputDevice& os, const MSEdge* const from, const MSEdge* const upTo = 0) const;
109 
110  bool contains(const MSEdge* const edge) const {
111  return std::find(myEdges.begin(), myEdges.end(), edge) != myEdges.end();
112  }
113 
114  bool containsAnyOf(const MSEdgeVector& edgelist) const;
115 
116  const MSEdge* operator[](int index) const;
117 
120 
125  static void dict_saveState(OutputDevice& out);
127 
128  const ConstMSEdgeVector& getEdges() const {
129  return myEdges;
130  }
131 
144  SUMOReal getDistanceBetween(SUMOReal fromPos, SUMOReal toPos, const MSEdge* fromEdge, const MSEdge* toEdge, bool includeInternal = true) const;
145 
157  SUMOReal getDistanceBetween(SUMOReal fromPos, SUMOReal toPos, const MSRouteIterator& fromEdge, const MSRouteIterator& toEdge, bool includeInternal = true) const;
158 
160  const RGBColor& getColor() const;
161 
166  SUMOReal getCosts() const {
167  return myCosts;
168  }
169 
174  void setCosts(SUMOReal costs) {
175  myCosts = costs;
176  }
177 
179  const std::vector<SUMOVehicleParameter::Stop>& getStops() const;
180 
181 public:
191  static bool dictionary(const std::string& id, const MSRoute* route);
192 
203  static bool dictionary(const std::string& id, RandomDistributor<const MSRoute*>* const routeDist, const bool permanent = true);
204 
213  static const MSRoute* dictionary(const std::string& id, MTRand* rng = 0);
214 
222  static RandomDistributor<const MSRoute*>* distDictionary(const std::string& id);
223 
225  static void clear();
226 
228  static void checkDist(const std::string& id);
229 
230  static void insertIDs(std::vector<std::string>& into);
231 
232 private:
235 
237  const bool myAmPermanent;
238 
240  mutable int myReferenceCounter;
241 
243  const RGBColor* const myColor;
244 
247 
249  std::vector<SUMOVehicleParameter::Stop> myStops;
250 
251 private:
253  typedef std::map<std::string, const MSRoute*> RouteDict;
254 
256  static RouteDict myDict;
257 
259  typedef std::map<std::string, std::pair<RandomDistributor<const MSRoute*>*, bool> > RouteDistDict;
260 
262  static RouteDistDict myDistDict;
263 
264 #ifdef HAVE_FOX
265  static FXMutex myDictMutex;
267 #endif
268 private:
270  MSRoute& operator=(const MSRoute& s);
271 
272 };
273 
274 
275 #endif
276 
277 /****************************************************************************/
278 
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSRoute.h:57
std::map< std::string, const MSRoute * > RouteDict
Definition of the dictionary container.
Definition: MSRoute.h:253
const ConstMSEdgeVector & getEdges() const
Definition: MSRoute.h:128
void release() const
deletes the route if there are no further references to it
Definition: MSRoute.cpp:109
Represents a generic random distribution.
MSRoute & operator=(const MSRoute &s)
const RGBColor & getColor() const
Returns the color.
Definition: MSRoute.cpp:349
void setCosts(SUMOReal costs)
Sets the costs of the route.
Definition: MSRoute.h:174
const MSEdge * getLastEdge() const
returns the destination edge
Definition: MSRoute.cpp:96
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:78
static RandomDistributor< const MSRoute * > * distDictionary(const std::string &id)
Returns the named route distribution.
Definition: MSRoute.cpp:165
int size() const
Returns the number of edges to pass.
Definition: MSRoute.cpp:90
static void dict_saveState(OutputDevice &out)
Saves all known routes into the given stream.
Definition: MSRoute.cpp:265
static void insertIDs(std::vector< std::string > &into)
Definition: MSRoute.cpp:211
A road/street connecting two junctions.
Definition: MSEdge.h:80
SUMOReal getDistanceBetween(SUMOReal fromPos, SUMOReal 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:285
SUMOReal myCosts
The assigned or calculated costs.
Definition: MSRoute.h:246
SUMOReal getCosts() const
Returns the costs of the route.
Definition: MSRoute.h:166
static void clear()
Clears the dictionary (delete all known routes, too)
Definition: MSRoute.cpp:178
static RouteDistDict myDistDict
The dictionary container.
Definition: MSRoute.h:262
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:63
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:65
std::map< std::string, std::pair< RandomDistributor< const MSRoute * > *, bool > > RouteDistDict
Definition of the dictionary container.
Definition: MSRoute.h:259
virtual ~MSRoute()
Destructor.
Definition: MSRoute.cpp:72
std::vector< MSEdge * > MSEdgeVector
Definition: MSRoute.h:64
An upper class for objects with additional parameters.
Definition: Parameterised.h:47
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
std::vector< SUMOVehicleParameter::Stop > myStops
List of the stops on the parsed route.
Definition: MSRoute.h:249
Base class for objects which have an id.
Definition: Named.h:46
const bool myAmPermanent
whether the route may be deleted after the last vehicle abandoned it
Definition: MSRoute.h:237
const MSEdge * operator[](int index) const
Definition: MSRoute.cpp:259
bool containsAnyOf(const MSEdgeVector &edgelist) const
Definition: MSRoute.cpp:247
ConstMSEdgeVector myEdges
The list of edges to pass.
Definition: MSRoute.h:234
void addReference() const
increments the reference counter for the route
Definition: MSRoute.cpp:103
int myReferenceCounter
Information by how many vehicles the route is used.
Definition: MSRoute.h:240
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
#define SUMOReal
Definition: config.h:213
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:78
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:194
const std::vector< SUMOVehicleParameter::Stop > & getStops() const
Returns the stops.
Definition: MSRoute.cpp:358
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:84
static RouteDict myDict
The dictionary container.
Definition: MSRoute.h:256
bool contains(const MSEdge *const edge) const
Definition: MSRoute.h:110
const RGBColor *const myColor
The color.
Definition: MSRoute.h:243
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.
Definition: MSRoute.cpp:122