Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/router/CHRouterWrapper.h
169678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
4
// This program and the accompanying materials are made available under the
5
// terms of the Eclipse Public License 2.0 which is available at
6
// https://www.eclipse.org/legal/epl-2.0/
7
// This Source Code may also be made available under the following Secondary
8
// Licenses when the conditions for such availability set forth in the Eclipse
9
// Public License 2.0 are satisfied: GNU General Public License, version 2
10
// or later which is available at
11
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
/****************************************************************************/
14
/// @file CHRouterWrapper.h
15
/// @author Jakob Erdmann
16
/// @author Laura Bieker
17
/// @author Michael Behrisch
18
/// @date March 2012
19
///
20
// Wraps multiple CHRouters for different vehicle types
21
/****************************************************************************/
22
#pragma once
23
#include <config.h>
24
25
#include <string>
26
#include <functional>
27
#include <vector>
28
#include <set>
29
#include <limits>
30
#include <algorithm>
31
#include <iterator>
32
#include <utils/common/SysUtils.h>
33
#include <utils/common/MsgHandler.h>
34
#include <utils/common/StdDefs.h>
35
#include <utils/router/SUMOAbstractRouter.h>
36
#include <utils/common/SUMOVehicleClass.h>
37
#include "CHRouter.h"
38
39
#ifdef HAVE_FOX
40
#include <utils/foxtools/MFXWorkerThread.h>
41
#endif
42
43
44
// ===========================================================================
45
// class definitions
46
// ===========================================================================
47
/**
48
* @class CHRouterWrapper
49
* @brief Computes the shortest path through a contracted network
50
*
51
* The template parameters are:
52
* @param E The edge class to use (MSEdge/ROEdge)
53
* @param V The vehicle class to use (MSVehicle/ROVehicle)
54
*
55
* The router is edge-based. It must know the number of edges for internal reasons
56
* and whether a missing connection between two given edges (unbuild route) shall
57
* be reported as an error or as a warning.
58
*
59
*/
60
template<class E, class V>
61
class CHRouterWrapper: public SUMOAbstractRouter<E, V> {
62
63
public:
64
/** @brief Constructor
65
*/
66
CHRouterWrapper(const std::vector<E*>& edges, const bool ignoreErrors, typename SUMOAbstractRouter<E, V>::Operation operation,
67
const SUMOTime begin, const SUMOTime end, const SUMOTime weightPeriod, bool havePermissions, const int numThreads) :
68
SUMOAbstractRouter<E, V>("CHRouterWrapper", ignoreErrors, operation, nullptr, havePermissions, false),
69
myEdges(edges),
70
myIgnoreErrors(ignoreErrors),
71
myBegin(begin),
72
myEnd(end),
73
myWeightPeriod(weightPeriod),
74
myMaxNumInstances(numThreads) {
75
}
76
77
~CHRouterWrapper() {
78
for (typename RouterMap::iterator i = myRouters.begin(); i != myRouters.end(); ++i) {
79
delete i->second;
80
}
81
}
82
83
virtual void prohibit(const std::map<const E*, double>& toProhibit) {
84
if (toProhibit.size() > 0) {
85
WRITE_WARNINGF(TL("Routing algorithm CHWrapper does not support dynamic closing of edges%"), "");
86
}
87
}
88
89
virtual SUMOAbstractRouter<E, V>* clone() {
90
CHRouterWrapper<E, V>* clone = new CHRouterWrapper<E, V>(myEdges, myIgnoreErrors, this->myOperation, myBegin, myEnd, myWeightPeriod, this->myHavePermissions, myMaxNumInstances);
91
for (const auto& item : myRouters) {
92
clone->myRouters[item.first] = static_cast<CHRouterType*>(item.second->clone());
93
}
94
return clone;
95
}
96
97
98
bool compute(const E* from, const E* to, const V* const vehicle,
99
SUMOTime msTime, std::vector<const E*>& into, bool silent = false) {
100
const std::pair<const SUMOVehicleClass, const double> svc = std::make_pair(vehicle->getVClass(), vehicle->getMaxSpeed());
101
if (myRouters.count(svc) == 0) {
102
// create new router for the given permissions and maximum speed
103
// XXX a new router may also be needed if vehicles differ in speed factor
104
myRouters[svc] = new CHRouterType(myEdges, myIgnoreErrors, this->myOperation, svc.first, myWeightPeriod, false, false);
105
}
106
return myRouters[svc]->compute(from, to, vehicle, msTime, into, silent);
107
}
108
109
110
private:
111
typedef CHRouter<E, V> CHRouterType;
112
113
private:
114
typedef std::map<std::pair<const SUMOVehicleClass, const double>, CHRouterType*> RouterMap;
115
116
RouterMap myRouters;
117
118
/// @brief all edges with numerical ids
119
const std::vector<E*>& myEdges;
120
121
const bool myIgnoreErrors;
122
123
const SUMOTime myBegin;
124
const SUMOTime myEnd;
125
const SUMOTime myWeightPeriod;
126
const int myMaxNumInstances;
127
};
128
129