SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSRoute.h
Go to the documentation of this file.
1 /****************************************************************************/
10 // A vehicle route
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
13 // Copyright (C) 2001-2014 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
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 
46 
47 // ===========================================================================
48 // class declarations
49 // ===========================================================================
50 class MSEdge;
51 class BinaryInputDevice;
53 
54 
55 // ===========================================================================
56 // types definitions
57 // ===========================================================================
58 typedef std::vector<const MSEdge*> MSEdgeVector;
59 typedef MSEdgeVector::const_iterator MSRouteIterator;
60 
61 
62 // ===========================================================================
63 // class definitions
64 // ===========================================================================
68 class MSRoute : public Named, public Parameterised {
69 public:
71  MSRoute(const std::string& id, const MSEdgeVector& edges,
72  const bool isPermanent, const RGBColor* const c,
73  const std::vector<SUMOVehicleParameter::Stop>& stops);
74 
76  virtual ~MSRoute();
77 
79  MSRouteIterator begin() const;
80 
82  MSRouteIterator end() const;
83 
85  unsigned size() const;
86 
88  const MSEdge* getLastEdge() const;
89 
91  void addReference() const;
92 
94  void release() const;
95 
102  int writeEdgeIDs(OutputDevice& os, const MSEdge* const from, const MSEdge* const upTo = 0) const;
103 
104  bool contains(const MSEdge* const edge) const {
105  return std::find(myEdges.begin(), myEdges.end(), edge) != myEdges.end();
106  }
107 
108  bool containsAnyOf(const std::vector<MSEdge*>& edgelist) const;
109 
110  const MSEdge* operator[](unsigned index) const;
111 
114 
119  static void dict_saveState(OutputDevice& out);
121 
122  const MSEdgeVector& getEdges() const {
123  return myEdges;
124  }
125 
126  SUMOReal getLength() const;
127 
136  SUMOReal getDistanceBetween(SUMOReal fromPos, SUMOReal toPos, const MSEdge* fromEdge, const MSEdge* toEdge) const;
137 
139  const RGBColor& getColor() const;
140 
142  const std::vector<SUMOVehicleParameter::Stop>& getStops() const;
143 
144 public:
154  static bool dictionary(const std::string& id, const MSRoute* route);
155 
166  static bool dictionary(const std::string& id, RandomDistributor<const MSRoute*>* const routeDist, const bool permanent = true);
167 
176  static const MSRoute* dictionary(const std::string& id);
177 
185  static RandomDistributor<const MSRoute*>* distDictionary(const std::string& id);
186 
188  static void clear();
189 
191  static void checkDist(const std::string& id);
192 
193  static void insertIDs(std::vector<std::string>& into);
194 
195 private:
198 
200  const bool myAmPermanent;
201 
203  mutable unsigned int myReferenceCounter;
204 
206  const RGBColor* const myColor;
207 
209  std::vector<SUMOVehicleParameter::Stop> myStops;
210 
211 private:
213  typedef std::map<std::string, const MSRoute*> RouteDict;
214 
217 
219  typedef std::map<std::string, std::pair<RandomDistributor<const MSRoute*>*, bool> > RouteDistDict;
220 
223 
224 private:
226  MSRoute& operator=(const MSRoute& s);
227 
228 };
229 
230 
231 #endif
232 
233 /****************************************************************************/
234 
std::map< std::string, const MSRoute * > RouteDict
Definition of the dictionary container.
Definition: MSRoute.h:213
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:198
MSRoute & operator=(const MSRoute &s)
MSEdgeVector::const_iterator MSRouteIterator
Definition: MSRoute.h:59
const MSEdge * getLastEdge() const
returns the destination edge
Definition: MSRoute.cpp:92
const MSEdgeVector & getEdges() const
Definition: MSRoute.h:122
static RandomDistributor< const MSRoute * > * distDictionary(const std::string &id)
Returns the named route distribution.
Definition: MSRoute.cpp:149
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:264
const std::vector< SUMOVehicleParameter::Stop > & getStops() const
Returns the stops.
Definition: MSRoute.cpp:321
static void dict_saveState(OutputDevice &out)
Saves all known routes into the given stream.
Definition: MSRoute.cpp:237
static void insertIDs(std::vector< std::string > &into)
Definition: MSRoute.cpp:186
A road/street connecting two junctions.
Definition: MSEdge.h:73
static void clear()
Clears the dictionary (delete all known routes, too)
Definition: MSRoute.cpp:159
std::vector< const MSEdge * > MSEdgeVector
Definition: MSPerson.h:53
bool containsAnyOf(const std::vector< MSEdge * > &edgelist) const
Definition: MSRoute.cpp:219
static RouteDistDict myDistDict
The dictionary container.
Definition: MSRoute.h:222
MSEdgeVector myEdges
The list of edges to pass.
Definition: MSRoute.h:197
bool contains(const MSEdge *const edge) const
Definition: MSRoute.h:104
std::map< std::string, std::pair< RandomDistributor< const MSRoute * > *, bool > > RouteDistDict
Definition of the dictionary container.
Definition: MSRoute.h:219
virtual ~MSRoute()
Destructor.
Definition: MSRoute.cpp:68
SUMOReal getLength() const
Definition: MSRoute.cpp:254
An upper class for objects with additional parameters.
Definition: Parameterised.h:46
void addReference() const
increments the reference counter for the route
Definition: MSRoute.cpp:99
std::vector< const MSEdge * > MSEdgeVector
Definition: MSRoute.h:52
std::vector< SUMOVehicleParameter::Stop > myStops
List of the stops on the parsed route.
Definition: MSRoute.h:209
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:200
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:80
unsigned size() const
Returns the number of edges to pass.
Definition: MSRoute.cpp:86
const MSEdge * operator[](unsigned index) const
Definition: MSRoute.cpp:231
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
const RGBColor & getColor() const
Returns the color.
Definition: MSRoute.cpp:312
#define SUMOReal
Definition: config.h:215
unsigned int myReferenceCounter
Information by how many vehicles the route is used.
Definition: MSRoute.h:203
void release() const
deletes the route if there are no further references to it
Definition: MSRoute.cpp:105
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:172
static RouteDict myDict
The dictionary container.
Definition: MSRoute.h:216
const RGBColor *const myColor
The color.
Definition: MSRoute.h:206
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
Definition: MSRoute.cpp:74
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:59
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.
Definition: MSRoute.cpp:115