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