Skip to content

Preparing support of turn restrictions (4): Introducing edge-based routing algorithms - #158

Closed
kschrab wants to merge 3 commits into
graphhopper:masterfrom
kschrab:master
Closed

kschrab wants to merge 3 commits into
graphhopper:masterfrom
kschrab:master

Conversation

@kschrab

@kschrab kschrab commented Mar 5, 2014

Copy link
Copy Markdown
Contributor

This pull requests contents changes in AStar, Djikstra, DijkstraBidirectionRef and AStarBidirection which let those algorithms traverse edges instead of nodes. The edge-based behavior is necessary in order to fully support turn restrictions and P-turns in the resulting paths. Following changes have been made:

The prior implementation used the id of the adjacent node to access the map of shortest weights during traversal. An edge-based version of the same algorithms would use the id of the current edge instead of its adjacent node. Therefore, I added a method createIdentifier(EdgeIterator) in AbstractRoutingAlgorithm in order to move the desired traversal behavior to the super class. Additionally, the traversal mode can be defined in AbstractRoutingAlgorithm, which is either NODE_BASED (default behavior), EDGE_BASED or EDGE_BASED_DIRECTION_SENSITIVE (description can be found in the source). Several tiny adjustments in the inheriting routing algorithms have been made in order to support the different traversal modes.

Tests of those algorithms will be executed for each of the traversal modes by using parameterized tests. However, the bidirectional algorithms fail in three tests. I have no idea why this happens but I tried to describe the problem in the source (see AStarBidirectionTest).

Additionally, the adapted algorithms now consider turn restrictions/costs if the graph stores them in its extended storage. However, tests for turn restrictions/costs have not been written yet. This pull request solely aims to introduce the edge-based behavior to present routing algorithms.

DijkstraBidirectionRef and AStarBidirection. 

In order to share code, the present routing algorithms can now switch
between both node-based and edge-based behavior. Tests of those
algorithms are executed for each of the traversal modes using
parametrized tests.

Additionally, the adapted algorithms now consider turn
restrictions/costs if the graph stores them in its extended storage.
However, tests for turn restrictions/costs have not been written yet.
@karussell

Copy link
Copy Markdown
Member

Thanks a lot! I'll have a look.

I'm not sure if I understand the test thing. In one sentence you say some test fail in the next you say "have not been written yet". Do you mean existing test break and new are not written? If so, I would rather tend to have both fixed before merge. Or is it not possible yet to test turn stuff?

@kschrab

kschrab commented Mar 6, 2014

Copy link
Copy Markdown
Contributor Author

There are tests which cover the edge-based behavior, in order to make sure that edge-based traversal leads to same routes as the node-based variant. Some of those tests regarding bi-directional algorithms are broken, but I assume there is something wrong with QueryGraph but I did not discover what exactelly the problem is.
There are currently NO tests which cover turn restrictions in the routing process, just because I have no time to write them.

@kschrab

kschrab commented Mar 17, 2014

Copy link
Copy Markdown
Contributor Author

#163 should be fixed before adding edge-based algorithms.

Karl Hübner added 2 commits March 17, 2014 12:19
DijkstraBidirectionRef and AStarBidirection. 

In order to share code, the present routing algorithms can now switch
between both node-based and edge-based behavior. Tests of those
algorithms are executed for each of the traversal modes using
parametrized tests.

Additionally, the adapted algorithms now consider turn
restrictions/costs if the graph stores them in its extended storage.
However, tests for turn restrictions/costs have not been written yet.
Conflicts:
	core/src/main/java/com/graphhopper/routing/AStarBidirection.java
	core/src/main/java/com/graphhopper/routing/Dijkstra.java
	core/src/main/java/com/graphhopper/routing/DijkstraBidirectionRef.java
	core/src/test/java/com/graphhopper/util/InstructionListTest.java
@karussell

Copy link
Copy Markdown
Member

I think we need "tests which cover turn restrictions in the routing process" before merging this ... when I wanted to see make this happen, what do I need to enable? Like turn weighting etc ...

some more questions:

  • When do we need TRAVERSAL_MODE.EDGE_BASED? I mean isn't EDGE_BASED_DIRECTION_SENSITIVE always good enough or will it be too slow to be sufficient for all usecase? (I'm asking just to know if there is possibility to reduce complexity)
  • Isn't this always 0? iter.getEdge() & HIGHEST_BIT_ONE
  • Will bidirectional algorithms work at its 'visiting point'? Even if there is a turn restriction. (I don't mean the possible QueryGraph bug here :))
  • Also it looks like TurnWeighting.java and AbstractTurnWeighting.java have different line endings. I hate it :(, I thought that I fixed this via .gitattributes. Would you mind to have a look into this? Maybe I picked the wrong config for this.

@brunesto

brunesto commented Apr 4, 2014

Copy link
Copy Markdown

Hi Peter and Karl,

I am using the turn restrictions and I added a test for it - I am trying since a couple of hours to make a pull request to khuebner/graphhopper without success. I will go back to it on Monday but if you wish to have a look at it in the meantime the diff is there:
https://github.com/brunesto/khuebner-graphhopper/compare/forked...turnrestrictions-test

The diff contains one test (RoutingAlgorithmIT.testMoscowTurnRestrictions) for the turn restrictions together with fixes in AStar and Fast/ShortWeighting.
I also changed a little bit RoutingAlgorithmIT and RoutingAlgorithmSpecialAreaTests so that the test can run with turn restrictions enabled.

All tests are running, but there are 2 'cheatings':

  • 'dijkstraOneToMany' is still commented out of the algorithms to be tested in RoutingAlgorithmSpecialAreaTests
  • For the turn restriction test, 3 algos are not tested: CH, astarbi and dijkstrabi.
    astarbi and dijkstrabi can pass the test but only after adding code to prevent sharp U Turns (i.e. from X to X) in AbstractTurnWeighting.
    I left it commented because uncommenting the code breaks the test DijkstraBidirectionRefTest.testCalcIfEmptyWay()

Regards
Bruno

@karussell

Copy link
Copy Markdown
Member

Hey,

I really appreciate your hacking on this and I hope to get time next week to review it.

dijkstraOneToMany

This is commented out because it does not support the QueryGraph (GPS exact routing)

For the turn restriction test, 3 algos are not tested: CH, astarbi and dijkstrabi.

For CH to work we need dijkstraOneToMany to work with turn restrictions. astarbi+dijkstrbi may fail due to the bug Karl mentioned #163 ... in some weeks I'll have more time to finally start hacking on these all issues.

@karussell

Copy link
Copy Markdown
Member

@brunesto

Copy link
Copy Markdown

Hi Peter, thanks for looking at it.
I tried to write a One2ManyDijkstra using only GH classes with turn restrictions, it seems to work but not with CH though. If you are interested, it is currently there : https://github.com/brunesto/graphhopper/blob/master/core/src/main/java/com/graphhopper/routing/DijkstraOneToMany.java

In our prod we are using a different One2Many that supports turn restrictions but it is based on complete rewrite of the Dijkstra and uses our own classes so it is probably of little use to you, however if you would like to see the code I will be glad to share it.

Bruno

@karussell

Copy link
Copy Markdown
Member

Merged in #238 where also the follow up will happen - thanks again!

@karussell karussell closed this Jul 18, 2014
@karussell karussell added this to the 0.4 milestone Jul 18, 2014
dabiih pushed a commit to dabiih/graphhopper that referenced this pull request Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants