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-2015 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 
47 
48 // ===========================================================================
49 // class declarations
50 // ===========================================================================
51 class MSEdge;
52 class BinaryInputDevice;
54 
55 
56 // ===========================================================================
57 // types definitions
58 // ===========================================================================
59 typedef std::vector<const MSEdge*> ConstMSEdgeVector;
60 typedef std::vector<MSEdge*> MSEdgeVector;
61 typedef ConstMSEdgeVector::const_iterator MSRouteIterator;
62 
63 
64 // ===========================================================================
65 // class definitions
66 // ===========================================================================
70 class MSRoute : public Named, public Parameterised {
71 public:
73  MSRoute(const std::string& id, const ConstMSEdgeVector& edges,
74  const bool isPermanent, const RGBColor* const c,
75  const std::vector<SUMOVehicleParameter::Stop>& stops);
76 
78  virtual ~MSRoute();
79 
81  MSRouteIterator begin() const;
82 
84  MSRouteIterator end() const;
85 
87  unsigned size() const;
88 
90  const MSEdge* getLastEdge() const;
91 
93  void addReference() const;
94 
96  void release() const;
97 
104  int writeEdgeIDs(OutputDevice& os, const MSEdge* const from, const MSEdge* const upTo = 0) const;
105 
106  bool contains(const MSEdge* const edge) const {
107  return std::find(myEdges.begin(), myEdges.end(), edge) != myEdges.end();
108  }
109 
110  bool containsAnyOf(const MSEdgeVector& edgelist) const;
111 
112  const MSEdge* operator[](unsigned index) const;
113 
116 
121  static void dict_saveState(OutputDevice& out);
123 
124  const ConstMSEdgeVector& getEdges() const {
125  return myEdges;
126  }
127 
140  SUMOReal getDistanceBetween(SUMOReal fromPos, SUMOReal toPos, const MSEdge* fromEdge, const MSEdge* toEdge, bool includeInternal = true) const;
141 
153  SUMOReal getDistanceBetween(SUMOReal fromPos, SUMOReal toPos, const MSRouteIterator& fromEdge, const MSRouteIterator& toEdge, bool includeInternal = true) const;
154 
156  const RGBColor& getColor() const;
157 
162  SUMOReal getCosts() const {
163  return myCosts;
164  }
165 
170  void setCosts(SUMOReal costs) {
171  myCosts = costs;
172  }
173 
175  const std::vector<SUMOVehicleParameter::Stop>& getStops() const;
176 
177 public:
187  static bool dictionary(const std::string& id, const MSRoute* route);
188 
199  static bool dictionary(const std::string& id, RandomDistributor<const MSRoute*>* const routeDist, const bool permanent = true);
200 
209  static const MSRoute* dictionary(const std::string& id, MTRand* rng = 0);
210 
218  static RandomDistributor<const MSRoute*>* distDictionary(const std::string& id);
219 
221  static void clear();
222 
224  static void checkDist(const std::string& id);
225 
226  static void insertIDs(std::vector<std::string>& into);
227 
228 private:
231 
233  const bool myAmPermanent;
234 
236  mutable unsigned int myReferenceCounter;
237 
239  const RGBColor* const myColor;
240 
243 
245  std::vector<SUMOVehicleParameter::Stop> myStops;
246 
247 private:
249  typedef std::map<std::string, const MSRoute*> RouteDict;
250 
252  static RouteDict myDict;
253 
255  typedef std::map<std::string, std::pair<RandomDistributor<const MSRoute*>*, bool> > RouteDistDict;
256 
258  static RouteDistDict myDistDict;
259 
260 private:
262  MSRoute& operator=(const MSRoute& s);
263 
264 };
265 
266 
267 #endif
268 
269 /****************************************************************************/
270 
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSRoute.h:53
std::map< std::string, const MSRoute * > RouteDict
Definition of the dictionary container.
Definition: MSRoute.h:249
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:199
MSRoute & operator=(const MSRoute &s)
const MSEdge * getLastEdge() const
returns the destination edge
Definition: MSRoute.cpp:93
void setCosts(SUMOReal costs)
Sets the costs of the route.
Definition: MSRoute.h:170
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:79
static RandomDistributor< const MSRoute * > * distDictionary(const std::string &id)
Returns the named route distribution.
Definition: MSRoute.cpp:150
const std::vector< SUMOVehicleParameter::Stop > & getStops() const
Returns the stops.
Definition: MSRoute.cpp:337
static void dict_saveState(OutputDevice &out)
Saves all known routes into the given stream.
Definition: MSRoute.cpp:238
static void insertIDs(std::vector< std::string > &into)
Definition: MSRoute.cpp:187
A road/street connecting two junctions.
Definition: MSEdge.h:81
SUMOReal myCosts
The assigned or calculated costs.
Definition: MSRoute.h:242
static void clear()
Clears the dictionary (delete all known routes, too)
Definition: MSRoute.cpp:160
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:255
static RouteDistDict myDistDict
The dictionary container.
Definition: MSRoute.h:258
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:60
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:61
bool contains(const MSEdge *const edge) const
Definition: MSRoute.h:106
const ConstMSEdgeVector & getEdges() const
Definition: MSRoute.h:124
std::map< std::string, std::pair< RandomDistributor< const MSRoute * > *, bool > > RouteDistDict
Definition of the dictionary container.
Definition: MSRoute.h:255
virtual ~MSRoute()
Destructor.
Definition: MSRoute.cpp:69
std::vector< MSEdge * > MSEdgeVector
Definition: MSRoute.h:60
SUMOReal getCosts() const
Returns the costs of the route.
Definition: MSRoute.h:162
An upper class for objects with additional parameters.
Definition: Parameterised.h:47
void addReference() const
increments the reference counter for the route
Definition: MSRoute.cpp:100
std::vector< SUMOVehicleParameter::Stop > myStops
List of the stops on the parsed route.
Definition: MSRoute.h:245
Base class for objects which have an id.
Definition: Named.h:45
const bool myAmPermanent
whether the route may be deleted after the last vehicle abandoned it
Definition: MSRoute.h:233
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:81
ConstMSEdgeVector myEdges
The list of edges to pass.
Definition: MSRoute.h:230
unsigned size() const
Returns the number of edges to pass.
Definition: MSRoute.cpp:87
const MSEdge * operator[](unsigned index) const
Definition: MSRoute.cpp:232
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
const RGBColor & getColor() const
Returns the color.
Definition: MSRoute.cpp:328
#define SUMOReal
Definition: config.h:218
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:78
unsigned int myReferenceCounter
Information by how many vehicles the route is used.
Definition: MSRoute.h:236
void release() const
deletes the route if there are no further references to it
Definition: MSRoute.cpp:106
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:173
static RouteDict myDict
The dictionary container.
Definition: MSRoute.h:252
const RGBColor *const myColor
The color.
Definition: MSRoute.h:239
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:75
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.
Definition: MSRoute.cpp:116
bool containsAnyOf(const MSEdgeVector &edgelist) const
Definition: MSRoute.cpp:220