SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NIVissimNodeCluster.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // -------------------
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
12 // Copyright (C) 2001-2012 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 
34 #include <map>
35 #include <algorithm>
36 #include <cassert>
38 #include <utils/common/ToString.h>
40 #include <netbuild/NBNode.h>
41 #include <netbuild/NBNodeCont.h>
42 #include "NIVissimTL.h"
43 #include "NIVissimDisturbance.h"
44 #include "NIVissimConnection.h"
45 #include "NIVissimNodeCluster.h"
46 
47 #ifdef CHECK_MEMORY_LEAKS
48 #include <foreign/nvwa/debug_new.h>
49 #endif // CHECK_MEMORY_LEAKS
50 // ===========================================================================
51 // used namespaces
52 // ===========================================================================
53 
54 using namespace std;
55 
58 
59 
60 
61 NIVissimNodeCluster::NIVissimNodeCluster(int id, int nodeid, int tlid,
62  const std::vector<int>& connectors,
63  const std::vector<int>& disturbances,
64  bool amEdgeSplitOnly)
65  : myID(id), myNodeID(nodeid), myTLID(tlid),
66  myConnectors(connectors), myDisturbances(disturbances),
67  myNBNode(0), myAmEdgeSplit(amEdgeSplitOnly) {}
68 
69 
71 
72 
73 
74 
75 bool
77  DictType::iterator i = myDict.find(id);
78  if (i == myDict.end()) {
79  myDict[id] = o;
80  return true;
81  }
82  assert(false);
83  return false;
84 }
85 
86 
87 int
88 NIVissimNodeCluster::dictionary(int nodeid, int tlid,
89  const std::vector<int>& connectors,
90  const std::vector<int>& disturbances,
91  bool amEdgeSplitOnly) {
92  int id = nodeid;
93  if (nodeid < 0) {
94  id = myCurrentID++;
95  }
97  nodeid, tlid, connectors, disturbances, amEdgeSplitOnly);
98  dictionary(id, o);
99  return id;
100 }
101 
102 
105  DictType::iterator i = myDict.find(id);
106  if (i == myDict.end()) {
107  return 0;
108  }
109  return (*i).second;
110 }
111 
112 
113 
114 size_t
116  return myDict.size();
117 }
118 
119 
120 
121 std::string
123  if (myTLID == -1) {
124  return toString<int>(myID);
125  } else {
126  return toString<int>(myID) + "LSA " + toString<int>(myTLID);
127  }
128 }
129 
130 
131 void
133  if (myConnectors.size() == 0) {
134  return; // !!! Check, whether this can happen
135  }
136 
137  // compute the position
138  PositionVector crossings;
139  std::vector<int>::iterator i, j;
140  // check whether this is a split of an edge only
141  if (myAmEdgeSplit) {
142 // !!! should be assert(myTLID==-1);
143  for (i = myConnectors.begin(); i != myConnectors.end(); i++) {
146  }
147  } else {
148  // compute the places the connections cross
149  for (i = myConnectors.begin(); i != myConnectors.end(); i++) {
151  c1->buildGeom();
152  for (j = i + 1; j != myConnectors.end(); j++) {
154  c2->buildGeom();
155  if (c1->crossesEdge(c2)) {
156  crossings.push_back_noDoublePos(c1->crossesEdgeAtPoint(c2));
157  }
158  }
159  }
160  // alternative way: compute via positions of crossings
161  if (crossings.size() == 0) {
162  for (i = myConnectors.begin(); i != myConnectors.end(); i++) {
165  crossings.push_back_noDoublePos(c1->getToGeomPosition());
166  }
167  }
168  }
169  // get the position (center)
170  Position pos = crossings.getPolygonCenter();
171  // build the node
172  /* if(myTLID!=-1) {
173  !!! NIVissimTL *tl = NIVissimTL::dictionary(myTLID);
174  if(tl->getType()=="festzeit") {
175  node = new NBNode(getNodeName(), pos.x(), pos.y(),
176  "traffic_light");
177  } else {
178  node = new NBNode(getNodeName(), pos.x(), pos.y(),
179  "actuated_traffic_light");
180  }
181  }*/
183  if (!nc.insert(node)) {
184  delete node;
185  throw 1;
186  }
187  myNBNode = node;
188 }
189 
190 
191 void
193  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
194  (*i).second->buildNBNode(nc);
195  }
196 }
197 
198 
199 
200 void
202  return;
203 }
204 
205 
206 int
208  int ret = -1;
209  bool mult = false;
210  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
211  NIVissimNodeCluster* c = (*i).second;
212  for (std::vector<int>::iterator j = c->myConnectors.begin(); j != c->myConnectors.end(); j++) {
214  if (conn != 0 && conn->getToEdgeID() == edgeid) {
215 // return (*i).first;
216  if (ret != -1 && (*i).first != ret) {
217  mult = true;
218 // "NIVissimNodeCluster:DoubleNode:" << ret << endl;
219  throw 1; // an edge should not outgo from two different nodes
220 // but actually, a joined cluster may posess a connections more than once
221  }
222  ret = (*i).first;
223  }
224  }
225  }
226  return ret;
227 }
228 
229 
230 int
232  int ret = -1;
233  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
234  NIVissimNodeCluster* c = (*i).second;
235  for (std::vector<int>::iterator j = c->myConnectors.begin(); j != c->myConnectors.end(); j++) {
237  if (conn != 0 && conn->getFromEdgeID() == edgeid) {
238 // return (*i).first;
239  if (ret != -1 && ret != (*i).first) {
240 // << "NIVissimNodeCluster: multiple to-nodes" << endl;
241  throw 1; // an edge should not outgo from two different nodes
242 // but actually, a joined cluster may posess a connections more than once
243 
244  }
245  ret = (*i).first;
246  }
247  }
248  }
249  return ret;
250 }
251 
252 
253 void
254 NIVissimNodeCluster::_debugOut(std::ostream& into) {
255  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
256  NIVissimNodeCluster* c = (*i).second;
257  into << endl << c->myID << ":";
258  for (std::vector<int>::iterator j = c->myConnectors.begin(); j != c->myConnectors.end(); j++) {
259  if (j != c->myConnectors.begin()) {
260  into << ", ";
261  }
262  into << (*j);
263  }
264  }
265  into << "=======================" << endl;
266 }
267 
268 
269 
270 NBNode*
272  return myNBNode;
273 }
274 
275 
276 Position
278  return myPosition;
279 }
280 
281 
282 void
284  NBNodeCont& nc, NBEdgeCont& ec) {
285  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
286  const std::vector<int>& disturbances = (*i).second->myDisturbances;
287  NBNode* node = nc.retrieve((*i).second->getNodeName());
288  for (std::vector<int>::const_iterator j = disturbances.begin(); j != disturbances.end(); j++) {
290  disturbance->addToNode(node, dc, nc, ec);
291  }
292  }
294 }
295 
296 
297 void
299  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
300  delete(*i).second;
301  }
302  myDict.clear();
303 }
304 
305 
306 void
308  myCurrentID = id;
309 }
310 
311 
312 
313 /****************************************************************************/
314