Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/dfrouter/RODFRouteCont.h
169666 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 RODFRouteCont.h
15
/// @author Daniel Krajzewicz
16
/// @author Michael Behrisch
17
/// @date Thu, 16.03.2006
18
///
19
// A container for routes
20
/****************************************************************************/
21
#pragma once
22
#include <config.h>
23
24
#include <vector>
25
#include <map>
26
#include <utils/common/UtilExceptions.h>
27
#include "RODFRouteDesc.h"
28
29
30
// ===========================================================================
31
// class declarations
32
// ===========================================================================
33
class RODFNet;
34
class OutputDevice;
35
36
37
// ===========================================================================
38
// class definitions
39
// ===========================================================================
40
/**
41
* @class RODFRouteCont
42
* @brief A container for DFROUTER-routes
43
*
44
* The route id is (re)set as soon as the route is added.
45
*
46
* As sometimes several routes can be used between two edges and have to be
47
* identified, the number of routes connecting them is stored for each
48
* edge pair "myConnectionOccurrences" and the route is named using this
49
* information, @see addRouteDesc.
50
*
51
* @see RODFRouteDesc
52
*/
53
class RODFRouteCont {
54
public:
55
/// @brief Constructor
56
RODFRouteCont();
57
58
/// @brief Destructor
59
~RODFRouteCont();
60
61
62
/** @brief Adds a route to the container
63
*
64
* If the same route is already known, its "overallProb" is increased
65
* by the value stored in the given route.
66
*
67
* An id for the route is generated if it is unset, yet. The id is
68
* computed and set via "setID".
69
*
70
* @param[in] desc The route description to add
71
* @see setID
72
*/
73
void addRouteDesc(RODFRouteDesc& desc);
74
75
76
/** @brief Removes the given route description from the container
77
*
78
* All routes are regarded as being same if they pass the same edges.
79
* This is done via the "route_finder".
80
*
81
* @param[in] desc The route description to remove
82
* @return Whether the route was removed (a similar was found)
83
* @see RODFRouteCont::route_finder
84
*/
85
bool removeRouteDesc(RODFRouteDesc& desc);
86
87
88
/** @brief Saves routes
89
*
90
* @param[in, out] saved The list of ids of routes that shall not be saved (were saved before)
91
* @param[in] prependix The prependix for route names
92
* @param[out] out The device the routes shall written to
93
* @return Whether at least one route was saved
94
* @exception IOError not yet implemented
95
*/
96
bool save(std::vector<std::string>& saved,
97
const std::string& prependix, OutputDevice& out);
98
99
100
/** @brief Returns the container of stored routes
101
* @return The stored routes
102
*/
103
std::vector<RODFRouteDesc>& get() {
104
return myRoutes;
105
}
106
107
108
/** @brief Sorts routes by their distance (length)
109
*
110
* Done using by_distance_sorter.
111
* @see RODFRouteCont::by_distance_sorter
112
*/
113
void sortByDistance();
114
115
116
/** @brief Removes "illegal" routes
117
*
118
* "illegal" routes means edge combinations that shall not be passed.
119
*
120
* @param[in] illegals List of edge combinations that shall not be passed
121
* @todo Not used, yet
122
*/
123
void removeIllegal(const std::vector<ROEdgeVector >& illegals);
124
125
126
protected:
127
/** @brief Computes and sets the id of a route
128
*
129
* The id is <FIRST_EDGE>_to_<LAST_EDGE>_<RUNNING> where <RUNNING>
130
* is the number of routes which connect <FIRST_EDGE> and <LAST_EDGE>.
131
*
132
* @param[in] desc The route description to add
133
*/
134
void setID(RODFRouteDesc& desc) const;
135
136
137
/** @brief A class for sorting route descriptions by their length */
138
class by_distance_sorter {
139
public:
140
/// @brief Constructor
141
explicit by_distance_sorter() { }
142
143
/// @brief Sorting function; compares RODFRouteDesc::distance2Last
144
int operator()(const RODFRouteDesc& p1, const RODFRouteDesc& p2) {
145
return p1.distance2Last < p2.distance2Last;
146
}
147
};
148
149
150
/** @brief A class for finding a same route (one that passes the same edges) */
151
class route_finder {
152
public:
153
/** @brief onstructor
154
* @param[in] desc The route description to which a same shall be found
155
*/
156
explicit route_finder(const RODFRouteDesc& desc) : myDesc(desc) { }
157
158
/** @brief The comparing function; compares passed edges */
159
bool operator()(const RODFRouteDesc& desc) {
160
return myDesc.edges2Pass == desc.edges2Pass;
161
}
162
163
private:
164
/// @brief The route description for which a same shall be found
165
const RODFRouteDesc& myDesc;
166
};
167
168
protected:
169
/// @brief Stored route descriptions
170
std::vector<RODFRouteDesc> myRoutes;
171
172
/// @brief Counts how many routes connecting the key-edges were already stored
173
mutable std::map<std::pair<ROEdge*, ROEdge*>, int> myConnectionOccurrences;
174
175
176
};
177
178