SUMO - Simulation of Urban MObility
NIVissimNodeCluster.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // -------------------
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 
33 #include <map>
34 #include <algorithm>
35 #include <cassert>
37 #include <utils/common/ToString.h>
39 #include <netbuild/NBNode.h>
40 #include <netbuild/NBNodeCont.h>
41 #include "NIVissimTL.h"
42 #include "NIVissimDisturbance.h"
43 #include "NIVissimConnection.h"
44 #include "NIVissimNodeCluster.h"
45 
46 
47 // ===========================================================================
48 // static member variables
49 // ===========================================================================
52 
53 
54 // ===========================================================================
55 // method definitions
56 // ===========================================================================
57 NIVissimNodeCluster::NIVissimNodeCluster(int id, int nodeid, int tlid,
58  const std::vector<int>& connectors,
59  const std::vector<int>& disturbances,
60  bool amEdgeSplitOnly)
61  : myID(id), myNodeID(nodeid), myTLID(tlid),
62  myConnectors(connectors), myDisturbances(disturbances),
63  myNBNode(0), myAmEdgeSplit(amEdgeSplitOnly) {}
64 
65 
67 
68 
69 
70 
71 bool
73  DictType::iterator i = myDict.find(id);
74  if (i == myDict.end()) {
75  myDict[id] = o;
76  return true;
77  }
78  assert(false);
79  return false;
80 }
81 
82 
83 int
84 NIVissimNodeCluster::dictionary(int nodeid, int tlid,
85  const std::vector<int>& connectors,
86  const std::vector<int>& disturbances,
87  bool amEdgeSplitOnly) {
88  int id = nodeid;
89  if (nodeid < 0) {
90  id = myCurrentID++;
91  }
93  nodeid, tlid, connectors, disturbances, amEdgeSplitOnly);
94  dictionary(id, o);
95  return id;
96 }
97 
98 
101  DictType::iterator i = myDict.find(id);
102  if (i == myDict.end()) {
103  return 0;
104  }
105  return (*i).second;
106 }
107 
108 
109 
110 int
112  return (int)myDict.size();
113 }
114 
115 
116 
117 std::string
119  if (myTLID == -1) {
120  return toString<int>(myID);
121  } else {
122  return toString<int>(myID) + "LSA " + toString<int>(myTLID);
123  }
124 }
125 
126 
127 void
129  if (myConnectors.size() == 0) {
130  return; // !!! Check, whether this can happen
131  }
132 
133  // compute the position
134  PositionVector crossings;
135  std::vector<int>::iterator i, j;
136  // check whether this is a split of an edge only
137  if (myAmEdgeSplit) {
138 // !!! should be assert(myTLID==-1);
139  for (i = myConnectors.begin(); i != myConnectors.end(); i++) {
142  }
143  } else {
144  // compute the places the connections cross
145  for (i = myConnectors.begin(); i != myConnectors.end(); i++) {
147  c1->buildGeom();
148  for (j = i + 1; j != myConnectors.end(); j++) {
150  c2->buildGeom();
151  if (c1->crossesEdge(c2)) {
152  crossings.push_back_noDoublePos(c1->crossesEdgeAtPoint(c2));
153  }
154  }
155  }
156  // alternative way: compute via positions of crossings
157  if (crossings.size() == 0) {
158  for (i = myConnectors.begin(); i != myConnectors.end(); i++) {
161  crossings.push_back_noDoublePos(c1->getToGeomPosition());
162  }
163  }
164  }
165  // get the position (center)
166  Position pos = crossings.getPolygonCenter();
167  // build the node
168  /* if(myTLID!=-1) {
169  !!! NIVissimTL *tl = NIVissimTL::dictionary(myTLID);
170  if(tl->getType()=="festzeit") {
171  node = new NBNode(getNodeName(), pos.x(), pos.y(),
172  "traffic_light");
173  } else {
174  node = new NBNode(getNodeName(), pos.x(), pos.y(),
175  "actuated_traffic_light");
176  }
177  }*/
178  NBNode* node = new NBNode(getNodeName(), pos, NODETYPE_PRIORITY);
179  if (!nc.insert(node)) {
180  delete node;
181  throw 1;
182  }
183  myNBNode = node;
184 }
185 
186 
187 void
189  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
190  (*i).second->buildNBNode(nc);
191  }
192 }
193 
194 
195 
196 void
198  return;
199 }
200 
201 
202 int
204  int ret = -1;
205  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
206  NIVissimNodeCluster* c = (*i).second;
207  for (std::vector<int>::iterator j = c->myConnectors.begin(); j != c->myConnectors.end(); j++) {
209  if (conn != 0 && conn->getToEdgeID() == edgeid) {
210 // return (*i).first;
211  if (ret != -1 && (*i).first != ret) {
212 // "NIVissimNodeCluster:DoubleNode:" << ret << endl;
213  throw 1; // an edge should not outgo from two different nodes
214 // but actually, a joined cluster may posess a connections more than once
215  }
216  ret = (*i).first;
217  }
218  }
219  }
220  return ret;
221 }
222 
223 
224 int
226  int ret = -1;
227  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
228  NIVissimNodeCluster* c = (*i).second;
229  for (std::vector<int>::iterator j = c->myConnectors.begin(); j != c->myConnectors.end(); j++) {
231  if (conn != 0 && conn->getFromEdgeID() == edgeid) {
232 // return (*i).first;
233  if (ret != -1 && ret != (*i).first) {
234 // << "NIVissimNodeCluster: multiple to-nodes" << endl;
235  throw 1; // an edge should not outgo from two different nodes
236 // but actually, a joined cluster may posess a connections more than once
237 
238  }
239  ret = (*i).first;
240  }
241  }
242  }
243  return ret;
244 }
245 
246 
247 void
248 NIVissimNodeCluster::_debugOut(std::ostream& into) {
249  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
250  NIVissimNodeCluster* c = (*i).second;
251  into << std::endl << c->myID << ":";
252  for (std::vector<int>::iterator j = c->myConnectors.begin(); j != c->myConnectors.end(); j++) {
253  if (j != c->myConnectors.begin()) {
254  into << ", ";
255  }
256  into << (*j);
257  }
258  }
259  into << "=======================" << std::endl;
260 }
261 
262 
263 
264 NBNode*
266  return myNBNode;
267 }
268 
269 
270 Position
272  return myPosition;
273 }
274 
275 
276 void
278  NBNodeCont& nc, NBEdgeCont& ec) {
279  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
280  const std::vector<int>& disturbances = (*i).second->myDisturbances;
281  NBNode* node = nc.retrieve((*i).second->getNodeName());
282  for (std::vector<int>::const_iterator j = disturbances.begin(); j != disturbances.end(); j++) {
284  disturbance->addToNode(node, dc, nc, ec);
285  }
286  }
288 }
289 
290 
291 void
293  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
294  delete(*i).second;
295  }
296  myDict.clear();
297 }
298 
299 
300 void
302  myCurrentID = id;
303 }
304 
305 
306 
307 /****************************************************************************/
308 
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
Definition: NBNodeCont.cpp:108
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:45
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:79
bool crossesEdge(NIVissimAbstractEdge *c) const
static void buildNBNodes(NBNodeCont &nc)
Represents a single node (junction) during network building.
Definition: NBNode.h:74
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:66