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-2015 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 #ifdef CHECK_MEMORY_LEAKS
46 #include <foreign/nvwa/debug_new.h>
47 #endif // CHECK_MEMORY_LEAKS
48 
49 
50 // ===========================================================================
51 // member method definitions
52 // ===========================================================================
53 NBDistrict::NBDistrict(const std::string& id, const Position& pos)
54  : Named(StringUtils::convertUmlaute(id)),
55  myPosition(pos) {}
56 
57 
58 NBDistrict::NBDistrict(const std::string& id)
59  : Named(id), myPosition(0, 0) {}
60 
61 
63 
64 
65 // ----------- Applying offset
66 void
68  myPosition.add(xoff, yoff, 0);
69  myShape.add(xoff, yoff, 0);
70 }
71 
72 
73 void
75  myPosition.mul(1, -1);
76  myShape.mirrorX();
77 }
78 
79 
80 bool
81 NBDistrict::addSource(NBEdge* const source, SUMOReal weight) {
82  EdgeVector::iterator i = find(mySources.begin(), mySources.end(), source);
83  if (i != mySources.end()) {
84  return false;
85  }
86  mySources.push_back(source);
87  mySourceWeights.push_back(weight);
88  assert(source->getID() != "");
89  return true;
90 }
91 
92 
93 bool
94 NBDistrict::addSink(NBEdge* const sink, SUMOReal weight) {
95  EdgeVector::iterator i = find(mySinks.begin(), mySinks.end(), sink);
96  if (i != mySinks.end()) {
97  return false;
98  }
99  mySinks.push_back(sink);
100  mySinkWeights.push_back(weight);
101  assert(sink->getID() != "");
102  return true;
103 }
104 
105 
106 void
108  myPosition = pos;
109 }
110 
111 
112 void
114  // temporary structures
115  EdgeVector newList;
116  WeightsCont newWeights;
117  SUMOReal joinedVal = 0;
118  // go through the list of sinks
119  EdgeVector::iterator i = mySinks.begin();
120  WeightsCont::iterator j = mySinkWeights.begin();
121  for (; i != mySinks.end(); i++, j++) {
122  NBEdge* tmp = (*i);
123  SUMOReal val = (*j);
124  if (find(which.begin(), which.end(), tmp) == which.end()) {
125  // if the current edge shall not be replaced, add to the
126  // temporary list
127  newList.push_back(tmp);
128  newWeights.push_back(val);
129  } else {
130  // otherwise, skip it and add its weight to the one to be inserted
131  // instead
132  joinedVal += val;
133  }
134  }
135  // add the one to be inserted instead
136  newList.push_back(by);
137  newWeights.push_back(joinedVal);
138  // assign to values
139  mySinks = newList;
140  mySinkWeights = newWeights;
141 }
142 
143 
144 void
146  // temporary structures
147  EdgeVector newList;
148  WeightsCont newWeights;
149  SUMOReal joinedVal = 0;
150  // go through the list of sinks
151  EdgeVector::iterator i = mySources.begin();
152  WeightsCont::iterator j = mySourceWeights.begin();
153  for (; i != mySources.end(); i++, j++) {
154  NBEdge* tmp = (*i);
155  SUMOReal val = (*j);
156  if (find(which.begin(), which.end(), tmp) == which.end()) {
157  // if the current edge shall not be replaced, add to the
158  // temporary list
159  newList.push_back(tmp);
160  newWeights.push_back(val);
161  } else {
162  // otherwise, skip it and add its weight to the one to be inserted
163  // instead
164  joinedVal += val;
165  }
166  }
167  // add the one to be inserted instead
168  newList.push_back(by);
169  newWeights.push_back(joinedVal);
170  // assign to values
171  mySources = newList;
172  mySourceWeights = newWeights;
173 }
174 
175 
176 void
178  size_t i;
179  for (i = 0; i < mySinks.size(); ++i) {
180  if (mySinks[i] == e) {
181  mySinks.erase(mySinks.begin() + i);
182  mySinkWeights.erase(mySinkWeights.begin() + i);
183  }
184  }
185  for (i = 0; i < mySources.size(); ++i) {
186  if (mySources[i] == e) {
187  mySources.erase(mySources.begin() + i);
188  mySourceWeights.erase(mySourceWeights.begin() + i);
189  }
190  }
191 }
192 
193 
194 void
196  myShape = p;
197 }
198 
199 
200 
201 /****************************************************************************/
202 
void replaceOutgoing(const EdgeVector &which, NBEdge *const by)
Replaces outgoing edges from the vector (source) by the given edge.
Definition: NBDistrict.cpp:145
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:119
Some static methods for string processing.
Definition: StringUtils.h:45
bool addSource(NBEdge *const source, SUMOReal weight)
Adds a source.
Definition: NBDistrict.cpp:81
The representation of a single edge during network building.
Definition: NBEdge.h:70
void mirrorX()
mirror coordinates along the x-axis
Definition: NBDistrict.cpp:74
void addShape(const PositionVector &p)
Sets the shape of this district.
Definition: NBDistrict.cpp:195
NBDistrict(const std::string &id, const Position &pos)
Constructor with id, and position.
Definition: NBDistrict.cpp:53
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:107
const std::string & getID() const
Returns the id.
Definition: Named.h:65
Position myPosition
The position of the district.
Definition: NBDistrict.h:262
void mirrorX()
mirror coordinates along the x-axis
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
A list of positions.
void add(SUMOReal xoff, SUMOReal yoff, SUMOReal zoff)
void removeFromSinksAndSources(NBEdge *const e)
Removes the given edge from the lists of sources and sinks.
Definition: NBDistrict.cpp:177
~NBDistrict()
Destructor.
Definition: NBDistrict.cpp:62
Base class for objects which have an id.
Definition: Named.h:45
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< SUMOReal > WeightsCont
Definition of a vector of connection weights.
Definition: NBDistrict.h:247
bool addSink(NBEdge *const sink, SUMOReal weight)
Adds a sink.
Definition: NBDistrict.cpp:94
std::vector< NBEdge * > EdgeVector
Definition: NBCont.h:41
void mul(SUMOReal val)
Multiplies both positions with the given value.
Definition: Position.h:99
PositionVector myShape
The shape of the dsitrict.
Definition: NBDistrict.h:265
void reshiftPosition(SUMOReal xoff, SUMOReal yoff)
Applies an offset to the district.
Definition: NBDistrict.cpp:67
#define SUMOReal
Definition: config.h:214
void replaceIncoming(const EdgeVector &which, NBEdge *const by)
Replaces incoming edges from the vector (sinks) by the given edge.
Definition: NBDistrict.cpp:113