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