Eclipse SUMO - Simulation of Urban MObility
CHRouterWrapper.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
16 // Wraps multiple CHRouters for different vehicle types
17 /****************************************************************************/
18 #ifndef CHRouterWrapper_h
19 #define CHRouterWrapper_h
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <string>
28 #include <functional>
29 #include <vector>
30 #include <set>
31 #include <limits>
32 #include <algorithm>
33 #include <iterator>
34 #include <utils/common/SysUtils.h>
36 #include <utils/common/StdDefs.h>
39 #include "CHRouter.h"
40 
41 #ifdef HAVE_FOX
43 #endif
44 
45 
46 // ===========================================================================
47 // class definitions
48 // ===========================================================================
62 template<class E, class V>
63 class CHRouterWrapper: public SUMOAbstractRouter<E, V> {
64 
65 public:
68  CHRouterWrapper(const std::vector<E*>& edges, const bool ignoreErrors, typename SUMOAbstractRouter<E, V>::Operation operation,
69  const SUMOTime begin, const SUMOTime end, const SUMOTime weightPeriod, const int numThreads) :
70  SUMOAbstractRouter<E, V>("CHRouterWrapper", ignoreErrors, operation, nullptr, false, false),
71  myEdges(edges),
72  myIgnoreErrors(ignoreErrors),
73  myBegin(begin),
74  myEnd(end),
75  myWeightPeriod(weightPeriod),
76  myMaxNumInstances(numThreads) {
77  }
78 
80  for (typename RouterMap::iterator i = myRouters.begin(); i != myRouters.end(); ++i) {
81  delete i->second;
82  }
83  }
84 
85 
88  for (const auto& item : myRouters) {
89  clone->myRouters[item.first] = static_cast<CHRouterType*>(item.second->clone());
90  }
91  return clone;
92  }
93 
94 
95  bool compute(const E* from, const E* to, const V* const vehicle,
96  SUMOTime msTime, std::vector<const E*>& into, bool silent = false) {
97  const std::pair<const SUMOVehicleClass, const double> 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  myEdges, myIgnoreErrors, &E::getTravelTimeStatic, svc.first, myWeightPeriod, false, false);
103  }
104  return myRouters[svc]->compute(from, to, vehicle, msTime, into, silent);
105  }
106 
107 
108 private:
110 
111 private:
112  typedef std::map<std::pair<const SUMOVehicleClass, const double>, CHRouterType*> RouterMap;
113 
115 
117  const std::vector<E*>& myEdges;
118 
119  const bool myIgnoreErrors;
120 
124  const int myMaxNumInstances;
125 };
126 
127 
128 #endif
129 
130 /****************************************************************************/
131 
CHRouterWrapper::CHRouterWrapper
CHRouterWrapper(const std::vector< E * > &edges, const bool ignoreErrors, typename SUMOAbstractRouter< E, V >::Operation operation, const SUMOTime begin, const SUMOTime end, const SUMOTime weightPeriod, const int numThreads)
Constructor.
Definition: CHRouterWrapper.h:68
CHRouterWrapper::CHRouterType
CHRouter< E, V > CHRouterType
Definition: CHRouterWrapper.h:109
MsgHandler.h
CHRouterWrapper::~CHRouterWrapper
~CHRouterWrapper()
Definition: CHRouterWrapper.h:79
CHRouterWrapper::compute
bool compute(const E *from, const E *to, const V *const vehicle, SUMOTime msTime, std::vector< const E * > &into, bool silent=false)
Builds the route between the given edges using the minimum effort at the given time The definition of...
Definition: CHRouterWrapper.h:95
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
SUMOAbstractRouter::myOperation
Operation myOperation
The object's operation to perform.
Definition: SUMOAbstractRouter.h:239
CHRouter.h
CHRouterWrapper::RouterMap
std::map< std::pair< const SUMOVehicleClass, const double >, CHRouterType * > RouterMap
Definition: CHRouterWrapper.h:112
CHRouterWrapper::myBegin
const SUMOTime myBegin
Definition: CHRouterWrapper.h:121
SysUtils.h
SUMOVehicleClass.h
CHRouterWrapper
Computes the shortest path through a contracted network.
Definition: CHRouterWrapper.h:63
FXWorkerThread.h
CHRouterWrapper::myEdges
const std::vector< E * > & myEdges
all edges with numerical ids
Definition: CHRouterWrapper.h:117
CHRouterWrapper::clone
virtual SUMOAbstractRouter< E, V > * clone()
Definition: CHRouterWrapper.h:86
SUMOAbstractRouter
Definition: SUMOAbstractRouter.h:46
CHRouter
Computes the shortest path through a contracted network.
Definition: CHRouter.h:61
CHRouterWrapper::myMaxNumInstances
const int myMaxNumInstances
Definition: CHRouterWrapper.h:124
CHRouterWrapper::myIgnoreErrors
const bool myIgnoreErrors
Definition: CHRouterWrapper.h:119
config.h
CHRouterWrapper::myWeightPeriod
const SUMOTime myWeightPeriod
Definition: CHRouterWrapper.h:123
CHRouterWrapper::myEnd
const SUMOTime myEnd
Definition: CHRouterWrapper.h:122
StdDefs.h
SUMOAbstractRouter.h
CHRouterWrapper::myRouters
RouterMap myRouters
Definition: CHRouterWrapper.h:114