Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/dfrouter/RODFRouteCont.cpp
169665 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.cpp
15
/// @author Daniel Krajzewicz
16
/// @author Laura Bieker
17
/// @author Michael Behrisch
18
/// @date Thu, 16.03.2006
19
///
20
// A container for routes
21
/****************************************************************************/
22
#include <config.h>
23
24
#include <fstream>
25
#include <cassert>
26
#include "RODFRouteDesc.h"
27
#include "RODFRouteCont.h"
28
#include "RODFNet.h"
29
#include <router/ROEdge.h>
30
#include <utils/common/ToString.h>
31
#include <utils/iodevices/OutputDevice.h>
32
33
34
// ===========================================================================
35
// method definitions
36
// ===========================================================================
37
RODFRouteCont::RODFRouteCont() {}
38
39
40
RODFRouteCont::~RODFRouteCont() {
41
}
42
43
44
void
45
RODFRouteCont::addRouteDesc(RODFRouteDesc& desc) {
46
// routes may be duplicate as in-between routes may have different starting points
47
if (find_if(myRoutes.begin(), myRoutes.end(), route_finder(desc)) == myRoutes.end()) {
48
// compute route id
49
setID(desc);
50
myRoutes.push_back(desc);
51
} else {
52
RODFRouteDesc& prev = *find_if(myRoutes.begin(), myRoutes.end(), route_finder(desc));
53
prev.overallProb += desc.overallProb;
54
}
55
}
56
57
58
bool
59
RODFRouteCont::removeRouteDesc(RODFRouteDesc& desc) {
60
std::vector<RODFRouteDesc>::const_iterator j = find_if(myRoutes.begin(), myRoutes.end(), route_finder(desc));
61
if (j == myRoutes.end()) {
62
return false;
63
}
64
return true;
65
}
66
67
68
bool
69
RODFRouteCont::save(std::vector<std::string>& saved,
70
const std::string& prependix, OutputDevice& out) {
71
bool haveSavedOneAtLeast = false;
72
for (std::vector<RODFRouteDesc>::const_iterator j = myRoutes.begin(); j != myRoutes.end(); ++j) {
73
const RODFRouteDesc& desc = (*j);
74
if (find(saved.begin(), saved.end(), desc.routename) != saved.end()) {
75
continue;
76
}
77
saved.push_back((*j).routename);
78
assert(desc.edges2Pass.size() >= 1);
79
out.openTag(SUMO_TAG_ROUTE).writeAttr(SUMO_ATTR_ID, prependix + desc.routename);
80
out << " edges=\"";
81
for (ROEdgeVector::const_iterator k = desc.edges2Pass.begin(); k != desc.edges2Pass.end(); k++) {
82
if (k != desc.edges2Pass.begin()) {
83
out << ' ';
84
}
85
out << (*k)->getID();
86
}
87
out << '"';
88
out.closeTag();
89
haveSavedOneAtLeast = true;
90
}
91
return haveSavedOneAtLeast;
92
}
93
94
95
void
96
RODFRouteCont::sortByDistance() {
97
sort(myRoutes.begin(), myRoutes.end(), by_distance_sorter());
98
}
99
100
101
void
102
RODFRouteCont::removeIllegal(const std::vector<ROEdgeVector >& illegals) {
103
for (std::vector<RODFRouteDesc>::iterator i = myRoutes.begin(); i != myRoutes.end();) {
104
RODFRouteDesc& desc = *i;
105
bool remove = false;
106
for (std::vector<ROEdgeVector >::const_iterator j = illegals.begin(); !remove && j != illegals.end(); ++j) {
107
int noFound = 0;
108
for (ROEdgeVector::const_iterator k = (*j).begin(); !remove && k != (*j).end(); ++k) {
109
if (find(desc.edges2Pass.begin(), desc.edges2Pass.end(), *k) != desc.edges2Pass.end()) {
110
noFound++;
111
if (noFound > 1) {
112
remove = true;
113
}
114
}
115
}
116
}
117
if (remove) {
118
i = myRoutes.erase(i);
119
} else {
120
++i;
121
}
122
}
123
}
124
125
126
void
127
RODFRouteCont::setID(RODFRouteDesc& desc) const {
128
std::pair<ROEdge*, ROEdge*> c(desc.edges2Pass[0], desc.edges2Pass.back());
129
desc.routename = c.first->getID() + "_to_" + c.second->getID();
130
if (myConnectionOccurrences.find(c) == myConnectionOccurrences.end()) {
131
myConnectionOccurrences[c] = 0;
132
} else {
133
myConnectionOccurrences[c] = myConnectionOccurrences[c] + 1;
134
desc.routename = desc.routename + "_" + toString(myConnectionOccurrences[c]);
135
}
136
}
137
138
139
/****************************************************************************/
140
141