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