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