Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Fixes edge-based CH problem with u-turns at virtual edges, fixes #1593 #1596
Let's say there are edges like this: 0-1-2 with edge-ids 0:0-1 and 1:1-2 and a shortcut gets introduced from 0 to 2 (skipping 1) (with id 2). Then there is a virtual node (id 3) between 1 and 2 like this: 1-(3)-2 which will add some virtual edges 3:1-3 and 4:3-2. When we detect u-turns we compare the edge ids. So if we travel via the shortcut from 0 to 2 we arrive at 2 with the shortcut id 2, but to calculate the turn costs we use the 'origEdgeLast' (here this is the edge 1-2 with id 1). When we check if going to the virtual node 3 is a u-turn we used to check 1==4 which tells us it is no u-turn (when in reality it is). So instead of the virtual edge id 4 we have to use the original edge id 1 for the comparison.
An important case is also checking for a u-turn at node 3 when coming from node 1 and going to node 2. In this case we must not use the original edge id (1) for both virtual edges, but instead compare 3==4.
In this PR I have:
Ultimately I think the u-turn detection needs some more sophisticated refactoring and we should get rid of the
Wow the necessary detailed tests are many. Thanks for accepting this challenge :)
BTW: We could need a cleaner solution to this virtual edges problem that bites us again and again :/ ... but any solution that comes to my mind (that does not use virtual edges) becomes tricky with all the special cases like many virtual nodes on one original edge etc and then we have this in every algorithm instead just in the QueryGraph and only some "tiny tricks" in the algorithm like here.
I would not say they are all strictly necessary and maybe they could even be simplified / made a bit more to the point. During development I had a few more and already deleted some again. The most important is the random one, because you can just have it running for a while and it spits out some failing cases, which was really helpful to arrive at a solution (now I think it is green).
I think the