Skip to content

Move path extraction logic out of Path class - #1730

Merged
easbar merged 19 commits into
masterfrom
path_cleanup
Sep 18, 2019
Merged

easbar merged 19 commits into
masterfrom
path_cleanup

Conversation

@easbar

@easbar easbar commented Sep 17, 2019

Copy link
Copy Markdown
Member

This PR is supposed to move the path extraction stuff out of Path. So far Path was used by the routing algorithms to store some intermediate state (SPTEntry, switchToFrom, etc.) that later was used to 'extract' the Path. So basically some parts of the routing algorithm used to live inside Path and (because the extraction depends on the type of algorithm) the subclasses (PathNative, Path4CH, PathBidirRef, EdgeBasedPath4CH). However, since Path is the return type of the RoutingAlgorithm interface it should really be a data-only class IMO.

Here I basically did the following:

  • Added dedicated classes for path extraction: PathExtractor, BidirPathExtractor, Node/EdgeBasedCHBidirPathExtractor, which basically take some SPTEntry (or two) and create a Path from it. In turn I removed the path extraction stuff from Path and deleted its subclasses.

  • Instead of holding a reference to an (intermediate) Path instance (bestPath) AbstractBidirAlgo now just has a reference to the best fwd/bwd SPTEntry and the bestWeight. We can override extractPath if we want something different than the default path extraction, or just change the path extraction implementation by overriding createPathExtractor.

@karussell karussell left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nice. Have so far only skimmed through the code, but this already looks good. I see no objections.

(In another issue it would be nice to remove the encoder dependency like the calcInstructions and calcDetails methods, so that we can work towards a fix of #1551)


public static Path extractPath(Graph graph, Weighting weighting, SPTEntry fwdEntry, SPTEntry bwdEntry, double weight) {
return new BidirPathExtractor(graph, weighting).extract(fwdEntry, bwdEntry, weight);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is the only required public method, can we make the constructor and other methods (package) protected or even private?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the idea was that one can override stuff like 'onEdge' if need be, but protected works

@karussell karussell added this to the 0.14 milestone Sep 17, 2019
@karussell

Copy link
Copy Markdown
Member

The build error for openjdk13 drives me crazy. There was a mistake regarding the version, but now this is fixed and locally it builds fine with it, even if I do rm -rf ~/.m2/repository/com/graphhopper/*. Also I removed the caches for travis, but this does not help. Do you have an idea or can you reproduce the problem that travis has with openjdk13?

The command should be:

export JAVA_HOME=/path/to/jdk-13/
mvn -version # verify that jdk-13 is used
mvn clean test very checkstyle:check forbiddenapis:check

Or maybe we try without the caching setting again in .travis.yml ...

@karussell

Copy link
Copy Markdown
Member

Or maybe we try without the caching setting again in .travis.yml ...

Didn't help.

The problem is that it downloads the core dependency:

Downloading from sonatype-snapshots: https://oss.sonatype.org/content/repositories/snapshots/com/graphhopper/graphhopper-core/0.14-SNAPSHOT/graphhopper-core-0.14-20190918.103923-1.jar

Although it builds this dependency before:

[INFO] Building jar: /home/travis/build/graphhopper/graphhopper/core/target/graphhopper-core-0.14-SNAPSHOT.jar

Comment thread .travis.yml Outdated

script:
- "mvn -Dkey=$API_KEY clean test verify -B"
- "mvn -Dkey=$API_KEY clean test verify install -B"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems to have fixed the build ? should we keep it like this ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the install forces maven to always fetch the dep from local repo. A bit strange as I thought that maven knows this already, but maybe also a bug of that forbiddenapis plugin. A bit strange that it passes for openjdk8...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, install should be enough (instead of verify install) since install already includes verify, Ill do this in master and then merge this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And thanks a lot for figuring this one out!

# Conflicts:
#	.travis.yml
# Conflicts:
#	core/files/changelog.txt
@easbar
easbar merged commit 9a5efe6 into master Sep 18, 2019
@easbar
easbar deleted the path_cleanup branch September 18, 2019 20:49
sguill pushed a commit to sguill/graphhopper that referenced this pull request Sep 23, 2019
* Remove PathBidirRef#switchFromTo
* Remove unnecessary statement in edge-based CH algo
* Remove unnecessary check in AlternativeRoute
* Use dedicated path extraction class for bidir algos
* Remove PathBidirRef and subclasses
* Make AStar more similar to Dijkstra
* Move path extraction for unidir algos into new PathExtractor
* Remove extract stuff from Path class
@michaz

michaz commented Oct 14, 2019

Copy link
Copy Markdown
Member

Omg, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants