SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NIVissimConnection.cpp
Go to the documentation of this file.
1 /****************************************************************************/
11 // -------------------
12 /****************************************************************************/
13 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
14 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
15 /****************************************************************************/
16 //
17 // This file is part of SUMO.
18 // SUMO is free software: you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation, either version 3 of the License, or
21 // (at your option) any later version.
22 //
23 /****************************************************************************/
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <string>
36 #include <map>
37 #include <iostream>
38 #include <cassert>
41 #include <utils/common/ToString.h>
44 #include <utils/geom/Boundary.h>
45 #include <utils/geom/GeomHelper.h>
46 #include <netbuild/NBEdge.h>
47 #include <netbuild/NBNode.h>
48 #include <netbuild/NBEdgeCont.h>
49 #include "NIVissimEdge.h"
51 #include "NIVissimNodeDef.h"
52 #include "NIVissimConnection.h"
54 
55 #ifdef CHECK_MEMORY_LEAKS
56 #include <foreign/nvwa/debug_new.h>
57 #endif // CHECK_MEMORY_LEAKS
58 
59 
60 // ===========================================================================
61 // static members
62 // ===========================================================================
65 
66 
67 // ===========================================================================
68 // method definitions
69 // ===========================================================================
71  const std::string& name, const NIVissimExtendedEdgePoint& from_def,
72  const NIVissimExtendedEdgePoint& to_def,
73  const PositionVector& geom, Direction direction,
74  SUMOReal dxnothalt, SUMOReal dxeinordnen,
75  SUMOReal zuschlag1, SUMOReal zuschlag2, SUMOReal /*seglength*/,
76  const std::vector<int>& assignedVehicles, const NIVissimClosedLanesVector& clv)
77  : NIVissimAbstractEdge(id, geom),
78  myName(name), myFromDef(from_def), myToDef(to_def),
79  myDirection(direction),
80  myDXNothalt(dxnothalt), myDXEinordnen(dxeinordnen),
81  myZuschlag1(zuschlag1), myZuschlag2(zuschlag2),
82  myAssignedVehicles(assignedVehicles), myClosedLanes(clv) {}
83 
84 
86  for (NIVissimClosedLanesVector::iterator i = myClosedLanes.begin(); i != myClosedLanes.end(); i++) {
87  delete(*i);
88  }
89  myClosedLanes.clear();
90 }
91 
92 
93 bool
94 NIVissimConnection::dictionary(int id, const std::string& name,
95  const NIVissimExtendedEdgePoint& from_def,
96  const NIVissimExtendedEdgePoint& to_def,
97  const PositionVector& geom,
98  Direction direction,
99  SUMOReal dxnothalt, SUMOReal dxeinordnen,
100  SUMOReal zuschlag1, SUMOReal zuschlag2,
101  SUMOReal seglength,
102  const std::vector<int>& assignedVehicles,
103  const NIVissimClosedLanesVector& clv) {
104  NIVissimConnection* o = new NIVissimConnection(id, name, from_def, to_def,
105  geom, direction, dxnothalt, dxeinordnen, zuschlag1, zuschlag2,
106  seglength, assignedVehicles, clv);
107  if (!dictionary(id, o)) {
108  delete o;
109  return false;
110  }
111  if (myMaxID < id) {
112  myMaxID = id;
113  }
114  return true;
115 }
116 
117 
118 
119 bool
121  DictType::iterator i = myDict.find(id);
122  if (i == myDict.end()) {
123  myDict[id] = o;
124  return true;
125  }
126  return false;
127 }
128 
129 
130 
133  DictType::iterator i = myDict.find(id);
134  if (i == myDict.end()) {
135  return 0;
136  }
137  return (*i).second;
138 }
139 
140 
141 void
143  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
144  NIVissimConnection* e = (*i).second;
145  if (!e->clustered()) {
146  assert(e->myBoundary != 0 && e->myBoundary->xmax() > e->myBoundary->xmin());
147  std::vector<int> connections =
149  NIVissimNodeCluster::dictionary(-1, -1, connections,
150  std::vector<int>(), true); // 19.5.!!! should be on a single edge
151  }
152  }
153 }
154 
155 
156 
157 
158 
159 std::vector<int>
161  std::vector<int> ret;
162  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
163  if ((*i).second->crosses(poly)) {
164  ret.push_back((*i).second->myID);
165  }
166  }
167  return ret;
168 }
169 
170 
171 void
173  Boundary* bound = new Boundary();
174  bound->add(myFromDef.getGeomPosition());
175  bound->add(myToDef.getGeomPosition());
176  assert(myBoundary == 0);
177  myBoundary = bound;
178 }
179 
180 
181 std::vector<int>
182 NIVissimConnection::getForEdge(int edgeid, bool /*omitNodeAssigned*/) {
183  std::vector<int> ret;
184  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
185  int connID = (*i).first;
186  if ((*i).second->myFromDef.getEdgeID() == edgeid
187  ||
188  (*i).second->myToDef.getEdgeID() == edgeid) {
189  if (!(*i).second->hasNodeCluster()) {
190  ret.push_back(connID);
191  }
192  }
193  }
194  return ret;
195 }
196 
197 
198 int
200  return myFromDef.getEdgeID();
201 }
202 
203 
204 int
206  return myToDef.getEdgeID();
207 }
208 
209 
210 SUMOReal
212  return myFromDef.getPosition();
213 }
214 
215 
216 SUMOReal
218  return myToDef.getPosition();
219 }
220 
221 
222 Position
224  return myFromDef.getGeomPosition();
225 }
226 
227 
228 
229 Position
231  return myToDef.getGeomPosition();
232 }
233 
234 
235 void
237  assert(myNode == -1);
238  myNode = nodeid;
239 }
240 
241 
242 void
244  if (myGeom.size() > 0) {
245  return;
246  }
249 }
250 
251 
252 unsigned int
254  unsigned int unsetConnections = 0;
255  // try to determine the connected edges
256  NBEdge* fromEdge = 0;
257  NBEdge* toEdge = 0;
259  if (vissimFrom->wasWithinAJunction()) {
260  // this edge was not built, try to get one that approaches it
261  vissimFrom = vissimFrom->getBestIncoming();
262  if (vissimFrom != 0) {
263  fromEdge = ec.retrievePossiblySplitted(toString(vissimFrom->getID()), toString(getFromEdgeID()), true);
264  }
265  } else {
266  // this edge was built, try to get the proper part
268  }
270  if (vissimTo->wasWithinAJunction()) {
271  vissimTo = vissimTo->getBestOutgoing();
272  if (vissimTo != 0) {
273  toEdge = ec.retrievePossiblySplitted(toString(vissimTo->getID()), toString(getToEdgeID()), true);
274  }
275  } else {
277  }
278 
279  // try to get the edges the current connection connects
280  /*
281  NBEdge *fromEdge = ec.retrievePossiblySplitted(toString(getFromEdgeID()), toString(getToEdgeID()), true);
282  NBEdge *toEdge = ec.retrievePossiblySplitted(toString(getToEdgeID()), toString(getFromEdgeID()), false);
283  */
284  if (fromEdge == 0 || toEdge == 0) {
285  WRITE_WARNING("Could not build connection between '" + toString(getFromEdgeID()) + "' and '" + toString(getToEdgeID()) + "'.");
286  return 1; // !!! actually not 1
287  }
288  recheckLanes(fromEdge, toEdge);
289  const std::vector<int>& fromLanes = getFromLanes();
290  const std::vector<int>& toLanes = getToLanes();
291  if (fromLanes.size() != toLanes.size()) {
292  WRITE_WARNING("Lane sizes differ for connection '" + toString(getID()) + "'.");
293  } else {
294  for (unsigned int index = 0; index < fromLanes.size(); ++index) {
295  if (fromEdge->getNumLanes() <= static_cast<unsigned int>(fromLanes[index])) {
296  WRITE_WARNING("Could not set connection between '" + fromEdge->getID() + "_" + toString(fromLanes[index]) + "' and '" + toEdge->getID() + "_" + toString(toLanes[index]) + "'.");
297  ++unsetConnections;
298  } else if (!fromEdge->addLane2LaneConnection(fromLanes[index], toEdge, toLanes[index], NBEdge::L2L_VALIDATED)) {
299  WRITE_WARNING("Could not set connection between '" + fromEdge->getID() + "_" + toString(fromLanes[index]) + "' and '" + toEdge->getID() + "_" + toString(toLanes[index]) + "'.");
300  ++unsetConnections;
301  }
302  }
303  }
304  return unsetConnections;
305 }
306 
307 
308 void
310  unsigned int unsetConnections = 0;
311  // go through connections
312  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
313  unsetConnections += (*i).second->buildEdgeConnections(ec);
314  }
315  if (unsetConnections != 0) {
316  WRITE_WARNING(toString<size_t>(unsetConnections) + " of " + toString<size_t>(myDict.size()) + " connections could not be assigned.");
317  }
318 }
319 
320 
321 const std::vector<int>&
323  return myFromDef.getLanes();
324 }
325 
326 
327 const std::vector<int>&
329  return myToDef.getLanes();
330 }
331 
332 
333 void
334 NIVissimConnection::recheckLanes(const NBEdge* const fromEdge, const NBEdge* const toEdge) {
335  myFromDef.recheckLanes(fromEdge);
336  myToDef.recheckLanes(toEdge);
337 }
338 
339 
340 const Boundary&
342  assert(myBoundary != 0 && myBoundary->xmax() >= myBoundary->xmin());
343  return *myBoundary;
344 }
345 
346 
347 void
349  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
350  NIVissimConnection* c = (*i).second;
351  NIVissimEdge::dictionary(c->getFromEdgeID())->addOutgoingConnection((*i).first);
352  NIVissimEdge::dictionary(c->getToEdgeID())->addIncomingConnection((*i).first);
353  }
354 }
355 
356 
357 int
359  return myMaxID;
360 }
361 
362 
363 /****************************************************************************/
364 
365