Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
NIVissimConnection.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
22// -------------------
23/****************************************************************************/
24#include <config.h>
25
26#include <string>
27#include <map>
28#include <iostream>
29#include <cassert>
35#include <utils/geom/Boundary.h>
37#include <netbuild/NBEdge.h>
38#include <netbuild/NBNode.h>
39#include <netbuild/NBEdgeCont.h>
40#include "NIVissimEdge.h"
42#include "NIVissimNodeDef.h"
43#include "NIVissimConnection.h"
45
46
47// ===========================================================================
48// static members
49// ===========================================================================
52
53
54// ===========================================================================
55// method definitions
56// ===========================================================================
58 const std::string& name, const NIVissimExtendedEdgePoint& from_def,
59 const NIVissimExtendedEdgePoint& to_def,
60 const PositionVector& geom,
61 const std::vector<int>& assignedVehicles, const NIVissimClosedLanesVector& clv)
62 : NIVissimAbstractEdge(id, geom),
63 myName(name), myFromDef(from_def), myToDef(to_def),
64 myAssignedVehicles(assignedVehicles), myClosedLanes(clv) {}
65
66
68 for (NIVissimClosedLanesVector::iterator i = myClosedLanes.begin(); i != myClosedLanes.end(); i++) {
69 delete (*i);
70 }
71 myClosedLanes.clear();
72}
73
74
75bool
77 DictType::iterator i = myDict.find(id);
78 if (i == myDict.end()) {
79 myDict[id] = o;
80 return true;
81 }
82 return false;
83}
84
85
86
89 DictType::iterator i = myDict.find(id);
90 if (i == myDict.end()) {
91 return nullptr;
92 }
93 return (*i).second;
94}
95
96
97void
99 for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
100 NIVissimConnection* e = (*i).second;
101 if (!e->clustered()) {
102 assert(e->myBoundary != 0 && e->myBoundary->xmax() > e->myBoundary->xmin());
103 std::vector<int> connections =
105 NIVissimNodeCluster::dictionary(-1, -1, connections,
106 std::vector<int>(), true); // 19.5.!!! should be on a single edge
107 }
108 }
109}
110
111
112
113
114
115std::vector<int>
117 std::vector<int> ret;
118 for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
119 if ((*i).second->crosses(poly)) {
120 ret.push_back((*i).second->myID);
121 }
122 }
123 return ret;
124}
125
126
127void
129 Boundary* bound = new Boundary();
130 bound->add(myFromDef.getGeomPosition());
131 bound->add(myToDef.getGeomPosition());
132 assert(myBoundary == 0);
133 myBoundary = bound;
134}
135
136
137std::vector<int>
138NIVissimConnection::getForEdge(int edgeid, bool /*omitNodeAssigned*/) {
139 std::vector<int> ret;
140 for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
141 int connID = (*i).first;
142 if ((*i).second->myFromDef.getEdgeID() == edgeid
143 ||
144 (*i).second->myToDef.getEdgeID() == edgeid) {
145 if (!(*i).second->hasNodeCluster()) {
146 ret.push_back(connID);
147 }
148 }
149 }
150 return ret;
151}
152
153
154int
158
159
160int
164
165
166double
170
171
172double
176
177
182
183
184
189
190
191void
193 assert(myNode == -1);
194 myNode = nodeid;
195}
196
197
198void
200 if (myGeom.size() > 0) {
201 return;
202 }
203 myGeom.push_back(myFromDef.getGeomPosition());
204 myGeom.push_back(myToDef.getGeomPosition());
205}
206
207
208int
210 int unsetConnections = 0;
211 // try to determine the connected edges
212 NBEdge* fromEdge = nullptr;
213 NBEdge* toEdge = nullptr;
215 if (vissimFrom->wasWithinAJunction()) {
216 // this edge was not built, try to get one that approaches it
217 vissimFrom = vissimFrom->getBestIncoming();
218 if (vissimFrom != nullptr) {
219 fromEdge = ec.retrievePossiblySplit(toString(vissimFrom->getID()), toString(getFromEdgeID()), true);
220 }
221 } else {
222 // this edge was built, try to get the proper part
224 }
226 if (vissimTo->wasWithinAJunction()) {
227 vissimTo = vissimTo->getBestOutgoing();
228 if (vissimTo != nullptr) {
229 toEdge = ec.retrievePossiblySplit(toString(vissimTo->getID()), toString(getToEdgeID()), true);
230 }
231 } else {
233 }
234
235 // try to get the edges the current connection connects
236 /*
237 NBEdge *fromEdge = ec.retrievePossiblySplit(toString(getFromEdgeID()), toString(getToEdgeID()), true);
238 NBEdge *toEdge = ec.retrievePossiblySplit(toString(getToEdgeID()), toString(getFromEdgeID()), false);
239 */
240 if (fromEdge == nullptr || toEdge == nullptr) {
241 WRITE_WARNINGF(TL("Could not build connection between '%' and '%'."), toString(getFromEdgeID()), toString(getToEdgeID()));
242 return 1; // !!! actually not 1
243 }
244 recheckLanes(fromEdge, toEdge);
245 const std::vector<int>& fromLanes = getFromLanes();
246 const std::vector<int>& toLanes = getToLanes();
247 if (fromLanes.size() != toLanes.size()) {
248 WRITE_WARNINGF(TL("Lane sizes differ for connection '%'."), toString(getID()));
249 } else {
250 for (int index = 0; index < (int)fromLanes.size(); ++index) {
251 if (fromEdge->getNumLanes() <= fromLanes[index]) {
252 WRITE_WARNING("Could not set connection between '" + fromEdge->getID() + "_" + toString(fromLanes[index]) + "' and '" + toEdge->getID() + "_" + toString(toLanes[index]) + "'.");
253 ++unsetConnections;
254 } else if (!fromEdge->addLane2LaneConnection(fromLanes[index], toEdge, toLanes[index], NBEdge::Lane2LaneInfoType::VALIDATED, true)) {
255 WRITE_WARNING("Could not set connection between '" + fromEdge->getID() + "_" + toString(fromLanes[index]) + "' and '" + toEdge->getID() + "_" + toString(toLanes[index]) + "'.");
256 ++unsetConnections;
257 }
258 }
259 }
260 return unsetConnections;
261}
262
263
264void
266 int unsetConnections = 0;
267 // go through connections
268 for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
269 unsetConnections += (*i).second->buildEdgeConnections(ec);
270 }
271 if (unsetConnections != 0) {
272 WRITE_WARNING(toString<int>(unsetConnections) + " of " + toString<int>((int)myDict.size()) + " connections could not be assigned.");
273 }
274}
275
276
277const std::vector<int>&
281
282
283const std::vector<int>&
287
288
289void
290NIVissimConnection::recheckLanes(const NBEdge* const fromEdge, const NBEdge* const toEdge) {
291 myFromDef.recheckLanes(fromEdge);
292 myToDef.recheckLanes(toEdge);
293}
294
295
296const Boundary&
298 assert(myBoundary != 0 && myBoundary->xmax() >= myBoundary->xmin());
299 return *myBoundary;
300}
301
302
303void
305 for (DictType::iterator i = myDict.begin(); i != myDict.end(); i++) {
306 NIVissimConnection* c = (*i).second;
307 NIVissimEdge::dictionary(c->getFromEdgeID())->addOutgoingConnection((*i).first);
308 NIVissimEdge::dictionary(c->getToEdgeID())->addIncomingConnection((*i).first);
309 }
310}
311
312
313int
317
318
319/****************************************************************************/
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:296
#define WRITE_WARNING(msg)
Definition MsgHandler.h:295
#define TL(string)
Definition MsgHandler.h:315
std::vector< NIVissimClosedLaneDef * > NIVissimClosedLanesVector
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
A class that stores a 2D geometrical boundary.
Definition Boundary.h:39
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition Boundary.cpp:78
double xmin() const
Returns minimum x-coordinate.
Definition Boundary.cpp:118
double xmax() const
Returns maximum x-coordinate.
Definition Boundary.cpp:124
Storage for edges, including some functionality operating on multiple edges.
Definition NBEdgeCont.h:59
NBEdge * retrievePossiblySplit(const std::string &id, bool downstream) const
Tries to retrieve an edge, even if it is splitted.
The representation of a single edge during network building.
Definition NBEdge.h:92
bool addLane2LaneConnection(int fromLane, NBEdge *dest, int toLane, Lane2LaneInfoType type, bool mayUseSameDestination=false, bool mayDefinitelyPass=false, KeepClear keepClear=KEEPCLEAR_UNSPECIFIED, double contPos=UNSPECIFIED_CONTPOS, double visibility=UNSPECIFIED_VISIBILITY_DISTANCE, double speed=UNSPECIFIED_SPEED, double friction=UNSPECIFIED_FRICTION, double length=myDefaultConnectionLength, const PositionVector &customShape=PositionVector::EMPTY, const bool uncontrolled=UNSPECIFIED_CONNECTION_UNCONTROLLED, SVCPermissions permissions=SVC_UNSPECIFIED, const bool indirectLeft=false, const std::string &edgeType="", SVCPermissions changeLeft=SVC_UNSPECIFIED, SVCPermissions changeRight=SVC_UNSPECIFIED, bool postProcess=false)
Adds a connection between the specified this edge's lane and an approached one.
Definition NBEdge.cpp:1133
const std::string & getID() const
Definition NBEdge.h:1528
int getNumLanes() const
Returns the number of lanes.
Definition NBEdge.h:520
@ VALIDATED
The connection was computed and validated.
static void buildNodeClusters()
NIVissimExtendedEdgePoint myToDef
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)
static std::vector< int > getWithin(const AbstractPoly &poly)
const std::vector< int > & getFromLanes() const
static void dict_buildNBEdgeConnections(NBEdgeCont &ec)
double getFromPosition() const
void setNodeCluster(int nodeid)
static std::vector< int > getForEdge(int edgeid, bool omitNodeAssigned=true)
NIVissimExtendedEdgePoint myFromDef
const Boundary & getBoundingBox() const
int buildEdgeConnections(NBEdgeCont &ec)
const std::vector< int > & getToLanes() const
static void dict_assignToEdges()
static bool dictionary(int id, NIVissimConnection *o)
Position getToGeomPosition() const
std::map< int, NIVissimConnection * > DictType
NIVissimClosedLanesVector myClosedLanes
Position getFromGeomPosition() const
void recheckLanes(const NBEdge *const fromEdge, const NBEdge *const toEdge)
Resets lane numbers if all lanes shall be used.
A temporary storage for edges imported from Vissim.
NIVissimEdge * getBestOutgoing() const
NIVissimEdge * getBestIncoming() const
bool wasWithinAJunction() const
Returns whether this edge was found to be within a junction.
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.
void recheckLanes(const NBEdge *const edge)
Resets lane numbers if all lanes shall be used.
const std::vector< int > & getLanes() const
static bool dictionary(int id, NIVissimNodeCluster *o)
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.