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  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
210  NIVissimNodeCluster* c = (*i).second;
211  for (std::vector<int>::iterator j = c->myConnectors.begin(); j != c->myConnectors.end(); j++) {
213  if (conn != 0 && conn->getToEdgeID() == edgeid) {
214 // return (*i).first;
215  if (ret != -1 && (*i).first != ret) {
216 // "NIVissimNodeCluster:DoubleNode:" << ret << endl;
217  throw 1; // an edge should not outgo from two different nodes
218 // but actually, a joined cluster may posess a connections more than once
219  }
220  ret = (*i).first;
221  }
222  }
223  }
224  return ret;
225 }
226 
227 
228 int
230  int ret = -1;
231  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
232  NIVissimNodeCluster* c = (*i).second;
233  for (std::vector<int>::iterator j = c->myConnectors.begin(); j != c->myConnectors.end(); j++) {
235  if (conn != 0 && conn->getFromEdgeID() == edgeid) {
236 // return (*i).first;
237  if (ret != -1 && ret != (*i).first) {
238 // << "NIVissimNodeCluster: multiple to-nodes" << endl;
239  throw 1; // an edge should not outgo from two different nodes
240 // but actually, a joined cluster may posess a connections more than once
241 
242  }
243  ret = (*i).first;
244  }
245  }
246  }
247  return ret;
248 }
249 
250 
251 void
252 NIVissimNodeCluster::_debugOut(std::ostream& into) {
253  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
254  NIVissimNodeCluster* c = (*i).second;
255  into << endl << c->myID << ":";
256  for (std::vector<int>::iterator j = c->myConnectors.begin(); j != c->myConnectors.end(); j++) {
257  if (j != c->myConnectors.begin()) {
258  into << ", ";
259  }
260  into << (*j);
261  }
262  }
263  into << "=======================" << endl;
264 }
265 
266 
267 
268 NBNode*
270  return myNBNode;
271 }
272 
273 
274 Position
276  return myPosition;
277 }
278 
279 
280 void
282  NBNodeCont& nc, NBEdgeCont& ec) {
283  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
284  const std::vector<int>& disturbances = (*i).second->myDisturbances;
285  NBNode* node = nc.retrieve((*i).second->getNodeName());
286  for (std::vector<int>::const_iterator j = disturbances.begin(); j != disturbances.end(); j++) {
288  disturbance->addToNode(node, dc, nc, ec);
289  }
290  }
292 }
293 
294 
295 void
297  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
298  delete(*i).second;
299  }
300  myDict.clear();
301 }
302 
303 
304 void
306  myCurrentID = id;
307 }
308 
309 
310 
311 /****************************************************************************/
312