Repository navigation
Some minor refactoring picked from turncost_ch branch. - #1336
Conversation
easbar
commented
Apr 11, 2018
- Fixes some typos and whitespace
- Adds visited nodes sum to via routing template debug info.
* Fixes some typos and whitespace * Adds visited nodes sum to via routing template debug info.
Signed-off-by: ammagamma <[email protected]>
# 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
Signed-off-by: ammagamma <[email protected]>
| // 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 ?? |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)
|
|
||
| // Preparation works only once so we can release temporary data. | ||
| // The preparation object itself has to be intact to create the algorithm. | ||
| close(); |
There was a problem hiding this comment.
Should we make close private now?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)
Signed-off-by: ammagamma <[email protected]>
Signed-off-by: ammagamma <[email protected]>
|
|
||
| @Override | ||
| public void doWork() { | ||
| public void doSpecificWork() { |
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
The reason is highly likely that now it is not required to call the super method (so more methods but cleaner design IMO)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I have no preferences and the noun-argument incl. prepare sounds good.