SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SUMOAbstractRouter.h
Go to the documentation of this file.
1 /****************************************************************************/
9 // The dijkstra-router
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  myType(type),
62  myQueryVisits(0),
63  myNumQueries(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() const = 0;
77 
80  virtual void compute(const E* from, const E* to, const V* const vehicle,
81  SUMOTime msTime, std::vector<const E*>& into) = 0;
82 
83  virtual SUMOReal recomputeCosts(const std::vector<const E*>& edges,
84  const V* const v, SUMOTime msTime) const = 0;
85 
86  // interface extension for BulkStarRouter
87  virtual void prepare(const E*, const V*, bool) {
88  assert(false);
89  }
90 
91  inline SUMOReal getEffort(const E* const e, const V* const v, SUMOReal t) const {
92  return (*myOperation)(e, v, t);
93  }
94 
95  inline void startQuery() {
96  myNumQueries++;
98  }
99 
100  inline void endQuery(int visits) {
101  myQueryVisits += visits;
103  }
104 
105 protected:
108 
109 private:
111  const std::string myType;
112 
119 private:
122 };
123 
124 
125 template<class E, class V>
127 public:
128  inline bool operator()(const E* edge, const V* vehicle) const {
129  if (std::find(myProhibited.begin(), myProhibited.end(), edge) != myProhibited.end()) {
130  return true;
131  }
132  return edge->prohibits(vehicle);
133  }
134 
135  void prohibit(const std::vector<E*>& toProhibit) {
136  myProhibited = toProhibit;
137  }
138 
139 protected:
140  std::vector<E*> myProhibited;
141 
142 };
143 
144 template<class E, class V>
146 public:
147  inline bool operator()(const E*, const V*) const {
148  return false;
149  }
150 };
151 
152 
153 
154 
155 #endif
156 
157 /****************************************************************************/
158 
SUMOLong myQueryStartTime
the time spent querying in milliseconds
bool operator()(const E *, const V *) const
virtual SUMOAbstractRouter * clone() const =0
SUMOReal(* Operation)(const E *const, const V *const, SUMOReal)
Type of the function that is used to retrieve the edge effort.
void prohibit(const std::vector< E * > &toProhibit)
virtual void prepare(const E *, const V *, bool)
#define SUMOLong
Definition: config.h:215
Operation myOperation
The object's operation to perform.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:53
SUMOAbstractRouter & operator=(const SUMOAbstractRouter &s)
Invalidated assignment operator.
virtual ~SUMOAbstractRouter()
Destructor.
bool operator()(const E *edge, const V *vehicle) const
int SUMOTime
Definition: SUMOTime.h:43
SUMOLong myQueryVisits
counters for performance logging
virtual SUMOReal recomputeCosts(const std::vector< const E * > &edges, const V *const v, SUMOTime msTime) const =0
#define SUMOReal
Definition: config.h:218
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.