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.reshiftRotate(xoff, yoff, 0);
69  myShape.reshiftRotate(xoff, yoff, 0);
70 }
71 
72 
73 bool
74 NBDistrict::addSource(NBEdge* const source, SUMOReal weight) {
75  EdgeVector::iterator i = find(mySources.begin(), mySources.end(), source);
76  if (i != mySources.end()) {
77  return false;
78  }
79  mySources.push_back(source);
80  mySourceWeights.push_back(weight);
81  assert(source->getID() != "");
82  return true;
83 }
84 
85 
86 bool
87 NBDistrict::addSink(NBEdge* const sink, SUMOReal weight) {
88  EdgeVector::iterator i = find(mySinks.begin(), mySinks.end(), sink);
89  if (i != mySinks.end()) {
90  return false;
91  }
92  mySinks.push_back(sink);
93  mySinkWeights.push_back(weight);
94  assert(sink->getID() != "");
95  return true;
96 }
97 
98 
99 void
101  myPosition = pos;
102 }
103 
104 
105 void
107  // temporary structures
108  EdgeVector newList;
109  WeightsCont newWeights;
110  SUMOReal joinedVal = 0;
111  // go through the list of sinks
112  EdgeVector::iterator i = mySinks.begin();
113  WeightsCont::iterator j = mySinkWeights.begin();
114  for (; i != mySinks.end(); i++, j++) {
115  NBEdge* tmp = (*i);
116  SUMOReal val = (*j);
117  if (find(which.begin(), which.end(), tmp) == which.end()) {
118  // if the current edge shall not be replaced, add to the
119  // temporary list
120  newList.push_back(tmp);
121  newWeights.push_back(val);
122  } else {
123  // otherwise, skip it and add its weight to the one to be inserted
124  // instead
125  joinedVal += val;
126  }
127  }
128  // add the one to be inserted instead
129  newList.push_back(by);
130  newWeights.push_back(joinedVal);
131  // assign to values
132  mySinks = newList;
133  mySinkWeights = newWeights;
134 }
135 
136 
137 void
139  // temporary structures
140  EdgeVector newList;
141  WeightsCont newWeights;
142  SUMOReal joinedVal = 0;
143  // go through the list of sinks
144  EdgeVector::iterator i = mySources.begin();
145  WeightsCont::iterator j = mySourceWeights.begin();
146  for (; i != mySources.end(); i++, j++) {
147  NBEdge* tmp = (*i);
148  SUMOReal val = (*j);
149  if (find(which.begin(), which.end(), tmp) == which.end()) {
150  // if the current edge shall not be replaced, add to the
151  // temporary list
152  newList.push_back(tmp);
153  newWeights.push_back(val);
154  } else {
155  // otherwise, skip it and add its weight to the one to be inserted
156  // instead
157  joinedVal += val;
158  }
159  }
160  // add the one to be inserted instead
161  newList.push_back(by);
162  newWeights.push_back(joinedVal);
163  // assign to values
164  mySources = newList;
165  mySourceWeights = newWeights;
166 }
167 
168 
169 void
171  size_t i;
172  for (i = 0; i < mySinks.size(); ++i) {
173  if (mySinks[i] == e) {
174  mySinks.erase(mySinks.begin() + i);
175  mySinkWeights.erase(mySinkWeights.begin() + i);
176  }
177  }
178  for (i = 0; i < mySources.size(); ++i) {
179  if (mySources[i] == e) {
180  mySources.erase(mySources.begin() + i);
181  mySourceWeights.erase(mySourceWeights.begin() + i);
182  }
183  }
184 }
185 
186 
187 void
189  myShape = p;
190 }
191 
192 
193 
194 /****************************************************************************/
195 
void replaceOutgoing(const EdgeVector &which, NBEdge *const by)
Replaces outgoing edges from the vector (source) by the given edge.
Definition: NBDistrict.cpp:138
void reshiftRotate(SUMOReal xoff, SUMOReal yoff, SUMOReal rot)
Definition: Position.h:164
WeightsCont mySinkWeights
The weights of the sinks.
Definition: NBDistrict.h:256
Some static methods for string processing.
Definition: StringUtils.h:45
bool addSource(NBEdge *const source, SUMOReal weight)
Adds a source.
Definition: NBDistrict.cpp:74
The representation of a single edge during network building.
Definition: NBEdge.h:71
void addShape(const PositionVector &p)
Sets the shape of this district.
Definition: NBDistrict.cpp:188
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:247
void setCenter(const Position &pos)
Sets the center coordinates.
Definition: NBDistrict.cpp:100
const std::string & getID() const
Returns the id.
Definition: Named.h:60
void reshiftRotate(SUMOReal xoff, SUMOReal yoff, SUMOReal rot)
Position myPosition
The position of the district.
Definition: NBDistrict.h:259
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:170
~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:253
WeightsCont mySourceWeights
The weights of the sources.
Definition: NBDistrict.h:250
std::vector< SUMOReal > WeightsCont
Definition of a vector of connection weights.
Definition: NBDistrict.h:244
bool addSink(NBEdge *const sink, SUMOReal weight)
Adds a sink.
Definition: NBDistrict.cpp:87
std::vector< NBEdge * > EdgeVector
Definition: NBCont.h:41
PositionVector myShape
The shape of the dsitrict.
Definition: NBDistrict.h:262
void reshiftPosition(SUMOReal xoff, SUMOReal yoff)
Applies an offset to the district.
Definition: NBDistrict.cpp:67
#define SUMOReal
Definition: config.h:218
void replaceIncoming(const EdgeVector &which, NBEdge *const by)
Replaces incoming edges from the vector (sinks) by the given edge.
Definition: NBDistrict.cpp:106