SUMO - Simulation of Urban MObility
NIVissimConnection.cpp
Go to the documentation of this file.
1 /****************************************************************************/
11 // -------------------
12 /****************************************************************************/
13 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
14 // Copyright (C) 2001-2015 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,
74  const std::vector<int>& assignedVehicles, const NIVissimClosedLanesVector& clv)
75  : NIVissimAbstractEdge(id, geom),
76  myName(name), myFromDef(from_def), myToDef(to_def),
77  myAssignedVehicles(assignedVehicles), myClosedLanes(clv) {}
78 
79 
81  for (NIVissimClosedLanesVector::iterator i = myClosedLanes.begin(); i != myClosedLanes.end(); i++) {
82  delete(*i);
83  }
84  myClosedLanes.clear();
85 }
86 
87 
88 bool
90  DictType::iterator i = myDict.find(id);
91  if (i == myDict.end()) {
92  myDict[id] = o;
93  return true;
94  }
95  return false;
96 }
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 void
112  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
113  NIVissimConnection* e = (*i).second;
114  if (!e->clustered()) {
115  assert(e->myBoundary != 0 && e->myBoundary->xmax() > e->myBoundary->xmin());
116  std::vector<int> connections =
118  NIVissimNodeCluster::dictionary(-1, -1, connections,
119  std::vector<int>(), true); // 19.5.!!! should be on a single edge
120  }
121  }
122 }
123 
124 
125 
126 
127 
128 std::vector<int>
130  std::vector<int> ret;
131  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
132  if ((*i).second->crosses(poly)) {
133  ret.push_back((*i).second->myID);
134  }
135  }
136  return ret;
137 }
138 
139 
140 void
142  Boundary* bound = new Boundary();
143  bound->add(myFromDef.getGeomPosition());
144  bound->add(myToDef.getGeomPosition());
145  assert(myBoundary == 0);
146  myBoundary = bound;
147 }
148 
149 
150 std::vector<int>
151 NIVissimConnection::getForEdge(int edgeid, bool /*omitNodeAssigned*/) {
152  std::vector<int> ret;
153  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
154  int connID = (*i).first;
155  if ((*i).second->myFromDef.getEdgeID() == edgeid
156  ||
157  (*i).second->myToDef.getEdgeID() == edgeid) {
158  if (!(*i).second->hasNodeCluster()) {
159  ret.push_back(connID);
160  }
161  }
162  }
163  return ret;
164 }
165 
166 
167 int
169  return myFromDef.getEdgeID();
170 }
171 
172 
173 int
175  return myToDef.getEdgeID();
176 }
177 
178 
179 SUMOReal
181  return myFromDef.getPosition();
182 }
183 
184 
185 SUMOReal
187  return myToDef.getPosition();
188 }
189 
190 
191 Position
193  return myFromDef.getGeomPosition();
194 }
195 
196 
197 
198 Position
200  return myToDef.getGeomPosition();
201 }
202 
203 
204 void
206  assert(myNode == -1);
207  myNode = nodeid;
208 }
209 
210 
211 void
213  if (myGeom.size() > 0) {
214  return;
215  }
218 }
219 
220 
221 unsigned int
223  unsigned int unsetConnections = 0;
224  // try to determine the connected edges
225  NBEdge* fromEdge = 0;
226  NBEdge* toEdge = 0;
228  if (vissimFrom->wasWithinAJunction()) {
229  // this edge was not built, try to get one that approaches it
230  vissimFrom = vissimFrom->getBestIncoming();
231  if (vissimFrom != 0) {
232  fromEdge = ec.retrievePossiblySplit(toString(vissimFrom->getID()), toString(getFromEdgeID()), true);
233  }
234  } else {
235  // this edge was built, try to get the proper part
237  }
239  if (vissimTo->wasWithinAJunction()) {
240  vissimTo = vissimTo->getBestOutgoing();
241  if (vissimTo != 0) {
242  toEdge = ec.retrievePossiblySplit(toString(vissimTo->getID()), toString(getToEdgeID()), true);
243  }
244  } else {
246  }
247 
248  // try to get the edges the current connection connects
249  /*
250  NBEdge *fromEdge = ec.retrievePossiblySplit(toString(getFromEdgeID()), toString(getToEdgeID()), true);
251  NBEdge *toEdge = ec.retrievePossiblySplit(toString(getToEdgeID()), toString(getFromEdgeID()), false);
252  */
253  if (fromEdge == 0 || toEdge == 0) {
254  WRITE_WARNING("Could not build connection between '" + toString(getFromEdgeID()) + "' and '" + toString(getToEdgeID()) + "'.");
255  return 1; // !!! actually not 1
256  }
257  recheckLanes(fromEdge, toEdge);
258  const std::vector<int>& fromLanes = getFromLanes();
259  const std::vector<int>& toLanes = getToLanes();
260  if (fromLanes.size() != toLanes.size()) {
261  WRITE_WARNING("Lane sizes differ for connection '" + toString(getID()) + "'.");
262  } else {
263  for (unsigned int index = 0; index < fromLanes.size(); ++index) {
264  if (fromEdge->getNumLanes() <= static_cast<unsigned int>(fromLanes[index])) {
265  WRITE_WARNING("Could not set connection between '" + fromEdge->getID() + "_" + toString(fromLanes[index]) + "' and '" + toEdge->getID() + "_" + toString(toLanes[index]) + "'.");
266  ++unsetConnections;
267  } else if (!fromEdge->addLane2LaneConnection(fromLanes[index], toEdge, toLanes[index], NBEdge::L2L_VALIDATED)) {
268  WRITE_WARNING("Could not set connection between '" + fromEdge->getID() + "_" + toString(fromLanes[index]) + "' and '" + toEdge->getID() + "_" + toString(toLanes[index]) + "'.");
269  ++unsetConnections;
270  }
271  }
272  }
273  return unsetConnections;
274 }
275 
276 
277 void
279  unsigned int unsetConnections = 0;
280  // go through connections
281  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
282  unsetConnections += (*i).second->buildEdgeConnections(ec);
283  }
284  if (unsetConnections != 0) {
285  WRITE_WARNING(toString<size_t>(unsetConnections) + " of " + toString<size_t>(myDict.size()) + " connections could not be assigned.");
286  }
287 }
288 
289 
290 const std::vector<int>&
292  return myFromDef.getLanes();
293 }
294 
295 
296 const std::vector<int>&
298  return myToDef.getLanes();
299 }
300 
301 
302 void
303 NIVissimConnection::recheckLanes(const NBEdge* const fromEdge, const NBEdge* const toEdge) {
304  myFromDef.recheckLanes(fromEdge);
305  myToDef.recheckLanes(toEdge);
306 }
307 
308 
309 const Boundary&
311  assert(myBoundary != 0 && myBoundary->xmax() >= myBoundary->xmin());
312  return *myBoundary;
313 }
314 
315 
316 void
318  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
319  NIVissimConnection* c = (*i).second;
320  NIVissimEdge::dictionary(c->getFromEdgeID())->addOutgoingConnection((*i).first);
321  NIVissimEdge::dictionary(c->getToEdgeID())->addIncomingConnection((*i).first);
322  }
323 }
324 
325 
326 int
328  return myMaxID;
329 }
330 
331 
332 /****************************************************************************/
333 
334 
SUMOReal getFromPosition() const
static DictType myDict
NBEdge * retrievePossiblySplit(const std::string &id, bool downstream) const
Tries to retrieve an edge, even if it is splitted.
Definition: NBEdgeCont.cpp:275
const std::vector< int > & getToLanes() const
static void dict_buildNBEdgeConnections(NBEdgeCont &ec)
void recheckLanes(const NBEdge *const edge)
Resets lane numbers if all lanes shall be used.
std::vector< NIVissimClosedLaneDef * > NIVissimClosedLanesVector
The representation of a single edge during network building.
Definition: NBEdge.h:71
std::map< int, NIVissimConnection * > DictType
SUMOReal xmin() const
Returns minimum x-coordinate.
Definition: Boundary.cpp:112
NIVissimClosedLanesVector myClosedLanes
bool addLane2LaneConnection(unsigned int fromLane, NBEdge *dest, unsigned int toLane, Lane2LaneInfoType type, bool mayUseSameDestination=false, bool mayDefinitelyPass=false)
Adds a connection between the specified this edge's lane and an approached one.
Definition: NBEdge.cpp:649
static bool dictionary(int id, NIVissimNodeCluster *o)
static void buildNodeClusters()
static bool dictionary(int id, NIVissimConnection *o)
SUMOReal xmax() const
Returns maximum x-coordinate.
Definition: Boundary.cpp:118
bool wasWithinAJunction() const
Returns whether this edge was found to be within a junction.
Definition: NIVissimEdge.h:113
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
Position getToGeomPosition() const
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
The connection was computed and validated.
Definition: NBEdge.h:116
A temporary storage for edges imported from Vissim.
Definition: NIVissimEdge.h:61
NIVissimExtendedEdgePoint myFromDef
static void dict_assignToEdges()
static std::vector< int > getWithin(const AbstractPoly &poly)
const std::string & getID() const
Returns the id.
Definition: Named.h:60
SUMOReal getToPosition() const
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
const std::vector< int > & getLanes() const
A list of positions.
void setNodeCluster(int nodeid)
NIVissimEdge * getBestOutgoing() const
unsigned int getNumLanes() const
Returns the number of lanes.
Definition: NBEdge.h:347
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:66
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:53
const Boundary & getBoundingBox() const
void push_back(const PositionVector &p)
Appends all positions from the given vector.
void add(SUMOReal x, SUMOReal y)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:76
void recheckLanes(const NBEdge *const fromEdge, const NBEdge *const toEdge)
Resets lane numbers if all lanes shall be used.
const std::vector< int > & getFromLanes() const
static bool dictionary(int id, const std::string &name, const std::string &type, int noLanes, SUMOReal zuschlag1, SUMOReal zuschlag2, SUMOReal length, const PositionVector &geom, const NIVissimClosedLanesVector &clv)
Adds the described item to the dictionary Builds the edge first.
NIVissimConnection(int id, const std::string &name, const NIVissimExtendedEdgePoint &from_def, const NIVissimExtendedEdgePoint &to_def, const PositionVector &geom, const std::vector< int > &assignedVehicles, const NIVissimClosedLanesVector &clv)
NIVissimEdge * getBestIncoming() const
#define SUMOReal
Definition: config.h:218
NIVissimExtendedEdgePoint myToDef
Position getFromGeomPosition() const
static std::vector< int > getForEdge(int edgeid, bool omitNodeAssigned=true)
unsigned int buildEdgeConnections(NBEdgeCont &ec)