SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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-sim.org/
12 // Copyright (C) 2006-2014 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  SUMOAbstractRouter(const std::string& type):
57  myType(type),
58  myQueryVisits(0),
59  myNumQueries(0),
62  { }
63 
65  virtual ~SUMOAbstractRouter() {
66  if (myNumQueries > 0) {
67  WRITE_MESSAGE(myType + " answered " + toString(myNumQueries) + " queries and explored " + toString(double(myQueryVisits) / myNumQueries) + " edges on average.");
68  WRITE_MESSAGE(myType + " spent " + toString(myQueryTimeSum) + " ms answering queries (" + toString(double(myQueryTimeSum) / myNumQueries) + " ms on average).");
69  }
70  }
71 
74  virtual void compute(const E* from, const E* to, const V* const vehicle,
75  SUMOTime msTime, std::vector<const E*>& into) = 0;
76 
77  virtual SUMOReal recomputeCosts(const std::vector<const E*>& edges,
78  const V* const v, SUMOTime msTime) const = 0;
79 
80  // interface extension for BulkStarRouter
81  virtual void prepare(const E*, const V*, bool) {
82  assert(false);
83  }
84 
85  inline void startQuery() {
86  myNumQueries++;
88  }
89 
90  inline void endQuery(int visits) {
91  myQueryVisits += visits;
93  }
94 
95 private:
97  const std::string myType;
104 private:
107 };
108 
109 
110 template<class E, class V>
112 public:
113  inline bool operator()(const E* edge, const V* vehicle) const {
114  if (std::find(myProhibited.begin(), myProhibited.end(), edge) != myProhibited.end()) {
115  return true;
116  }
117  return edge->prohibits(vehicle);
118  }
119 
120  void prohibit(const std::vector<E*>& toProhibit) {
121  myProhibited = toProhibit;
122  }
123 
124 protected:
125  std::vector<E*> myProhibited;
126 
127 };
128 
129 template<class E, class V>
131 public:
132  inline bool operator()(const E*, const V*) const {
133  return false;
134  }
135 };
136 
137 
138 
139 
140 #endif
141 
142 /****************************************************************************/
143