SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
NIVissimNodeCluster.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // -------------------
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 
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 
52 // ===========================================================================
53 // static member variables
54 // ===========================================================================
57 
58 
59 // ===========================================================================
60 // method definitions
61 // ===========================================================================
62 NIVissimNodeCluster::NIVissimNodeCluster(int id, int nodeid, int tlid,
63  const std::vector<int>& connectors,
64  const std::vector<int>& disturbances,
65  bool amEdgeSplitOnly)
66  : myID(id), myNodeID(nodeid), myTLID(tlid),
67  myConnectors(connectors), myDisturbances(disturbances),
68  myNBNode(0), myAmEdgeSplit(amEdgeSplitOnly) {}
69 
70 
72 
73 
74 
75 
76 bool
78  DictType::iterator i = myDict.find(id);
79  if (i == myDict.end()) {
80  myDict[id] = o;
81  return true;
82  }
83  assert(false);
84  return false;
85 }
86 
87 
88 int
89 NIVissimNodeCluster::dictionary(int nodeid, int tlid,
90  const std::vector<int>& connectors,
91  const std::vector<int>& disturbances,
92  bool amEdgeSplitOnly) {
93  int id = nodeid;
94  if (nodeid < 0) {
95  id = myCurrentID++;
96  }
98  nodeid, tlid, connectors, disturbances, amEdgeSplitOnly);
99  dictionary(id, o);
100  return id;
101 }
102 
103 
106  DictType::iterator i = myDict.find(id);
107  if (i == myDict.end()) {
108  return 0;
109  }
110  return (*i).second;
111 }
112 
113 
114 
115 size_t
117  return myDict.size();
118 }
119 
120 
121 
122 std::string
124  if (myTLID == -1) {
125  return toString<int>(myID);
126  } else {
127  return toString<int>(myID) + "LSA " + toString<int>(myTLID);
128  }
129 }
130 
131 
132 void
134  if (myConnectors.size() == 0) {
135  return; // !!! Check, whether this can happen
136  }
137 
138  // compute the position
139  PositionVector crossings;
140  std::vector<int>::iterator i, j;
141  // check whether this is a split of an edge only
142  if (myAmEdgeSplit) {
143 // !!! should be assert(myTLID==-1);
144  for (i = myConnectors.begin(); i != myConnectors.end(); i++) {
147  }
148  } else {
149  // compute the places the connections cross
150  for (i = myConnectors.begin(); i != myConnectors.end(); i++) {
152  c1->buildGeom();
153  for (j = i + 1; j != myConnectors.end(); j++) {
155  c2->buildGeom();
156  if (c1->crossesEdge(c2)) {
157  crossings.push_back_noDoublePos(c1->crossesEdgeAtPoint(c2));
158  }
159  }
160  }
161  // alternative way: compute via positions of crossings
162  if (crossings.size() == 0) {
163  for (i = myConnectors.begin(); i != myConnectors.end(); i++) {
166  crossings.push_back_noDoublePos(c1->getToGeomPosition());
167  }
168  }
169  }
170  // get the position (center)
171  Position pos = crossings.getPolygonCenter();
172  // build the node
173  /* if(myTLID!=-1) {
174  !!! NIVissimTL *tl = NIVissimTL::dictionary(myTLID);
175  if(tl->getType()=="festzeit") {
176  node = new NBNode(getNodeName(), pos.x(), pos.y(),
177  "traffic_light");
178  } else {
179  node = new NBNode(getNodeName(), pos.x(), pos.y(),
180  "actuated_traffic_light");
181  }
182  }*/
183  NBNode* node = new NBNode(getNodeName(), pos, NODETYPE_PRIORITY);
184  if (!nc.insert(node)) {
185  delete node;
186  throw 1;
187  }
188  myNBNode = node;
189 }
190 
191 
192 void
194  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
195  (*i).second->buildNBNode(nc);
196  }
197 }
198 
199 
200 
201 void
203  return;
204 }
205 
206 
207 int
209  int ret = -1;
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 // "NIVissimNodeCluster:DoubleNode:" << ret << endl;
218  throw 1; // an edge should not outgo from two different nodes
219 // but actually, a joined cluster may posess a connections more than once
220  }
221  ret = (*i).first;
222  }
223  }
224  }
225  return ret;
226 }
227 
228 
229 int
231  int ret = -1;
232  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
233  NIVissimNodeCluster* c = (*i).second;
234  for (std::vector<int>::iterator j = c->myConnectors.begin(); j != c->myConnectors.end(); j++) {
236  if (conn != 0 && conn->getFromEdgeID() == edgeid) {
237 // return (*i).first;
238  if (ret != -1 && ret != (*i).first) {
239 // << "NIVissimNodeCluster: multiple to-nodes" << endl;
240  throw 1; // an edge should not outgo from two different nodes
241 // but actually, a joined cluster may posess a connections more than once
242 
243  }
244  ret = (*i).first;
245  }
246  }
247  }
248  return ret;
249 }
250 
251 
252 void
253 NIVissimNodeCluster::_debugOut(std::ostream& into) {
254  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
255  NIVissimNodeCluster* c = (*i).second;
256  into << std::endl << c->myID << ":";
257  for (std::vector<int>::iterator j = c->myConnectors.begin(); j != c->myConnectors.end(); j++) {
258  if (j != c->myConnectors.begin()) {
259  into << ", ";
260  }
261  into << (*j);
262  }
263  }
264  into << "=======================" << std::endl;
265 }
266 
267 
268 
269 NBNode*
271  return myNBNode;
272 }
273 
274 
275 Position
277  return myPosition;
278 }
279 
280 
281 void
283  NBNodeCont& nc, NBEdgeCont& ec) {
284  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
285  const std::vector<int>& disturbances = (*i).second->myDisturbances;
286  NBNode* node = nc.retrieve((*i).second->getNodeName());
287  for (std::vector<int>::const_iterator j = disturbances.begin(); j != disturbances.end(); j++) {
289  disturbance->addToNode(node, dc, nc, ec);
290  }
291  }
293 }
294 
295 
296 void
298  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
299  delete(*i).second;
300  }
301  myDict.clear();
302 }
303 
304 
305 void
307  myCurrentID = id;
308 }
309 
310 
311 
312 /****************************************************************************/
313 
static DictType myDict
static int getFromNode(int edgeid)
Position getPos() const
static void dict_recheckEdgeChanges()
static bool dictionary(int id, NIVissimAbstractEdge *e)
NIVissimNodeCluster(int id, int nodeid, int tlid, const std::vector< int > &connectors, const std::vector< int > &disturbances, bool amEdgeSplitOnly)
A container for districts.
static bool dictionary(const std::string &name, const NIVissimExtendedEdgePoint &edge, const NIVissimExtendedEdgePoint &by)
bool addToNode(NBNode *node, NBDistrictCont &dc, NBNodeCont &nc, NBEdgeCont &ec)
static bool dictionary(int id, NIVissimNodeCluster *o)
static bool dictionary(int id, NIVissimConnection *o)
Position getToGeomPosition() const
bool crossesEdge(NIVissimAbstractEdge *c) const
static void setCurrentVirtID(int id)
static void dict_addDisturbances(NBDistrictCont &dc, NBNodeCont &nc, NBEdgeCont &ec)
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
A list of positions.
virtual void buildGeom()=0
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:66
std::map< int, NIVissimNodeCluster * > DictType
static int getToNode(int edgeid)
static void _debugOut(std::ostream &into)
std::string getNodeName() const
std::vector< int > myConnectors
bool insert(const std::string &id, const Position &position, NBDistrict *district=0)
Inserts a node into the map.
Definition: NBNodeCont.cpp:79
static void buildNBNodes(NBNodeCont &nc)
Represents a single node (junction) during network building.
Definition: NBNode.h:75
Position crossesEdgeAtPoint(NIVissimAbstractEdge *c) const
void buildNBNode(NBNodeCont &nc)
void push_back_noDoublePos(const Position &p)
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
Definition: NBNodeCont.cpp:108
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:64
Position getPolygonCenter() const
Returns the arithmetic of all corner points.
Position getFromGeomPosition() const
NBNode * getNBNode() const