Skip to content

Some minor refactoring picked from turncost_ch branch. - #1336

Merged
karussell merged 9 commits into
graphhopper:masterfrom
easbar:minor_cleanup
Apr 18, 2018
Merged

karussell merged 9 commits into
graphhopper:masterfrom
easbar:minor_cleanup

Conversation

@easbar

@easbar easbar commented Apr 11, 2018

Copy link
Copy Markdown
Member
  • Fixes some typos and whitespace
  • Adds visited nodes sum to via routing template debug info.

@easbar easbar changed the title Adds visited nodes sum to via routing template and fixes some typos. Some minor refactoring picked from turncost_ch branch. Apr 11, 2018
easbar added 3 commits April 11, 2018 20:47
# Conflicts:
#	core/src/main/java/com/graphhopper/GraphHopper.java
#	core/src/main/java/com/graphhopper/routing/ch/PrepareContractionHierarchies.java
#	core/src/main/java/com/graphhopper/util/GHUtility.java
#	reader-gtfs/src/main/java/com/graphhopper/reader/gtfs/RealtimeFeed.java
// graph contraction parameters, because it affects the node contraction order.
meanDegree = prepareGraph.getAllEdges().length() / prepareGraph.getNodes();
initSize = sortedNodes.getSize();
// todo: why do we start counting levels with 1 ??

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.

I think I was using it to distinguish uninitialized nodes from nodes with level=0 but now that we initialize all nodes with maxLevel at start this is probably no longer necessary.

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 I would suggest starting the count at 0 then, this would have saved me some nerves the first time I did not realize it starts at 1 :)

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.

Oh, ok. 👍


// Preparation works only once so we can release temporary data.
// The preparation object itself has to be intact to create the algorithm.
close();

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.

Should we make close private now?

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.

I think that would be better yes. btw @Nakaner mentioned it would sometimes be useful to have some protected hooks, for example at cleanUp() in GraphHopper.java https://media.ccc.de/v/2018-5257-eisenbahnrouting_mit_graphhopper#t=739 (around 12min)

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, but we should not do this in general. We should start as closed as possible as we otherwise provide a broader API that is harder to evolve. Also inheritance should be less used and replaced with composition. All this means we should still provide hooks, but well thought out and only if there is a 'proper' use case. E.g. the GraphHopper class with all the "hooks" is simple but not that good IMO and needs refactoring at some point.

LOGGER.info("Start calculating " + lms.getLandmarkCount() + " landmarks, default active lms:"
+ defaultActiveLandmarks + ", weighting:" + lms.getLmSelectionWeighting() + ", " + Helper.getMemInfo());
LOGGER.info("Start calculating {} landmarks, default active lms: {}, weighting: {}, {}",
lms.getLandmarkCount(), defaultActiveLandmarks, lms.getLmSelectionWeighting(), Helper.getMemInfo());

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.

To be honest: I found the previous logging statement more clear :)

The "{}" notation is used to avoid string concatening if we disable logging for this class, but usually the advantage is only for massive logging like we could get in the REST server but even there we would not deactivate logging because it is valuable to have them for analyzation

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.

I was not trying to improve performance here, but think {} is more readable, but that's probably because I am used to it. I will revert it, don't have a strong opinion here.

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.

The string itself is more clear. But counting the brackets {} {} {} to know which property goes where makes it harder for me. Also not a strong just a minor opinion :)

@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.

Thanks!


@Override
public void doWork() {
public void doSpecificWork() {

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.

I don't understand this rename :). Could you explain the background and why doSpecificWork is better than doWork (BTW: I think both names are not especially good at explaining what happens in this method)?

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.

The reason is highly likely that now it is not required to call the super method (so more methods but cleaner design IMO)

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.

Yes the idea was to be able to just override doSpecificWork instead of overriding doWork and calling super.doWork in the overriding method. This way AbstractAlgoPreparation is only dealing with making sure a preparation is only run once and the subclasses are only concerned with preparing the algorithm, which I think is cleaner. Regarding the names I think doWork isn't so bad ? Tbh I was more concerned with PrepareContractionHierarchies because it is not really a noun, but now I got used to it :) I would have preferred something like ContractionHierarchiesPreparer and then maybe naming the doWork() method prepare() instead (and maybe doPrepare instead of doSpecificWork. Then again this class not only 'prepares' the graph, but also creates the Algorithm (its a RoutingAlgorithmFactory). Anyway, I think these are all rather minor issues and I do not insist on my change if you dont like it.

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.

Thanks for the explanation :). I was just wondering why the name was changed. Should we rename doSpecificWork to prepare then? I am a fan of speaking method names, even if that makes names rather long sometimes, but I think this change makes sense, so I don't want to block anything.

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.

I have no preferences and the noun-argument incl. prepare sounds good.

@karussell
karussell merged commit 51c8a58 into graphhopper:master Apr 18, 2018
@karussell karussell added this to the 0.11 milestone Apr 18, 2018
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