SUMO - Simulation of Urban MObility
CHRouterWrapper.h
Go to the documentation of this file.
1 /****************************************************************************/
9 // Wraps multiple CHRouters for different vehicle types
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-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 CHRouterWrapper_h
23 #define CHRouterWrapper_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 <functional>
37 #include <vector>
38 #include <set>
39 #include <limits>
40 #include <algorithm>
41 #include <iterator>
42 #include <utils/common/SysUtils.h>
44 #include <utils/common/StdDefs.h>
47 #include "CHRouter.h"
48 
49 
50 // ===========================================================================
51 // class definitions
52 // ===========================================================================
67 template<class E, class V, class PF>
68 class CHRouterWrapper: public SUMOAbstractRouter<E, V>, public PF {
69 
70 public:
72  typedef SUMOReal(* Operation)(const E* const, const V* const, SUMOReal);
73 
76  CHRouterWrapper(size_t dictSize, bool ignoreErrors, Operation operation, SUMOTime begin, SUMOTime weightPeriod):
77  SUMOAbstractRouter<E, V>(operation, "CHRouterWrapper"),
78  myDictSize(dictSize),
79  myIgnoreErrors(ignoreErrors),
80  myBegin(begin),
81  myWeightPeriod(weightPeriod)
82  {}
83 
85  for (typename RouterMap::iterator i = myRouters.begin(); i != myRouters.end(); ++i) {
86  delete(*i).second;
87  }
88  }
89 
90 
91  virtual SUMOAbstractRouter<E, V>* clone() const {
93  }
94 
95  void compute(const E* from, const E* to, const V* const vehicle,
96  SUMOTime msTime, std::vector<const E*>& into) {
97  const std::pair<const SUMOVehicleClass, const SUMOReal> svc = std::make_pair(vehicle->getVClass(), vehicle->getMaxSpeed());
98  if (myRouters.count(svc) == 0) {
99  // create new router for the given permissions and maximum speed
100  // XXX a new router may also be needed if vehicles differ in speed factor
101  myRouters[svc] = new CHRouterType(
102  myDictSize, myIgnoreErrors, &E::getTravelTimeStatic, svc.first, myWeightPeriod, false);
103  }
104  myRouters[svc]->compute(from, to, vehicle, msTime, into);
105  }
106 
107 
108  SUMOReal recomputeCosts(const std::vector<const E*>& edges,
109  const V* const v, SUMOTime msTime) const {
110  const SUMOReal time = STEPS2TIME(msTime);
111  SUMOReal costs = 0;
112  for (typename std::vector<const E*>::const_iterator i = edges.begin(); i != edges.end(); ++i) {
113  if (PF::operator()(*i, v)) {
114  WRITE_WARNING("Vehicle '" + v->getID() + "' is restricted from using its assigned route.");
115  return -1;
116  }
117  costs += this->getEffort(*i, v, time + costs);
118  }
119  return costs;
120  }
121 
122 
123 private:
125  typedef std::map<std::pair<const SUMOVehicleClass, const SUMOReal>, CHRouterType*> RouterMap;
126 
127  RouterMap myRouters;
128 
130  size_t myDictSize;
131 
133 
136 };
137 
138 
139 #endif
140 
141 /****************************************************************************/
142 
Computes the shortest path through a contracted network.
Definition: CHRouter.h:74
long long int SUMOTime
Definition: SUMOTime.h:43
SUMOTime myWeightPeriod
std::map< std::pair< const SUMOVehicleClass, const SUMOReal >, CHRouterType * > RouterMap
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
CHRouterWrapper(size_t dictSize, bool ignoreErrors, Operation operation, SUMOTime begin, SUMOTime weightPeriod)
Constructor.
virtual SUMOAbstractRouter< E, V > * clone() const
SUMOReal(* Operation)(const E *const, const V *const, SUMOReal)
Type of the function that is used to retrieve the edge effort.
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
Operation myOperation
The object&#39;s operation to perform.
size_t myDictSize
number of edges with numerical id
CHRouter< E, V, noProhibitions< E, V > > CHRouterType
#define SUMOReal
Definition: config.h:214
SUMOReal getEffort(const E *const e, const V *const v, SUMOReal t) const
SUMOReal recomputeCosts(const std::vector< const E * > &edges, const V *const v, SUMOTime msTime) const
void compute(const E *from, const E *to, const V *const vehicle, SUMOTime msTime, std::vector< const E * > &into)
Builds the route between the given edges using the minimum effort at the given time The definition of...
Computes the shortest path through a contracted network.