Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
NBDistrict.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 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/****************************************************************************/
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>
33#include "NBEdge.h"
34#include "NBDistrict.h"
35
36
37// ===========================================================================
38// member method definitions
39// ===========================================================================
40NBDistrict::NBDistrict(const std::string& id, const Position& pos)
41 : Named(StringUtils::convertUmlaute(id)),
42 myPosition(pos) {}
43
44
45NBDistrict::NBDistrict(const std::string& id)
46 : Named(id), myPosition(0, 0) {}
47
48
50
51
52// ----------- Applying offset
53void
54NBDistrict::reshiftPosition(double xoff, double yoff) {
55 myPosition.add(xoff, yoff, 0);
56 myShape.add(xoff, yoff, 0);
57}
58
59
60void
65
66
67bool
68NBDistrict::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
80bool
81NBDistrict::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
93void
95 myPosition = pos;
96}
97
98
99void
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
131void
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
163void
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
181void
185
186
187/****************************************************************************/
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition NBCont.h:42
bool addSink(NBEdge *const sink, double weight)
Adds a sink.
Position myPosition
The position of the district.
Definition NBDistrict.h:252
std::vector< double > WeightsCont
Definition of a vector of connection weights.
Definition NBDistrict.h:237
void mirrorX()
mirror coordinates along the x-axis
NBDistrict(const std::string &id, const Position &pos)
Constructor with id, and position.
void replaceIncoming(const EdgeVector &which, NBEdge *const by)
Replaces incoming edges from the vector (sinks) by the given edge.
EdgeVector mySources
The sources (connection from district to network)
Definition NBDistrict.h:240
void addShape(const PositionVector &p)
Sets the shape of this district.
bool addSource(NBEdge *const source, double weight)
Adds a source.
EdgeVector mySinks
The sinks (connection from network to district)
Definition NBDistrict.h:246
void replaceOutgoing(const EdgeVector &which, NBEdge *const by)
Replaces outgoing edges from the vector (source) by the given edge.
void reshiftPosition(double xoff, double yoff)
Applies an offset to the district.
~NBDistrict()
Destructor.
WeightsCont mySourceWeights
The weights of the sources.
Definition NBDistrict.h:243
void setCenter(const Position &pos)
Sets the center coordinates.
PositionVector myShape
The shape of the dsitrict.
Definition NBDistrict.h:255
WeightsCont mySinkWeights
The weights of the sinks.
Definition NBDistrict.h:249
void removeFromSinksAndSources(NBEdge *const e)
Removes the given edge from the lists of sources and sinks.
The representation of a single edge during network building.
Definition NBEdge.h:92
const std::string & getID() const
Definition NBEdge.h:1528
Base class for objects which have an id.
Definition Named.h:54
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
void add(const Position &pos)
Adds the given position to this one.
Definition Position.h:132
void mul(double val)
Multiplies position with the given value.
Definition Position.h:105
A list of positions.
void add(double xoff, double yoff, double zoff)
Some static methods for string processing.
Definition StringUtils.h:40