Eclipse SUMO - Simulation of Urban MObility
NBDistrict.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
16 // A class representing a single district
17 /****************************************************************************/
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #include <cassert>
26 #include <vector>
27 #include <string>
28 #include <utility>
29 #include <iostream>
30 #include <algorithm>
31 #include <utils/common/Named.h>
34 #include "NBEdge.h"
35 #include "NBDistrict.h"
36 
37 
38 // ===========================================================================
39 // member method definitions
40 // ===========================================================================
41 NBDistrict::NBDistrict(const std::string& id, const Position& pos)
42  : Named(StringUtils::convertUmlaute(id)),
43  myPosition(pos) {}
44 
45 
46 NBDistrict::NBDistrict(const std::string& id)
47  : Named(id), myPosition(0, 0) {}
48 
49 
51 
52 
53 // ----------- Applying offset
54 void
55 NBDistrict::reshiftPosition(double xoff, double yoff) {
56  myPosition.add(xoff, yoff, 0);
57  myShape.add(xoff, yoff, 0);
58 }
59 
60 
61 void
63  myPosition.mul(1, -1);
64  myShape.mirrorX();
65 }
66 
67 
68 bool
69 NBDistrict::addSource(NBEdge* const source, double weight) {
70  EdgeVector::iterator i = std::find(mySources.begin(), mySources.end(), source);
71  if (i != mySources.end()) {
72  return false;
73  }
74  mySources.push_back(source);
75  mySourceWeights.push_back(weight);
76  assert(source->getID() != "");
77  return true;
78 }
79 
80 
81 bool
82 NBDistrict::addSink(NBEdge* const sink, double weight) {
83  EdgeVector::iterator i = std::find(mySinks.begin(), mySinks.end(), sink);
84  if (i != mySinks.end()) {
85  return false;
86  }
87  mySinks.push_back(sink);
88  mySinkWeights.push_back(weight);
89  assert(sink->getID() != "");
90  return true;
91 }
92 
93 
94 void
96  myPosition = pos;
97 }
98 
99 
100 void
102  // temporary structures
103  EdgeVector newList;
104  WeightsCont newWeights;
105  double joinedVal = 0;
106  // go through the list of sinks
107  EdgeVector::iterator i = mySinks.begin();
108  WeightsCont::iterator j = mySinkWeights.begin();
109  for (; i != mySinks.end(); i++, j++) {
110  NBEdge* tmp = (*i);
111  double val = (*j);
112  if (find(which.begin(), which.end(), tmp) == which.end()) {
113  // if the current edge shall not be replaced, add to the
114  // temporary list
115  newList.push_back(tmp);
116  newWeights.push_back(val);
117  } else {
118  // otherwise, skip it and add its weight to the one to be inserted
119  // instead
120  joinedVal += val;
121  }
122  }
123  // add the one to be inserted instead
124  newList.push_back(by);
125  newWeights.push_back(joinedVal);
126  // assign to values
127  mySinks = newList;
128  mySinkWeights = newWeights;
129 }
130 
131 
132 void
134  // temporary structures
135  EdgeVector newList;
136  WeightsCont newWeights;
137  double joinedVal = 0;
138  // go through the list of sinks
139  EdgeVector::iterator i = mySources.begin();
140  WeightsCont::iterator j = mySourceWeights.begin();
141  for (; i != mySources.end(); i++, j++) {
142  NBEdge* tmp = (*i);
143  double val = (*j);
144  if (find(which.begin(), which.end(), tmp) == which.end()) {
145  // if the current edge shall not be replaced, add to the
146  // temporary list
147  newList.push_back(tmp);
148  newWeights.push_back(val);
149  } else {
150  // otherwise, skip it and add its weight to the one to be inserted
151  // instead
152  joinedVal += val;
153  }
154  }
155  // add the one to be inserted instead
156  newList.push_back(by);
157  newWeights.push_back(joinedVal);
158  // assign to values
159  mySources = newList;
160  mySourceWeights = newWeights;
161 }
162 
163 
164 void
166  int i;
167  for (i = 0; i < (int)mySinks.size(); ++i) {
168  if (mySinks[i] == e) {
169  mySinks.erase(mySinks.begin() + i);
170  mySinkWeights.erase(mySinkWeights.begin() + i);
171  }
172  }
173  for (i = 0; i < (int)mySources.size(); ++i) {
174  if (mySources[i] == e) {
175  mySources.erase(mySources.begin() + i);
176  mySourceWeights.erase(mySourceWeights.begin() + i);
177  }
178  }
179 }
180 
181 
182 void
184  myShape = p;
185 }
186 
187 
188 
189 /****************************************************************************/
190 
NBDistrict::NBDistrict
NBDistrict(const std::string &id, const Position &pos)
Constructor with id, and position.
Definition: NBDistrict.cpp:41
NBDistrict::mySinks
EdgeVector mySinks
The sinks (connection from network to district)
Definition: NBDistrict.h:248
Named
Base class for objects which have an id.
Definition: Named.h:56
NBDistrict::replaceOutgoing
void replaceOutgoing(const EdgeVector &which, NBEdge *const by)
Replaces outgoing edges from the vector (source) by the given edge.
Definition: NBDistrict.cpp:133
EdgeVector
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:34
PositionVector
A list of positions.
Definition: PositionVector.h:45
NBDistrict.h
NBEdge
The representation of a single edge during network building.
Definition: NBEdge.h:91
NBDistrict::myShape
PositionVector myShape
The shape of the dsitrict.
Definition: NBDistrict.h:257
PositionVector::add
void add(double xoff, double yoff, double zoff)
Definition: PositionVector.cpp:617
NBDistrict::removeFromSinksAndSources
void removeFromSinksAndSources(NBEdge *const e)
Removes the given edge from the lists of sources and sinks.
Definition: NBDistrict.cpp:165
NBDistrict::reshiftPosition
void reshiftPosition(double xoff, double yoff)
Applies an offset to the district.
Definition: NBDistrict.cpp:55
NBDistrict::addShape
void addShape(const PositionVector &p)
Sets the shape of this district.
Definition: NBDistrict.cpp:183
Named.h
NBDistrict::WeightsCont
std::vector< double > WeightsCont
Definition of a vector of connection weights.
Definition: NBDistrict.h:239
OutputDevice.h
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:38
NBDistrict::mySinkWeights
WeightsCont mySinkWeights
The weights of the sinks.
Definition: NBDistrict.h:251
Position::mul
void mul(double val)
Multiplies both positions with the given value.
Definition: Position.h:106
StringUtils
Some static methods for string processing.
Definition: StringUtils.h:39
StringUtils.h
NBDistrict::myPosition
Position myPosition
The position of the district.
Definition: NBDistrict.h:254
NBDistrict::addSink
bool addSink(NBEdge *const sink, double weight)
Adds a sink.
Definition: NBDistrict.cpp:82
NBDistrict::mirrorX
void mirrorX()
mirror coordinates along the x-axis
Definition: NBDistrict.cpp:62
config.h
Position::add
void add(const Position &pos)
Adds the given position to this one.
Definition: Position.h:126
NBDistrict::setCenter
void setCenter(const Position &pos)
Sets the center coordinates.
Definition: NBDistrict.cpp:95
NBDistrict::mySourceWeights
WeightsCont mySourceWeights
The weights of the sources.
Definition: NBDistrict.h:245
NBDistrict::~NBDistrict
~NBDistrict()
Destructor.
Definition: NBDistrict.cpp:50
NBDistrict::addSource
bool addSource(NBEdge *const source, double weight)
Adds a source.
Definition: NBDistrict.cpp:69
PositionVector::mirrorX
void mirrorX()
Definition: PositionVector.cpp:655
NBDistrict::replaceIncoming
void replaceIncoming(const EdgeVector &which, NBEdge *const by)
Replaces incoming edges from the vector (sinks) by the given edge.
Definition: NBDistrict.cpp:101
NBDistrict::mySources
EdgeVector mySources
The sources (connection from district to network)
Definition: NBDistrict.h:242
NBEdge.h
NBEdge::getID
const std::string & getID() const
Definition: NBEdge.h:1380