Skip to content

Properly do turn costs update - #1276

Closed
Nakaner wants to merge 4 commits into
graphhopper:masterfrom
geofabrik:merge_turn_costs
Closed

Nakaner wants to merge 4 commits into
graphhopper:masterfrom
geofabrik:merge_turn_costs

Conversation

@Nakaner

@Nakaner Nakaner commented Jan 23, 2018 •

Copy link
Copy Markdown
Contributor

Add a new method to TurnCostExtension which enables users to define their preferred merge strategy (overwrite vs. bitwise OR vs. …). These changes require JDK 8.

#1107

Add a new method to TurnCostExtension which enables users to define
their preferred merge strategy (overwrite vs. bitwise OR vs. …).
These changes require JDK 8.
*/
package com.graphhopper.storage;

import java.util.function.BiFunction;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note: on Android the java.util.function package is available from API level 24 or higher.

@karussell

Copy link
Copy Markdown
Member

Thanks for the patch! Currently it is not planned to switch to JDK8 for core (otherwise harder for Android and iOS) - can you avoid this? Furthermore we need a signed CLA from new contributors, just send us an email.

}
BiFunction<Long, Long, Long> overwriteFunc = (oldFlags, newFlags) -> {
return newFlags;
};

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.

It would be better to avoid creating this function on every method call.

@karussell

Copy link
Copy Markdown
Member

Also did you compare speed for import with and without this patch (e.g. for Germany)? I expect no changes, but if there are many turn costs associated (e.g. if we add costs for every junction) we might run into troubles and then a different approach is needed like a sorted storage where we could stop the loop earlier.

@karussell karussell changed the title Fix #1107 without changing the existing API Properly do turn costs update Jan 23, 2018
* See EdgeBasedRoutingAlgorithmTest for examples.
*/
public void setAndMergeTurnInfo(int fromEdge, int viaNode, int toEdge, long turnFlags,
BiFunction<Long, Long, Long> mergeFunction) {

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.

Maybe instead of passing a function here we could convert this to an Enum that specifies the used mode like MergeMode.OVERWRITE and MergeMode.OR, that way we can add new modes in the future and still continue using JDK 7?

Users can circumvent the check if turn flags of a specific turn have
already been saved.
@Nakaner

Nakaner commented Jan 24, 2018

Copy link
Copy Markdown
Contributor Author

I pushed two commits today which should address your comments.

Results from a performance test importing Germany with following settings:

graph.flag_encoders=car
graph.flag_encoders=car|turn_costs=true
prepare.ch.weightings=no
graph.dataaccess=RAM_STORE

The master needs 7 minutes and 6 seconds, my branch needs the same time (or a few seconds more but it seems to be within the range of variation of the measurements).

@karussell

karussell commented Jan 25, 2018 •

Copy link
Copy Markdown
Member

Thanks a lot for addressing the comments - looks better now and almost mergable.

One question, identical to the comment from @boldtrn: why can't we just use a boolean instead of the function as parameter? I.e. do the merge if merge==true and otherwise do an overwrite.

@Nakaner

Nakaner commented Jan 29, 2018

Copy link
Copy Markdown
Contributor Author

@karussell wrote:

One question, identical to the comment from @boldtrn: why can't we just use a boolean instead of the function as parameter? I.e. do the merge if merge==true and otherwise do an overwrite.

I wanted to keep it flexible. A bitwise OR is the right solution if you write the flags of one encoder after another. But it is not the right operation on the old and new flags if you just want to overwrite the flags of one encoder or do other – maybe strange – things.

@karussell

Copy link
Copy Markdown
Member

We should introduce an additional layer of abstraction only if it is really necessary. Here I do not see why a boolean is not sufficient - can you explain?

@karussell

karussell commented Feb 6, 2018 •

Copy link
Copy Markdown
Member

Would you mind to do this tiny change so that we can include it in 0.10 release? (hope to get some initial version out in the next days)

@karussell

karussell commented Feb 12, 2018 •

Copy link
Copy Markdown
Member

Thanks for the change!

Why should keep the option checkExistingEntries==false as you said the import was similarly fast?

If this parameter is false (per default) it would not fix #1107 and if it is always true we can remove it from the method.

@Nakaner

Nakaner commented Feb 12, 2018

Copy link
Copy Markdown
Contributor Author

@karussell wrote:

Why should keep the option checkExistingEntries==false as you said the import was similarly fast?

It was a rough test and variation was within the measurement accuracy after two or three iterations.

If this parameter is false (per default) it would not fix #1107 and if it is always true we can remove it from the method.

#1107 is caused by a lack of documentation. If a user of the library does not have a look on the actual implementation, he might think that addTurnInfo will look for existing entries. I tried to keep this behaviour to be fully backwards-compatible but added an alternative to ease the usage of the library. I myself can use Graphhopper 0.9 because I found a simple way to mitigate this problem (switch to for loops – the loop over the nodes is now the outer one and the inner one iterates over the encoders).

Do with the pull request what you want. Git gives you the ability to pick out of this branch what you are interested in. I offered you a patch with unit tests and documentation and I am tired to continue this discussion.

@karussell

karussell commented Feb 12, 2018 •

Copy link
Copy Markdown
Member

he might think that addTurnInfo will look for existing entries

We should look for existing entries. This is no documentation issue IMO, there should be no feature "add without looking for existing entries" - at least I do not see why.

I tried to keep this behaviour to be fully backwards-compatible

why?

I offered you a patch with unit tests and documentation and I am tired to continue this discussion.

Oh, wow. I really appreciate your work and time but this is a bit disturbing to me. Open source lives from these discussions and a maintainer has to be carefully when he merges or adds new stuff. Also you'll learn what is important and can easier contribute the next time :)

@karussell karussell added this to the 0.10 milestone Feb 13, 2018
karussell pushed a commit that referenced this pull request Feb 16, 2018
Add a new method to TurnCostExtension which enables users to define
their preferred merge strategy (overwrite vs. bitwise OR vs. …).
These changes require JDK 8.

replace java.util.function by a JDK7 compatible solution

optimisation for simple writing of turn flags

Users can circumvent the check if turn flags of a specific turn have
already been saved.

drop FlagMergeStrategy interface and replace it by simple ifs

see
#1276 (comment)

less parameters, slightly more tests but avoid bit-based tests, include clearing turn infos
@karussell

Copy link
Copy Markdown
Member

I will merge this: bc91215

Please @Nakaner let me know if you are ok with this. I also added the possibility to clear a certain turn information with the new method.

@Nakaner

Nakaner commented Feb 16, 2018

Copy link
Copy Markdown
Contributor Author

I am ok with that.

karussell pushed a commit that referenced this pull request Feb 16, 2018
Add a new method to TurnCostExtension which enables users to define
their preferred merge strategy (overwrite vs. bitwise OR vs. …).
These changes require JDK 8.

replace java.util.function by a JDK7 compatible solution

optimisation for simple writing of turn flags

Users can circumvent the check if turn flags of a specific turn have
already been saved.

drop FlagMergeStrategy interface and replace it by simple ifs

see
#1276 (comment)

less parameters, slightly more tests but avoid bit-based tests, include clearing turn infos
@karussell

Copy link
Copy Markdown
Member

Thanks again for your contribution - merged now!

@karussell karussell closed this Feb 16, 2018
@Nakaner
Nakaner deleted the merge_turn_costs branch May 17, 2018 11:02
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.

4 participants