Skip to content

Use of expressions in custom model "multiply_by" #2743

Closed

Description

@xallaume

Hello,

The documentation at https://github.com/graphhopper/graphhopper/blob/master/docs/core/custom-models.md, in the chapter "The value expression", states that "The value of limit_to or multiply_by is usually only a number and can be a more complex expression like Math.sqrt(2)." and presents the following working example : "limit_to": "max_speed * 0.9".

But if we change the expression to be "limit_to": "max_speed / 0.9", the "/" operator isn't recognized. If we change it to "Math.sqrt(2)", it isn't recognized either.

To Reproduce

Steps to reproduce the behavior. For examples:

  1. Go to https://graphhopper.com/maps/?point=42.31575%2C2.482717&point=42.322636%2C2.51102&profile=hike&layer=TF+Outdoors
  2. Enter the following custom model in hike profile:
    {
    "distance_influence": 15,
    "speed": [{
    "if": "true",
    "multiply_by": "max_speed / 0.9" // or "Math.sqrt(2)"
    }],
    "priority": [],
    "areas": {}
    }
  3. You get a parsing error
  4. The same happens in a local 6.2 deployment

Expected behavior
Use of expressions should be possible in "multiply_by" & "limit_to" statements as described in specs.

System Information

GraphHopper 6.2

Sincerely,

Activity

  1. karussell commented on Feb 6, 2023

    @karussell
    Member

    Yes, either Math.sqrt should be possible or we should give a better "complex" example :)

    But if we change the expression to be "limit_to": "max_speed / 0.9", the "/" operator isn't recognized.

    I will make it clear in the docs that there are currently the following limitations for the right-hand side expression:

    • a single encoded value only
    • three operations +, * and -

    In an early version we allowed more complex things - see #2568. (The reason for these limits is mainly to simplify getting the maximum value which is necessary to improve the speed of non-CH requests.)

  2. easbar commented on Feb 7, 2023

    @easbar
    Member

    which is necessary to improve the speed of non-CH requests

    To be more precise, it is necessary to use LM. For A* we don't need this limitation and whether LM is faster than A* depends on the custom model: LM gets slower the more the custom model deviates from the prepared profile.

  3. karussell commented on Feb 7, 2023

    @karussell
    Member

    I think we need the maximum values for A* too. See getMinWeight. (To get a better speed approximation often leading to a better response speed)

  4. easbar commented on Feb 7, 2023

    @easbar
    Member

    Yes, the maximum-speed estimation is used to improve A* performance (actually currently only for A*, not LM). For LM we have another limitation that is not needed for A*: We cannot increase speeds / reduce weights.
    But with #2756 the A* limitation (we need to be able to determine the maximum speed from the custom model) also applies for LM.

  5. added this to the 7.0 milestone on Feb 20, 2023
  6. added a commit that references this issue on Mar 21, 2023
    8c55080
  7. added a commit that references this issue on Jun 21, 2023
    b3825b7
  8. added a commit that references this issue on Oct 27, 2023
    7a0960e
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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions