Skip to content

Weight can be NaN if distance is zero #2302

Closed

Description

@easbar

For example CustomWeighting calculates weight = seconds/priority + distanceCost. If seconds and priority are both zero this yields NaN. This can for example happen if distance is zero. For GH v1.0 this yields an error during CH preparation, see this forum discussion: https://discuss.graphhopper.com/t/custom-weighting-stable-version/6488/3, but the error was fixed in #2132 (GH versions 2.0+ do not throw an error). However, the weight can still be NaN. We probably should return zero weight in case distance is zero, or maybe distance=0/priority=0 should rather be infinity?

Activity

  1. karussell commented on Sep 14, 2022

    @karussell
    Member

    I think we faced this issue recently: ce461d2 - did this fix what you mentioned here?

  2. easbar commented on Sep 22, 2022

    @easbar
    MemberAuthor

    I'm not sure if I actually saw an error with the NaN value, but I probably just noticed this when reading the code. Anyway, the commit you linked to must have fixed it, because the distance==priority==0 case is now handled explicitly.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions