Skip to content

Request fails when not setting the weighting and/or the vehicle with CH and finite u-turn costs #1788

Closed

Description

@easbar

If we specify something like prepare.ch.weightings=fastest|u_turn_costs=40 in the configuration and then do not specify a weighting in GHRequest, GH tries to determine the weighting by looking at the CHProfile(s). This leads to:

java.lang.IllegalArgumentException: Cannot find CH profile for weighting map {edge_based=true, weighting=fastest|u_turn_costs=40, vehicle=car} in entries: [fastest|car|edge_based=true|u_turn_costs=40.

Activity

  1. added this to the 1.0 milestone on Nov 12, 2019
  2. changed the title [-]Request fails when not setting the weighting with CH and finite u-turn costs[/-] [+]Request fails when not setting the weighting and/or the vehicle with CH and finite u-turn costs[/+] on Nov 12, 2019
  3. easbar commented on Nov 12, 2019

    @easbar
    MemberAuthor

    This is very ugly. We already have this complex logic to determine the CHProfile when edge_based=true/false or u_turn_costs is not given on the request. Handling the case(s) where also the vehicle and/or the weighting is missing makes this even worse.

    The problematic code is here:

    if (map.getWeighting().isEmpty())
    map.setWeighting(getDefaultProfile());

    This is bad: If the weighting has not been specified on the request (HintsMap) we just take the one of the first of the CH profiles. In case we use multiple weightings we basically pick one at random which makes no sense. When u_turn_costs=40 is included it leads to the error, because we kind of compare a 'CH profile definition' (prepare.ch.weightings=fastest|u_turn_costs=40) with a 'weighting name' (fastest). For the vehicle we do not even set anything, so it remains an empty string when its not given in the request. (Update: no the vehicle is set to "car" by default if missing sigh)

    I think the easiest solution (for us of course) would be to just throw an error if CH is requested but the vehicle and weighting is not given, so we force the client to pass this information with the request.

    The next best thing we can do is check whether or not the CHProfiles use multiple weightings/vehicles. If not we use the single one there is, if yes we throw an error.

    In the mid/long run I think every CHProfile should just have a name/id and to use it this name/id has to be passed along with the request, #1708.

  4. karussell commented on Nov 12, 2019

    @karussell
    Member

    (Update: no the vehicle is set to "car" by default if missing sigh)

    I think it uses the first flag encoder if missing. I.e. if no car is given it should still work.

    In case we use multiple weightings we basically pick one at random which makes no sense

    Oh, really random?

    I think the easiest solution (for us of course) would be to just throw an error if CH is requested but the vehicle and weighting is not given, so we force the client to pass this information with the request

    Hmmh, yeah. This would break backward compatibility as currently the minimal request needs just two points. Couldn't it pick the first CHProfile as default settings for vehicle+weighting and the order is defined as

    flag_encoders=vehicle1,vehicle2,...
    ch.weightings=weighting1,weighting2,...
    =>
    ch profile 1 = vehicle1 + weighting1
    ch profile 2 = vehicle2 + weighting1
    ...
    ch profile ? = vehicle1 + weighting2
    ...
    

    IMO it makes sense to not specify these parameters, because if you just have one vehicle and one weighting defined you would not expect to be forced to specify them in the request.

  5. easbar commented on Nov 12, 2019

    @easbar
    MemberAuthor

    I think it uses the first flag encoder if missing. I.e. if no car is given it should still work.

    Yes if vehicle is missing on the request its set to the first encoder here (somewhat random):

    String vehicle = request.getVehicle();
    if (vehicle.isEmpty()) {
    vehicle = getDefaultVehicle().toString();
    request.setVehicle(vehicle);
    }

    FlagEncoder getDefaultVehicle() {
    if (encodingManager == null)
    throw new IllegalStateException("No encoding manager specified or loaded");
    return encodingManager.fetchEdgeEncoders().get(0);
    }

    Oh, really random?

    Well not 'random' but it depends on the order the profile string are in this list (so in a sense its random, I mean its deterministic, but there is no 'real' reason to choose one over the other)

    private String getDefaultProfile() {
    return chProfileStrings.isEmpty() ? "fastest" : chProfileStrings.iterator().next();
    }

    Hmmh, yeah. This would break backward compatibility

    Yeah I am working on this. Its doable, and with some cleanup its maybe not that bad...

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions