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-sim.org/
14 // Copyright (C) 2002-2014 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*> MSEdgeVector;
60 typedef MSEdgeVector::const_iterator MSRouteIterator;
61 
62 
63 // ===========================================================================
64 // class definitions
65 // ===========================================================================
69 class MSRoute : public Named, public Parameterised {
70 public:
72  MSRoute(const std::string& id, const MSEdgeVector& edges,
73  const bool isPermanent, const RGBColor* const c,
74  const std::vector<SUMOVehicleParameter::Stop>& stops);
75 
77  virtual ~MSRoute();
78 
80  MSRouteIterator begin() const;
81 
83  MSRouteIterator end() const;
84 
86  unsigned size() const;
87 
89  const MSEdge* getLastEdge() const;
90 
92  void addReference() const;
93 
95  void release() const;
96 
103  int writeEdgeIDs(OutputDevice& os, const MSEdge* const from, const MSEdge* const upTo = 0) const;
104 
105  bool contains(const MSEdge* const edge) const {
106  return std::find(myEdges.begin(), myEdges.end(), edge) != myEdges.end();
107  }
108 
109  bool containsAnyOf(const std::vector<MSEdge*>& edgelist) const;
110 
111  const MSEdge* operator[](unsigned index) const;
112 
115 
120  static void dict_saveState(OutputDevice& out);
122 
123  const MSEdgeVector& getEdges() const {
124  return myEdges;
125  }
126 
127  SUMOReal getLength() const;
128 
137  SUMOReal getDistanceBetween(SUMOReal fromPos, SUMOReal toPos, const MSEdge* fromEdge, const MSEdge* toEdge) const;
138 
140  const RGBColor& getColor() const;
141 
143  const std::vector<SUMOVehicleParameter::Stop>& getStops() const;
144 
145 public:
155  static bool dictionary(const std::string& id, const MSRoute* route);
156 
167  static bool dictionary(const std::string& id, RandomDistributor<const MSRoute*>* const routeDist, const bool permanent = true);
168 
177  static const MSRoute* dictionary(const std::string& id);
178 
186  static RandomDistributor<const MSRoute*>* distDictionary(const std::string& id);
187 
189  static void clear();
190 
192  static void checkDist(const std::string& id);
193 
194  static void insertIDs(std::vector<std::string>& into);
195 
196 private:
199 
201  const bool myAmPermanent;
202 
204  mutable unsigned int myReferenceCounter;
205 
207  const RGBColor* const myColor;
208 
210  std::vector<SUMOVehicleParameter::Stop> myStops;
211 
212 private:
214  typedef std::map<std::string, const MSRoute*> RouteDict;
215 
217  static RouteDict myDict;
218 
220  typedef std::map<std::string, std::pair<RandomDistributor<const MSRoute*>*, bool> > RouteDistDict;
221 
223  static RouteDistDict myDistDict;
224 
225 private:
227  MSRoute& operator=(const MSRoute& s);
228 
229 };
230 
231 
232 #endif
233 
234 /****************************************************************************/
235 
std::map< std::string, const MSRoute * > RouteDict
Definition of the dictionary container.
Definition: MSRoute.h:214
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)
MSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:60
const MSEdge * getLastEdge() const
returns the destination edge
Definition: MSRoute.cpp:93
const MSEdgeVector & getEdges() const
Definition: MSRoute.h:123
static RandomDistributor< const MSRoute * > * distDictionary(const std::string &id)
Returns the named route distribution.
Definition: MSRoute.cpp:150
SUMOReal getDistanceBetween(SUMOReal fromPos, SUMOReal toPos, const MSEdge *fromEdge, const MSEdge *toEdge) const
Compute the distance between 2 given edges on this route, including the length of internal lanes...
Definition: MSRoute.cpp:265
const std::vector< SUMOVehicleParameter::Stop > & getStops() const
Returns the stops.
Definition: MSRoute.cpp:322
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:74
static void clear()
Clears the dictionary (delete all known routes, too)
Definition: MSRoute.cpp:160
std::vector< const MSEdge * > MSEdgeVector
Definition: MSPerson.h:57
bool containsAnyOf(const std::vector< MSEdge * > &edgelist) const
Definition: MSRoute.cpp:220
static RouteDistDict myDistDict
The dictionary container.
Definition: MSRoute.h:223
MSEdgeVector myEdges
The list of edges to pass.
Definition: MSRoute.h:198
bool contains(const MSEdge *const edge) const
Definition: MSRoute.h:105
std::map< std::string, std::pair< RandomDistributor< const MSRoute * > *, bool > > RouteDistDict
Definition of the dictionary container.
Definition: MSRoute.h:220
virtual ~MSRoute()
Destructor.
Definition: MSRoute.cpp:69
SUMOReal getLength() const
Definition: MSRoute.cpp:255
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< const MSEdge * > MSEdgeVector
Definition: MSRoute.h:53
std::vector< SUMOVehicleParameter::Stop > myStops
List of the stops on the parsed route.
Definition: MSRoute.h:210
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:201
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:81
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:313
#define SUMOReal
Definition: config.h:215
unsigned int myReferenceCounter
Information by how many vehicles the route is used.
Definition: MSRoute.h:204
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:217
const RGBColor *const myColor
The color.
Definition: MSRoute.h:207
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:75
MSRoute(const std::string &id, const MSEdgeVector &edges, const bool isPermanent, const RGBColor *const c, const std::vector< SUMOVehicleParameter::Stop > &stops)
Constructor.
Definition: MSRoute.cpp:60
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.
Definition: MSRoute.cpp:116