eclipse-sumo / sumo

Eclipse SUMO is an open source, highly portable, microscopic and continuous traffic simulation package designed to handle large networks. It allows for intermodal simulation including pedestrians and comes with a large set of tools for scenario creation.
https://eclipse.dev/sumo
Eclipse Public License 2.0
2.58k stars 1.45k forks source link

sumolib.net.Net.getNeighboringLanes with default parameter gives wrong results #5854

Open zsambokiandras opened 5 years ago

zsambokiandras commented 5 years ago

The includeJunctions parameter is True by default, which gives wrong results for lots of different points in a large junction: points don't get matched to the internal lanes, but to the extra line segment between the node center and the first/last point of the wrong lane.

getNeighboringLanes uses sumolib.net.lane.Lane.getShape, where the same parameter is False by default. I suggest changing the default value to False, as the result seems more like the correct behaviour.

The following images show the difference between the two parameter values. Regular lanes are blue, the internal lanes are dotted gray, the nodes are large gray dots and the node shapes are thin dashed gray.

includeJunctionsTrueincludeJunctionsFalse

The default value is also True in getNeighboringEdges, where there is no check if it's an internal edge, all edges are connected to the end node(s).

behrisch commented 5 years ago

Maybe the name of the includeJunctions parameter is misleading. It does not refer to the internal edges of the junction but it only adds the junction points to the lane / edge shape before matching. Did you parse the network with internal junctions enabled? If so, can you please provide the exact code and the inputs you used?

zsambokiandras commented 5 years ago

The network doesn't have internal junctions, although I parse the internal edges/lanes. Here is a simplified example: net.zip and the console output.

In [1]: from sumolib.net import readNet
   ...: net = readNet('includejunctions.net.xml', withInternals=True)

In [2]: net.getLane('e0_0').getShape(includeJunctions=True)
Out[2]: [(0.0, 0.0), (0.0, -3.5), (45.0, -3.5), (50.0, 0.0)]

In [3]: net.getLane('e0_0').getShape(includeJunctions=False)
Out[3]: [(0.0, -3.5), (45.0, -3.5)]

In [4]: net.getEdge('e0').getShape(includeJunctions=True)
Out[4]: [(0.0, 0.0), (45.0, 0.0), (50.0, 0.0)]

In [5]: net.getEdge('e0').getShape(includeJunctions=False)
Out[5]: [(0.0, 0.0), (45.0, 0.0)]

In [6]: net.getLane(':n1_0_0').getShape(includeJunctions=True)
Out[6]: [(45.0, -3.5), (55.0, -3.5)]

In [7]: net.getLane(':n1_0_0').getShape(includeJunctions=False)
Out[7]: [(45.0, -3.5), (55.0, -3.5)]

In [8]: net.getEdge(':n1_0').getShape(includeJunctions=True)
Out[8]: [(50.0, 0.0), (45.0, 0.0), (55.0, 0.0), (50.0, 0.0)]

In [9]: net.getEdge(':n1_0').getShape(includeJunctions=False)
Out[9]: [(45.0, 0.0), (55.0, 0.0)]

I think the default value of includeJunctions should be False, because if the network has internal lanes, getShape gives wrong results. The result of command [8] shows that includeJunctions can't be used for internal edges, it prepends and appends the node's coordinates to the start and end points of the internal edge. For internal lanes, command [6] and [7] shows the expected result, omitting the node's coordinates.

namdre commented 4 years ago

I think I get the point. If you want to find internal lanes on a junction, it is annoying to also get the normal edges because their shape has been artificially extended.

zsambokiandras commented 4 years ago

Yes, this was my point. This behavior is documented at the Lane.getShape function. I found the includeJunctions parameter name misleading in the Net.getNeighboringLanes case, I thought this would enable or disable finding the closest internal lanes.

behrisch commented 3 years ago

enhancing the documentation is the most important step here. Maybe we could rename / deprecate the parameters of the function later.