SUMO - Simulation of Urban MObility
NIVissimConnection.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 /****************************************************************************/
21 // -------------------
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <string>
35 #include <map>
36 #include <iostream>
37 #include <cassert>
40 #include <utils/common/ToString.h>
43 #include <utils/geom/Boundary.h>
44 #include <utils/geom/GeomHelper.h>
45 #include <netbuild/NBEdge.h>
46 #include <netbuild/NBNode.h>
47 #include <netbuild/NBEdgeCont.h>
48 #include "NIVissimEdge.h"
50 #include "NIVissimNodeDef.h"
51 #include "NIVissimConnection.h"
53 
54 
55 // ===========================================================================
56 // static members
57 // ===========================================================================
60 
61 
62 // ===========================================================================
63 // method definitions
64 // ===========================================================================
66  const std::string& name, const NIVissimExtendedEdgePoint& from_def,
67  const NIVissimExtendedEdgePoint& to_def,
68  const PositionVector& geom,
69  const std::vector<int>& assignedVehicles, const NIVissimClosedLanesVector& clv)
70  : NIVissimAbstractEdge(id, geom),
71  myName(name), myFromDef(from_def), myToDef(to_def),
72  myAssignedVehicles(assignedVehicles), myClosedLanes(clv) {}
73 
74 
76  for (NIVissimClosedLanesVector::iterator i = myClosedLanes.begin(); i != myClosedLanes.end(); i++) {
77  delete(*i);
78  }
79  myClosedLanes.clear();
80 }
81 
82 
83 bool
85  DictType::iterator i = myDict.find(id);
86  if (i == myDict.end()) {
87  myDict[id] = o;
88  return true;
89  }
90  return false;
91 }
92 
93 
94 
97  DictType::iterator i = myDict.find(id);
98  if (i == myDict.end()) {
99  return 0;
100  }
101  return (*i).second;
102 }
103 
104 
105 void
107  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
108  NIVissimConnection* e = (*i).second;
109  if (!e->clustered()) {
110  assert(e->myBoundary != 0 && e->myBoundary->xmax() > e->myBoundary->xmin());
111  std::vector<int> connections =
113  NIVissimNodeCluster::dictionary(-1, -1, connections,
114  std::vector<int>(), true); // 19.5.!!! should be on a single edge
115  }
116  }
117 }
118 
119 
120 
121 
122 
123 std::vector<int>
125  std::vector<int> ret;
126  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
127  if ((*i).second->crosses(poly)) {
128  ret.push_back((*i).second->myID);
129  }
130  }
131  return ret;
132 }
133 
134 
135 void
137  Boundary* bound = new Boundary();
138  bound->add(myFromDef.getGeomPosition());
139  bound->add(myToDef.getGeomPosition());
140  assert(myBoundary == 0);
141  myBoundary = bound;
142 }
143 
144 
145 std::vector<int>
146 NIVissimConnection::getForEdge(int edgeid, bool /*omitNodeAssigned*/) {
147  std::vector<int> ret;
148  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
149  int connID = (*i).first;
150  if ((*i).second->myFromDef.getEdgeID() == edgeid
151  ||
152  (*i).second->myToDef.getEdgeID() == edgeid) {
153  if (!(*i).second->hasNodeCluster()) {
154  ret.push_back(connID);
155  }
156  }
157  }
158  return ret;
159 }
160 
161 
162 int
164  return myFromDef.getEdgeID();
165 }
166 
167 
168 int
170  return myToDef.getEdgeID();
171 }
172 
173 
174 double
176  return myFromDef.getPosition();
177 }
178 
179 
180 double
182  return myToDef.getPosition();
183 }
184 
185 
186 Position
188  return myFromDef.getGeomPosition();
189 }
190 
191 
192 
193 Position
195  return myToDef.getGeomPosition();
196 }
197 
198 
199 void
201  assert(myNode == -1);
202  myNode = nodeid;
203 }
204 
205 
206 void
208  if (myGeom.size() > 0) {
209  return;
210  }
211  myGeom.push_back(myFromDef.getGeomPosition());
212  myGeom.push_back(myToDef.getGeomPosition());
213 }
214 
215 
216 int
218  int unsetConnections = 0;
219  // try to determine the connected edges
220  NBEdge* fromEdge = 0;
221  NBEdge* toEdge = 0;
223  if (vissimFrom->wasWithinAJunction()) {
224  // this edge was not built, try to get one that approaches it
225  vissimFrom = vissimFrom->getBestIncoming();
226  if (vissimFrom != 0) {
227  fromEdge = ec.retrievePossiblySplit(toString(vissimFrom->getID()), toString(getFromEdgeID()), true);
228  }
229  } else {
230  // this edge was built, try to get the proper part
232  }
234  if (vissimTo->wasWithinAJunction()) {
235  vissimTo = vissimTo->getBestOutgoing();
236  if (vissimTo != 0) {
237  toEdge = ec.retrievePossiblySplit(toString(vissimTo->getID()), toString(getToEdgeID()), true);
238  }
239  } else {
241  }
242 
243  // try to get the edges the current connection connects
244  /*
245  NBEdge *fromEdge = ec.retrievePossiblySplit(toString(getFromEdgeID()), toString(getToEdgeID()), true);
246  NBEdge *toEdge = ec.retrievePossiblySplit(toString(getToEdgeID()), toString(getFromEdgeID()), false);
247  */
248  if (fromEdge == 0 || toEdge == 0) {
249  WRITE_WARNING("Could not build connection between '" + toString(getFromEdgeID()) + "' and '" + toString(getToEdgeID()) + "'.");
250  return 1; // !!! actually not 1
251  }
252  recheckLanes(fromEdge, toEdge);
253  const std::vector<int>& fromLanes = getFromLanes();
254  const std::vector<int>& toLanes = getToLanes();
255  if (fromLanes.size() != toLanes.size()) {
256  WRITE_WARNING("Lane sizes differ for connection '" + toString(getID()) + "'.");
257  } else {
258  for (int index = 0; index < (int)fromLanes.size(); ++index) {
259  if (fromEdge->getNumLanes() <= fromLanes[index]) {
260  WRITE_WARNING("Could not set connection between '" + fromEdge->getID() + "_" + toString(fromLanes[index]) + "' and '" + toEdge->getID() + "_" + toString(toLanes[index]) + "'.");
261  ++unsetConnections;
262  } else if (!fromEdge->addLane2LaneConnection(fromLanes[index], toEdge, toLanes[index], NBEdge::L2L_VALIDATED)) {
263  WRITE_WARNING("Could not set connection between '" + fromEdge->getID() + "_" + toString(fromLanes[index]) + "' and '" + toEdge->getID() + "_" + toString(toLanes[index]) + "'.");
264  ++unsetConnections;
265  }
266  }
267  }
268  return unsetConnections;
269 }
270 
271 
272 void
274  int unsetConnections = 0;
275  // go through connections
276  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
277  unsetConnections += (*i).second->buildEdgeConnections(ec);
278  }
279  if (unsetConnections != 0) {
280  WRITE_WARNING(toString<int>(unsetConnections) + " of " + toString<int>((int)myDict.size()) + " connections could not be assigned.");
281  }
282 }
283 
284 
285 const std::vector<int>&
287  return myFromDef.getLanes();
288 }
289 
290 
291 const std::vector<int>&
293  return myToDef.getLanes();
294 }
295 
296 
297 void
298 NIVissimConnection::recheckLanes(const NBEdge* const fromEdge, const NBEdge* const toEdge) {
299  myFromDef.recheckLanes(fromEdge);
300  myToDef.recheckLanes(toEdge);
301 }
302 
303 
304 const Boundary&
306  assert(myBoundary != 0 && myBoundary->xmax() >= myBoundary->xmin());
307  return *myBoundary;
308 }
309 
310 
311 void
313  for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
314  NIVissimConnection* c = (*i).second;
315  NIVissimEdge::dictionary(c->getFromEdgeID())->addOutgoingConnection((*i).first);
316  NIVissimEdge::dictionary(c->getToEdgeID())->addIncomingConnection((*i).first);
317  }
318 }
319 
320 
321 int
323  return myMaxID;
324 }
325 
326 
327 /****************************************************************************/
328 
329 
static DictType myDict
double xmax() const
Returns maximum x-coordinate.
Definition: Boundary.cpp:131
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:70
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:74
NIVissimEdge * getBestIncoming() const
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:47
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:199
The connection was computed and validated.
Definition: NBEdge.h:114
A temporary storage for edges imported from Vissim.
Definition: NIVissimEdge.h:59
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:55
NBEdge * retrievePossiblySplit(const std::string &id, bool downstream) const
Tries to retrieve an edge, even if it is splitted.
Definition: NBEdgeCont.cpp:286
int getNumLanes() const
Returns the number of lanes.
Definition: NBEdge.h:412
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
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:125
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 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, double speed=UNSPECIFIED_SPEED, const PositionVector &customShape=PositionVector::EMPTY)
Adds a connection between the specified this edge&#39;s lane and an approached one.
Definition: NBEdge.cpp:921
bool wasWithinAJunction() const
Returns whether this edge was found to be within a junction.
Definition: NIVissimEdge.h:111
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:85
static std::vector< int > getForEdge(int edgeid, bool omitNodeAssigned=true)
double getFromPosition() const