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 /****************************************************************************/
8 // The dijkstra-router
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
11 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
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  SUMOAbstractRouter(const std::string& type):
56  myType(type),
57  myQueryVisits(0),
58  myNumQueries(0),
61  { }
62 
64  virtual ~SUMOAbstractRouter() {
65  if (myNumQueries > 0) {
66  WRITE_MESSAGE(myType + " answered " + toString(myNumQueries) + " queries and explored " + toString(double(myQueryVisits) / myNumQueries) + " edges on average.");
67  WRITE_MESSAGE(myType + " spent " + toString(myQueryTimeSum) + " ms answering queries (" + toString(double(myQueryTimeSum) / myNumQueries) + " ms on average).");
68  }
69  }
70 
73  virtual void compute(const E* from, const E* to, const V* const vehicle,
74  SUMOTime msTime, std::vector<const E*>& into) = 0;
75 
76  virtual SUMOReal recomputeCosts(const std::vector<const E*>& edges,
77  const V* const v, SUMOTime msTime) const = 0;
78 
79  // interface extension for BulkStarRouter
80  virtual void prepare(const E*, const V*, bool) {
81  assert(false);
82  }
83 
84  inline void startQuery() {
85  myNumQueries++;
87  }
88 
89  inline void endQuery(int visits) {
90  myQueryVisits += visits;
92  }
93 
94 private:
96  const std::string myType;
103 private:
106 };
107 
108 
109 template<class E, class V>
111 public:
112  inline bool operator()(const E* edge, const V* vehicle) const {
113  if (std::find(myProhibited.begin(), myProhibited.end(), edge) != myProhibited.end()) {
114  return true;
115  }
116  return edge->prohibits(vehicle);
117  }
118 
119  void prohibit(const std::vector<E*>& toProhibit) {
120  myProhibited = toProhibit;
121  }
122 
123 protected:
124  std::vector<E*> myProhibited;
125 
126 };
127 
128 template<class E, class V>
130 public:
131  inline bool operator()(const E*, const V*) const {
132  return false;
133  }
134 };
135 
136 
137 
138 
139 #endif
140 
141 /****************************************************************************/
142 
bool operator()(const E *, const V *) const
SUMOAbstractRouter(const std::string &type)
Constructor.
int myQueryVisits
counters for performance logging
long myQueryStartTime
the time spent querying in milliseconds
void prohibit(const std::vector< E * > &toProhibit)
virtual void prepare(const E *, const V *, bool)
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:51
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
virtual SUMOReal recomputeCosts(const std::vector< const E * > &edges, const V *const v, SUMOTime msTime) const =0
#define SUMOReal
Definition: config.h:215
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:48
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:197
const std::string myType
the type of this router