SUMO - Simulation of Urban MObility
SUMOAbstractRouter.h
Go to the documentation of this file.
1 /****************************************************************************/
9 // An abstract router base class
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2006-2015 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 #ifndef SUMOAbstractRouter_h
23 #define SUMOAbstractRouter_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <string>
36 #include <vector>
37 #include <algorithm>
38 #include <assert.h>
39 #include <utils/common/SysUtils.h>
41 #include <utils/common/SUMOTime.h>
42 #include <utils/common/ToString.h>
43 
44 
45 // ===========================================================================
46 // class definitions
47 // ===========================================================================
52 template<class E, class V>
54 public:
56  typedef SUMOReal(* Operation)(const E* const, const V* const, SUMOReal);
57 
59  SUMOAbstractRouter(Operation operation, const std::string& type):
60  myOperation(operation),
61  myBulkMode(false),
62  myType(type),
63  myQueryVisits(0),
64  myNumQueries(0),
67  { }
68 
70  virtual ~SUMOAbstractRouter() {
71  if (myNumQueries > 0) {
72  WRITE_MESSAGE(myType + " answered " + toString(myNumQueries) + " queries and explored " + toString(double(myQueryVisits) / myNumQueries) + " edges on average.");
73  WRITE_MESSAGE(myType + " spent " + toString(myQueryTimeSum) + "ms answering queries (" + toString(double(myQueryTimeSum) / myNumQueries) + "ms on average).");
74  }
75  }
76 
77  virtual SUMOAbstractRouter* clone() const = 0;
78 
81  virtual void compute(const E* from, const E* to, const V* const vehicle,
82  SUMOTime msTime, std::vector<const E*>& into) = 0;
83 
84  virtual SUMOReal recomputeCosts(const std::vector<const E*>& edges,
85  const V* const v, SUMOTime msTime) const = 0;
86 
87  inline SUMOReal getEffort(const E* const e, const V* const v, SUMOReal t) const {
88  return (*myOperation)(e, v, t);
89  }
90 
91  inline void startQuery() {
92  myNumQueries++;
94  }
95 
96  inline void endQuery(int visits) {
97  myQueryVisits += visits;
99  }
100 
101  void setBulkMode(const bool mode) {
102  myBulkMode = mode;
103  }
104 
105 protected:
108 
111 
112 private:
114  const std::string myType;
115 
117  long long int myQueryVisits;
118  long long int myNumQueries;
120  long long int myQueryStartTime;
121  long long int myQueryTimeSum;
122 private:
125 };
126 
127 
128 template<class E, class V>
130 public:
131  inline bool operator()(const E* edge, const V* vehicle) const {
132  if (std::find(myProhibited.begin(), myProhibited.end(), edge) != myProhibited.end()) {
133  return true;
134  }
135  return edge->prohibits(vehicle);
136  }
137 
138  void prohibit(const std::vector<E*>& toProhibit) {
139  myProhibited = toProhibit;
140  }
141 
142 protected:
143  std::vector<E*> myProhibited;
144 
145 };
146 
147 template<class E, class V>
149 public:
150  inline bool operator()(const E*, const V*) const {
151  return false;
152  }
153 };
154 
155 
156 
157 
158 #endif
159 
160 /****************************************************************************/
161 
long long int SUMOTime
Definition: SUMOTime.h:43
std::vector< E * > myProhibited
long long int myQueryTimeSum
SUMOReal(* Operation)(const E *const, const V *const, SUMOReal)
Type of the function that is used to retrieve the edge effort.
virtual SUMOAbstractRouter * clone() const =0
bool operator()(const E *, const V *) const
bool myBulkMode
whether we are currently operating several route queries in a bulk
Operation myOperation
The object&#39;s operation to perform.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:53
long long int myQueryStartTime
the time spent querying in milliseconds
SUMOAbstractRouter & operator=(const SUMOAbstractRouter &s)
Invalidated assignment operator.
virtual ~SUMOAbstractRouter()
Destructor.
bool operator()(const E *edge, const V *vehicle) const
long long int myNumQueries
long long int myQueryVisits
counters for performance logging
void prohibit(const std::vector< E * > &toProhibit)
virtual SUMOReal recomputeCosts(const std::vector< const E * > &edges, const V *const v, SUMOTime msTime) const =0
#define SUMOReal
Definition: config.h:214
virtual void 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...
void endQuery(int visits)
static long getCurrentMillis()
Returns the current time in milliseconds.
Definition: SysUtils.cpp:50
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:201
SUMOReal getEffort(const E *const e, const V *const v, SUMOReal t) const
const std::string myType
the type of this router
SUMOAbstractRouter(Operation operation, const std::string &type)
Constructor.
void setBulkMode(const bool mode)