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-2017 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 
56 // ===========================================================================
57 // static members
58 // ===========================================================================
61 
62 
63 // ===========================================================================
64 // method definitions
65 // ===========================================================================
67  const std::string& name, const NIVissimExtendedEdgePoint& from_def,
68  const NIVissimExtendedEdgePoint& to_def,
69  const PositionVector& geom,
70  const std::vector<int>& assignedVehicles, const NIVissimClosedLanesVector& clv)
71  : NIVissimAbstractEdge(id, geom),
72  myName(name), myFromDef(from_def), myToDef(to_def),
73  myAssignedVehicles(assignedVehicles), myClosedLanes(clv) {}
74 
75 
77  for (NIVissimClosedLanesVector::iterator i = myClosedLanes.begin(); i != myClosedLanes.end(); i++) {
78  delete(*i);
79  }
80  myClosedLanes.clear();
81 }
82 
83 
84 bool
86  DictType::iterator i = myDict.find(id);
87  if (i == myDict.end()) {
88  myDict[id] = o;
89  return true;
90  }
91  return false;
92 }
93 
94 
95 
98  DictType::iterator i = myDict.find(id);
99  if (i == myDict.end()) {
100  return 0;
101  }
102  return (*i).second;
103 }
104 
105 
106 void
108  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
109  NIVissimConnection* e = (*i).second;
110  if (!e->clustered()) {
111  assert(e->myBoundary != 0 && e->myBoundary->xmax() > e->myBoundary->xmin());
112  std::vector<int> connections =
114  NIVissimNodeCluster::dictionary(-1, -1, connections,
115  std::vector<int>(), true); // 19.5.!!! should be on a single edge
116  }
117  }
118 }
119 
120 
121 
122 
123 
124 std::vector<int>
126  std::vector<int> ret;
127  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
128  if ((*i).second->crosses(poly)) {
129  ret.push_back((*i).second->myID);
130  }
131  }
132  return ret;
133 }
134 
135 
136 void
138  Boundary* bound = new Boundary();
139  bound->add(myFromDef.getGeomPosition());
140  bound->add(myToDef.getGeomPosition());
141  assert(myBoundary == 0);
142  myBoundary = bound;
143 }
144 
145 
146 std::vector<int>
147 NIVissimConnection::getForEdge(int edgeid, bool /*omitNodeAssigned*/) {
148  std::vector<int> ret;
149  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
150  int connID = (*i).first;
151  if ((*i).second->myFromDef.getEdgeID() == edgeid
152  ||
153  (*i).second->myToDef.getEdgeID() == edgeid) {
154  if (!(*i).second->hasNodeCluster()) {
155  ret.push_back(connID);
156  }
157  }
158  }
159  return ret;
160 }
161 
162 
163 int
165  return myFromDef.getEdgeID();
166 }
167 
168 
169 int
171  return myToDef.getEdgeID();
172 }
173 
174 
175 double
177  return myFromDef.getPosition();
178 }
179 
180 
181 double
183  return myToDef.getPosition();
184 }
185 
186 
187 Position
189  return myFromDef.getGeomPosition();
190 }
191 
192 
193 
194 Position
196  return myToDef.getGeomPosition();
197 }
198 
199 
200 void
202  assert(myNode == -1);
203  myNode = nodeid;
204 }
205 
206 
207 void
209  if (myGeom.size() > 0) {
210  return;
211  }
212  myGeom.push_back(myFromDef.getGeomPosition());
213  myGeom.push_back(myToDef.getGeomPosition());
214 }
215 
216 
217 int
219  int unsetConnections = 0;
220  // try to determine the connected edges
221  NBEdge* fromEdge = 0;
222  NBEdge* toEdge = 0;
224  if (vissimFrom->wasWithinAJunction()) {
225  // this edge was not built, try to get one that approaches it
226  vissimFrom = vissimFrom->getBestIncoming();
227  if (vissimFrom != 0) {
228  fromEdge = ec.retrievePossiblySplit(toString(vissimFrom->getID()), toString(getFromEdgeID()), true);
229  }
230  } else {
231  // this edge was built, try to get the proper part
233  }
235  if (vissimTo->wasWithinAJunction()) {
236  vissimTo = vissimTo->getBestOutgoing();
237  if (vissimTo != 0) {
238  toEdge = ec.retrievePossiblySplit(toString(vissimTo->getID()), toString(getToEdgeID()), true);
239  }
240  } else {
242  }
243 
244  // try to get the edges the current connection connects
245  /*
246  NBEdge *fromEdge = ec.retrievePossiblySplit(toString(getFromEdgeID()), toString(getToEdgeID()), true);
247  NBEdge *toEdge = ec.retrievePossiblySplit(toString(getToEdgeID()), toString(getFromEdgeID()), false);
248  */
249  if (fromEdge == 0 || toEdge == 0) {
250  WRITE_WARNING("Could not build connection between '" + toString(getFromEdgeID()) + "' and '" + toString(getToEdgeID()) + "'.");
251  return 1; // !!! actually not 1
252  }
253  recheckLanes(fromEdge, toEdge);
254  const std::vector<int>& fromLanes = getFromLanes();
255  const std::vector<int>& toLanes = getToLanes();
256  if (fromLanes.size() != toLanes.size()) {
257  WRITE_WARNING("Lane sizes differ for connection '" + toString(getID()) + "'.");
258  } else {
259  for (int index = 0; index < (int)fromLanes.size(); ++index) {
260  if (fromEdge->getNumLanes() <= fromLanes[index]) {
261  WRITE_WARNING("Could not set connection between '" + fromEdge->getID() + "_" + toString(fromLanes[index]) + "' and '" + toEdge->getID() + "_" + toString(toLanes[index]) + "'.");
262  ++unsetConnections;
263  } else if (!fromEdge->addLane2LaneConnection(fromLanes[index], toEdge, toLanes[index], NBEdge::L2L_VALIDATED)) {
264  WRITE_WARNING("Could not set connection between '" + fromEdge->getID() + "_" + toString(fromLanes[index]) + "' and '" + toEdge->getID() + "_" + toString(toLanes[index]) + "'.");
265  ++unsetConnections;
266  }
267  }
268  }
269  return unsetConnections;
270 }
271 
272 
273 void
275  int unsetConnections = 0;
276  // go through connections
277  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
278  unsetConnections += (*i).second->buildEdgeConnections(ec);
279  }
280  if (unsetConnections != 0) {
281  WRITE_WARNING(toString<int>(unsetConnections) + " of " + toString<int>((int)myDict.size()) + " connections could not be assigned.");
282  }
283 }
284 
285 
286 const std::vector<int>&
288  return myFromDef.getLanes();
289 }
290 
291 
292 const std::vector<int>&
294  return myToDef.getLanes();
295 }
296 
297 
298 void
299 NIVissimConnection::recheckLanes(const NBEdge* const fromEdge, const NBEdge* const toEdge) {
300  myFromDef.recheckLanes(fromEdge);
301  myToDef.recheckLanes(toEdge);
302 }
303 
304 
305 const Boundary&
307  assert(myBoundary != 0 && myBoundary->xmax() >= myBoundary->xmin());
308  return *myBoundary;
309 }
310 
311 
312 void
314  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
315  NIVissimConnection* c = (*i).second;
316  NIVissimEdge::dictionary(c->getFromEdgeID())->addOutgoingConnection((*i).first);
317  NIVissimEdge::dictionary(c->getToEdgeID())->addIncomingConnection((*i).first);
318  }
319 }
320 
321 
322 int
324  return myMaxID;
325 }
326 
327 
328 /****************************************************************************/
329 
330 
static DictType myDict
double xmax() const
Returns maximum x-coordinate.
Definition: Boundary.cpp:132
static void dict_buildNBEdgeConnections(NBEdgeCont &ec)
void recheckLanes(const NBEdge *const edge)
Resets lane numbers if all lanes shall be used.
const std::vector< int > & getFromLanes() const
std::vector< NIVissimClosedLaneDef * > NIVissimClosedLanesVector
The representation of a single edge during network building.
Definition: NBEdge.h:71
std::map< int, NIVissimConnection * > DictType
NIVissimClosedLanesVector myClosedLanes
static bool dictionary(int id, NIVissimNodeCluster *o)
static void buildNodeClusters()
const std::vector< int > & getToLanes() const
static bool dictionary(int id, NIVissimConnection *o)
const std::string & getID() const
Returns the id.
Definition: Named.h:66
NIVissimEdge * getBestIncoming() const
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
The connection was computed and validated.
Definition: NBEdge.h:117
A temporary storage for edges imported from Vissim.
Definition: NIVissimEdge.h:60
NIVissimExtendedEdgePoint myFromDef
static void dict_assignToEdges()
NIVissimEdge * getBestOutgoing() const
static std::vector< int > getWithin(const AbstractPoly &poly)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
NBEdge * retrievePossiblySplit(const std::string &id, bool downstream) const
Tries to retrieve an edge, even if it is splitted.
Definition: NBEdgeCont.cpp:287
int getNumLanes() const
Returns the number of lanes.
Definition: NBEdge.h:413
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
A list of positions.
void setNodeCluster(int nodeid)
const Boundary & getBoundingBox() const
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:66
double xmin() const
Returns minimum x-coordinate.
Definition: Boundary.cpp:126
static bool dictionary(int id, const std::string &name, const std::string &type, int noLanes, double zuschlag1, double zuschlag2, double length, const PositionVector &geom, const NIVissimClosedLanesVector &clv)
Adds the described item to the dictionary Builds the edge first.
const std::vector< int > & getLanes() const
double getToPosition() const
void recheckLanes(const NBEdge *const fromEdge, const NBEdge *const toEdge)
Resets lane numbers if all lanes shall be used.
int buildEdgeConnections(NBEdgeCont &ec)
Position getToGeomPosition() const
bool wasWithinAJunction() const
Returns whether this edge was found to be within a junction.
Definition: NIVissimEdge.h:112
bool addLane2LaneConnection(int fromLane, NBEdge *dest, int toLane, Lane2LaneInfoType type, bool mayUseSameDestination=false, bool mayDefinitelyPass=false, bool keepClear=true, double contPos=UNSPECIFIED_CONTPOS, double visibility=UNSPECIFIED_VISIBILITY_DISTANCE)
Adds a connection between the specified this edge&#39;s lane and an approached one.
Definition: NBEdge.cpp:900
Position getFromGeomPosition() const
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)
NIVissimExtendedEdgePoint myToDef
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:86
static std::vector< int > getForEdge(int edgeid, bool omitNodeAssigned=true)
double getFromPosition() const