Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netbuild/NBDistrict.cpp
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 NBDistrict.cpp
15
/// @author Daniel Krajzewicz
16
/// @author Jakob Erdmann
17
/// @author Michael Behrisch
18
/// @date Sept 2002
19
///
20
// A class representing a single district
21
/****************************************************************************/
22
#include <config.h>
23
24
#include <cassert>
25
#include <vector>
26
#include <string>
27
#include <utility>
28
#include <iostream>
29
#include <algorithm>
30
#include <utils/common/Named.h>
31
#include <utils/common/StringUtils.h>
32
#include <utils/iodevices/OutputDevice.h>
33
#include "NBEdge.h"
34
#include "NBDistrict.h"
35
36
37
// ===========================================================================
38
// member method definitions
39
// ===========================================================================
40
NBDistrict::NBDistrict(const std::string& id, const Position& pos)
41
: Named(StringUtils::convertUmlaute(id)),
42
myPosition(pos) {}
43
44
45
NBDistrict::NBDistrict(const std::string& id)
46
: Named(id), myPosition(0, 0) {}
47
48
49
NBDistrict::~NBDistrict() {}
50
51
52
// ----------- Applying offset
53
void
54
NBDistrict::reshiftPosition(double xoff, double yoff) {
55
myPosition.add(xoff, yoff, 0);
56
myShape.add(xoff, yoff, 0);
57
}
58
59
60
void
61
NBDistrict::mirrorX() {
62
myPosition.mul(1, -1);
63
myShape.mirrorX();
64
}
65
66
67
bool
68
NBDistrict::addSource(NBEdge* const source, double weight) {
69
EdgeVector::iterator i = std::find(mySources.begin(), mySources.end(), source);
70
if (i != mySources.end()) {
71
return false;
72
}
73
mySources.push_back(source);
74
mySourceWeights.push_back(weight);
75
assert(source->getID() != "");
76
return true;
77
}
78
79
80
bool
81
NBDistrict::addSink(NBEdge* const sink, double weight) {
82
EdgeVector::iterator i = std::find(mySinks.begin(), mySinks.end(), sink);
83
if (i != mySinks.end()) {
84
return false;
85
}
86
mySinks.push_back(sink);
87
mySinkWeights.push_back(weight);
88
assert(sink->getID() != "");
89
return true;
90
}
91
92
93
void
94
NBDistrict::setCenter(const Position& pos) {
95
myPosition = pos;
96
}
97
98
99
void
100
NBDistrict::replaceIncoming(const EdgeVector& which, NBEdge* const by) {
101
// temporary structures
102
EdgeVector newList;
103
WeightsCont newWeights;
104
double joinedVal = 0;
105
// go through the list of sinks
106
EdgeVector::iterator i = mySinks.begin();
107
WeightsCont::iterator j = mySinkWeights.begin();
108
for (; i != mySinks.end(); i++, j++) {
109
NBEdge* tmp = (*i);
110
double val = (*j);
111
if (find(which.begin(), which.end(), tmp) == which.end()) {
112
// if the current edge shall not be replaced, add to the
113
// temporary list
114
newList.push_back(tmp);
115
newWeights.push_back(val);
116
} else {
117
// otherwise, skip it and add its weight to the one to be inserted
118
// instead
119
joinedVal += val;
120
}
121
}
122
// add the one to be inserted instead
123
newList.push_back(by);
124
newWeights.push_back(joinedVal);
125
// assign to values
126
mySinks = newList;
127
mySinkWeights = newWeights;
128
}
129
130
131
void
132
NBDistrict::replaceOutgoing(const EdgeVector& which, NBEdge* const by) {
133
// temporary structures
134
EdgeVector newList;
135
WeightsCont newWeights;
136
double joinedVal = 0;
137
// go through the list of sinks
138
EdgeVector::iterator i = mySources.begin();
139
WeightsCont::iterator j = mySourceWeights.begin();
140
for (; i != mySources.end(); i++, j++) {
141
NBEdge* tmp = (*i);
142
double val = (*j);
143
if (find(which.begin(), which.end(), tmp) == which.end()) {
144
// if the current edge shall not be replaced, add to the
145
// temporary list
146
newList.push_back(tmp);
147
newWeights.push_back(val);
148
} else {
149
// otherwise, skip it and add its weight to the one to be inserted
150
// instead
151
joinedVal += val;
152
}
153
}
154
// add the one to be inserted instead
155
newList.push_back(by);
156
newWeights.push_back(joinedVal);
157
// assign to values
158
mySources = newList;
159
mySourceWeights = newWeights;
160
}
161
162
163
void
164
NBDistrict::removeFromSinksAndSources(NBEdge* const e) {
165
int i;
166
for (i = 0; i < (int)mySinks.size(); ++i) {
167
if (mySinks[i] == e) {
168
mySinks.erase(mySinks.begin() + i);
169
mySinkWeights.erase(mySinkWeights.begin() + i);
170
}
171
}
172
for (i = 0; i < (int)mySources.size(); ++i) {
173
if (mySources[i] == e) {
174
mySources.erase(mySources.begin() + i);
175
mySourceWeights.erase(mySourceWeights.begin() + i);
176
}
177
}
178
}
179
180
181
void
182
NBDistrict::addShape(const PositionVector& p) {
183
myShape = p;
184
}
185
186
187
/****************************************************************************/
188
189