SUMO - Simulation of Urban MObility
SUMOAbstractRouter.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2006-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 /****************************************************************************/
19 // An abstract router base class
20 /****************************************************************************/
21 #ifndef SUMOAbstractRouter_h
22 #define SUMOAbstractRouter_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <string>
35 #include <vector>
36 #include <algorithm>
37 #include <assert.h>
38 #include <utils/common/SysUtils.h>
40 #include <utils/common/SUMOTime.h>
41 #include <utils/common/ToString.h>
42 
43 
44 // ===========================================================================
45 // class definitions
46 // ===========================================================================
51 template<class E, class V>
53 public:
55  typedef double(* Operation)(const E* const, const V* const, double);
56 
58  SUMOAbstractRouter(Operation operation, const std::string& type):
59  myOperation(operation),
60  myBulkMode(false),
61  myType(type),
62  myQueryVisits(0),
63  myNumQueries(0),
65  myQueryTimeSum(0) {
66  }
67 
69  virtual ~SUMOAbstractRouter() {
70  if (myNumQueries > 0) {
71  WRITE_MESSAGE(myType + " answered " + toString(myNumQueries) + " queries and explored " + toString(double(myQueryVisits) / myNumQueries) + " edges on average.");
72  WRITE_MESSAGE(myType + " spent " + toString(myQueryTimeSum) + "ms answering queries (" + toString(double(myQueryTimeSum) / myNumQueries) + "ms on average).");
73  }
74  }
75 
76  virtual SUMOAbstractRouter* clone() = 0;
77 
80  virtual bool compute(const E* from, const E* to, const V* const vehicle,
81  SUMOTime msTime, std::vector<const E*>& into) = 0;
82 
83  virtual double recomputeCosts(const std::vector<const E*>& edges,
84  const V* const v, SUMOTime msTime) const = 0;
85 
86  inline double getEffort(const E* const e, const V* const v, double t) const {
87  return (*myOperation)(e, v, t);
88  }
89 
90  inline void startQuery() {
91  myNumQueries++;
93  }
94 
95  inline void endQuery(int visits) {
96  myQueryVisits += visits;
98  }
99 
100  void setBulkMode(const bool mode) {
101  myBulkMode = mode;
102  }
103 
104 protected:
107 
110 
111 private:
113  const std::string myType;
114 
116  long long int myQueryVisits;
117  long long int myNumQueries;
119  long long int myQueryStartTime;
120  long long int myQueryTimeSum;
121 private:
124 };
125 
126 
127 template<class E, class V>
129 public:
130  inline bool operator()(const E* edge, const V* vehicle) const {
131  if (std::find(myProhibited.begin(), myProhibited.end(), edge) != myProhibited.end()) {
132  return true;
133  }
134  return edge->prohibits(vehicle);
135  }
136 
137  void prohibit(const std::vector<E*>& toProhibit) {
138  myProhibited = toProhibit;
139  }
140 
141 protected:
142  std::vector<E*> myProhibited;
143 
144 };
145 
146 template<class E, class V>
148 public:
149  inline bool operator()(const E*, const V*) const {
150  return false;
151  }
152 };
153 
154 
155 
156 
157 #endif
158 
159 /****************************************************************************/
160 
double getEffort(const E *const e, const V *const v, double t) const
void prohibit(const std::vector< E *> &toProhibit)
double(* Operation)(const E *const, const V *const, double)
Type of the function that is used to retrieve the edge effort.
std::vector< E * > myProhibited
long long int myQueryTimeSum
virtual double recomputeCosts(const std::vector< const E *> &edges, const V *const v, SUMOTime msTime) const =0
virtual bool compute(const E *from, const E *to, const V *const vehicle, SUMOTime msTime, std::vector< const E *> &into)=0
Builds the route between the given edges using the minimum effort at the given time The definition of...
bool operator()(const E *edge, const V *vehicle) const
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
bool myBulkMode
whether we are currently operating several route queries in a bulk
Operation myOperation
The object&#39;s operation to perform.
long long int myQueryStartTime
the time spent querying in milliseconds
SUMOAbstractRouter & operator=(const SUMOAbstractRouter &s)
Invalidated assignment operator.
virtual ~SUMOAbstractRouter()
Destructor.
long long int myNumQueries
long long int myQueryVisits
counters for performance logging
void endQuery(int visits)
bool operator()(const E *, const V *) const
long long int SUMOTime
Definition: TraCIDefs.h:51
virtual SUMOAbstractRouter * clone()=0
static long getCurrentMillis()
Returns the current time in milliseconds.
Definition: SysUtils.cpp:45
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:200
const std::string myType
the type of this router
SUMOAbstractRouter(Operation operation, const std::string &type)
Constructor.
void setBulkMode(const bool mode)