Skip to content

Allows setting finite u-turn costs. - #1672

Merged
easbar merged 59 commits into
masterfrom
ch_profile_u_turn_costs
Sep 8, 2019
Merged

easbar merged 59 commits into
masterfrom
ch_profile_u_turn_costs

Conversation

@easbar

@easbar easbar commented Jul 29, 2019 •

Copy link
Copy Markdown
Member

This PR is based on #1671

With this PR it is possible to allow u-turns at some cost (when edge-based routing is enabled). On the request we have to specify, e.g., u_turn_costs=40 which means each u-turn that the route takes adds 40s to the overall travelling time. This only really makes sense as long as the weighting is based on time, like FastestWeighting. See also #1590.

Maybe this needs a bit of further thought and the u-turn costs should only be possible to apply if the weighting is time-based. Maybe we should deal with #1590 first ? Or just add some documentation and declare this parameter as experimental ?

However the largest part of this PR is about CH with finite u-turn costs. As for CH the u-turn costs must be specified in advance. This is done via the new CHProfile from #1671.

In config.yml the new configuration looks like this:

# use finite u-turn costs of 40s
prepare.ch.weightings: fastest|u_turn_costs=40
# if nothing is specified u-turns are forbidden as before
prepare.ch.weightings: fastest
# explicitly deny u-turns
prepare.ch.weightings: fastest|u_turn_costs=-1

Fixes #1652, also see discussion there.

# Conflicts:
#	core/files/changelog.txt
#	core/src/main/java/com/graphhopper/storage/CHGraphImpl.java
#	core/src/test/java/com/graphhopper/storage/GraphHopperStorageCHTest.java
@easbar easbar changed the title Allows setting finite u-turn costs. WIP: Allows setting finite u-turn costs. Aug 29, 2019
@easbar easbar changed the title WIP: Allows setting finite u-turn costs. Allows setting finite u-turn costs. Sep 8, 2019
throw new CHProfileSelectionException("Cannot find CH profile for weighting map " + weightingMap + " in entries: " + entriesStrs + ".");
}

if (edgeBased != null && uTurnCosts != null) {

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 is again quite a bit of nesting (even though its spread over different methods), but I thought this way it is easier to be sure we cover all the possible cases ? wdyt ?

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.

Looks fine due to the named cases IMO

@easbar

easbar commented Sep 8, 2019

Copy link
Copy Markdown
Member Author

I think I am happy with forbidding u-turns at virtual nodes. I added a comment to the docs stating that the u-turn penalty is time-based and therefore only works with time-based weightings, like fastest here: 3fafe81. Is this sufficient or should there be a more prominent warning (maybe at the place where the u_turn_costs parameter is documented ? Should we document it already ?

Should this go into 0.13 ? I think it's ready.

try {
return CHProfileSelector.select(chProfiles, map, edgeBased, uTurnCosts);
} catch (CHProfileSelectionException e) {
throw new IllegalArgumentException(e.getMessage());

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.

Is the checked exception CHProfileSelectionException required? Couldn't we let it extend DetailedIllegalArgumentException and avoid this method here and the 'throws CHProfileSelectionException' in a few methods? Or do you want it to be explicit? (I try to avoid checked exception as they are not often very helpful 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.

Ok, I changed it to a runtime exception. I do not necessarily think checked exceptions are never helpful because they give you a compile time check that helps you remembering to handle the error cases (for example here I think this is more of an advantage than it is a disadvantage that some 'intermediate' methods need to declare the exception). Anyway, either way is fine for me 👍.

@karussell

Copy link
Copy Markdown
Member

Is this sufficient or should there be a more prominent warning (maybe at the place where the u_turn_costs parameter is documented ? Should we document it already ?

Yes. May in ch.md and in the config-example.yml?

Should this go into 0.13 ? I think it's ready.

Sure 👍 - Thanks!

@easbar

easbar commented Sep 8, 2019

Copy link
Copy Markdown
Member Author

Yes. May in ch.md and in the config-example.yml?

Its in turn-restrictions.md and config-example.yml now

@easbar
easbar merged commit 9909da3 into master Sep 8, 2019
@easbar
easbar deleted the ch_profile_u_turn_costs branch September 9, 2019 05:39
@karussell karussell added this to the 0.13 milestone Sep 9, 2019
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.

Allow finite u-turn costs for CH

3 participants