Skip to content

Allow finite u-turn costs for CH #1652

Closed

Description

@easbar

Currently we cannot use finite u-turn costs with CH, but with #1640 this should now be possible to do.

Activity

  1. easbar commented on Jul 16, 2019

    @easbar
    MemberAuthor

    Doing this raises several questions.

    1. Should we start with one global value for u-turns (the same for all road-types, junctions, dead end streets etc.) ?
    2. If yes, should it be possible to use different values for the u-turn costs for each profile (probably makes sense, e.g. bike is certainly not the same as car) ?
    3. So far the u-turn costs 'live' inside TurnWeighting, but in the configuration file we would probably configure it with the encoder(s) ? Something like car|turn_costs=true|u_turn_cost=40 ? Maybe we should move the u-turn-cost into the (turn cost)encoder ? If we ever add more options like different u-turn costs for different road types etc. this configuration might become lengthy...
    4. Do we need to allow different u-turn-costs for the same vehicle/weighting (now or in the long run) ? related: Make creating CH profile more configurable #493
    5. Once we have this configuration we definitely need to store the u-turn cost with each CH profile, because it will be fixed after the CH preparation. I think we should store it as an int in (units of seconds ?), so we do not run into floating point comparison problems when loading a profile. We could use -1 as special value indicating the u-turn costs shall be infinite (this is the default at the moment).
  2. karussell commented on Jul 18, 2019

    @karussell
    Member

    As a start a global U-turn cost per profile makes sense. (Later on it should be at least dependent on road_class and dead end. But let's focus in this issue just on making it "possible" not especially "configurable")

    If we ever add more options like different u-turn costs for different road types etc. this configuration might become lengthy...

    Yeah, before we do this it will be time to push forward the development of a yaml config per profile. Like I have done in a branch. See #193 (comment)

    Do we need to allow different u-turn-costs for the same vehicle/weighting (now or in the long run) ? related: #493

    Yes, I think this would be good. Like for different trucks. But probably also related to a different issue.

  3. easbar commented on Jul 19, 2019

    @easbar
    MemberAuthor

    Ok, sounds like a plan!

    But let's focus in this issue just on making it "possible" not especially "configurable")

    Ok, so the most 'possible and not configurable' way would be to hard-code it somewhere in the FlagEncoder then we do not even need to add it to the current config.

  4. karussell commented on Jul 21, 2019

    @karussell
    Member

    Ok, so the most 'possible and not configurable' way would be to hard-code it somewhere in the FlagEncoder then we do not even need to add it to the current config.

    Sure!

  5. easbar commented on Jul 25, 2019

    @easbar
    MemberAuthor

    Ok first the good news: I got edge-based CH running with finite u-turn costs and most of the required changes were already done in #1640. What is even better is that according to my measurements on the Germany map it seems that the finite u-turn costs lead to less shortcuts. The routing and preparation is even the faster the smaller the u-turn costs are (right now they are infinite, so introducing finite u-turn costs should make everything faster and most importantly not slower), related #1565!

    However, the more I am thinking about it the more I am asking myself where the u-turn costs should be stored. For now I put them into FlagEncoder, but this is clearly not what we want in my opinion:

    • Just hard-coding the u-turn costs into the different FlagEncoders does not work, because we need at least two options: infinite u-turn costs and finite (fixed value) u-turn costs. Or should we take the even simpler option here where we always use (fixed value) finite u-turn costs (I do not think this is such a good idea). Hard-coding also does not allow changing the value in unit-tests and of course we cannot really 'experiment' with the value without recompiling the code.

    • Overall FlagEncoder seems to be the wrong place for u-turn costs, because this class's purpose is to interpret the edge flags, but the u-turn costs are not stored within the edge-flags. Also in principle the u-turn costs can even change on a per-request basis for flexible routing algorithms, but we cannot change the u-turn costs in FlagEncoder because it is not recreated for every request (opposed to Weighting).

    So I think keeping the u-turn costs in TurnWeighting makes sense for now, but we need a way to associate the u-turn costs with the CH graphs, because they can not change after the CH preparation. So far we 'identify' the CH graphs only via the Weighting, but now we need to take also into account the u-turn costs. I do not want to go too far, but I think the best way to do this would be to use something like this:

    public class CHProfile {
        private final Weighting weighting;
        private final boolean edgeBased;
        private final double uTurnCosts;
    }

    to identify the CH graphs within GraphHopperStorage. In CHAlgoFactoryDecorator we will have

    private final List<CHProfile> chProfiles = new ArrayList<>();

    instead of:

    private final List<Weighting> nodeBasedWeightings = new ArrayList<>();
    private final List<Weighting> edgeBasedWeightings = new ArrayList<>();

    I would keep the config.yml unchanged here, except that it will be possible to specify u-turn costs 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

    Does this make sense ?

  6. karussell commented on Jul 26, 2019

    @karussell
    Member

    Cool 👍 !

    So I think keeping the u-turn costs in TurnWeighting makes sense for now, but we need a way to associate the u-turn costs with the CH graphs, because they can not change after the CH preparation

    Isn't the association already done as TurnWeighting is still a Weighting?

  7. easbar commented on Jul 26, 2019

    @easbar
    MemberAuthor

    Isn't the association already done as TurnWeighting is still a Weighting?

    No, the CHGraphs are only identified by the Weighting and once the CH preparation is chosen based on the request parameters the weighting is wrapped with a TurnWeighting. I think this is also the reason why we separate edge/node-based Weightings in CHAlgoFactoryDecorator.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions