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