osrm-backend icon indicating copy to clipboard operation
osrm-backend copied to clipboard

Negative route durations

Open mjjbell opened this issue 4 years ago • 1 comments

Through the use of negative turn penalties, it's possible to return steps, legs or even entire routes that have negative durations.

    Background: 
        Given the node map
            """
            a   b   c   d
            """

        And the nodes
            | node | id |
            | a    | 1  |
            | b    | 2  |
            | c    | 3  |
            | d    | 4  |

        And the ways
            | nodes | highway |
            | ab    | primary |
            | bc    | primary |
            | bc    | primary |
            | cd    | primary |
        And the profile "testbot"


    Scenario: negative route
        Given the turn penalty file
            """
            2,3,4,-70,0
            """
        And the contract extra arguments "--turn-penalty-file {penalties_file}"
        And the customize extra arguments "--turn-penalty-file {penalties_file}"

        When I route I should get
            | from | to | route       | time    |
            | a    | d  | ab,bc,cd,cd | -10     |

I think this should be tightened up. I can't think of a use-case where a negative duration in the result would be desired.

Current implementation

Some observations about the current implementation:

Proposed Fix

My suggestion is to implement the same negative penalty clamping for duration as is done for weight when performing traffic updates. This will prevent steps, legs and routes from having negative duration. It will also provide consistency with the duration clamping that already occurs on the first route edge.

Related

Negative turn penalty discussion - #3683

mjjbell avatar Feb 20 '21 22:02 mjjbell