Skip to content

Avoid streets entirely with (legal) maxspeed higher than threshold #2840

Closed as not planned

Description

@nilsnolde

We recently added top_speed to all (motorized) models where roads with higher estimated (not max) speeds are slightly penalized.

However, there are instances where it's mandatory that vehicles don't enter roads which have a legal speed limit above a certain threshold. Apparently that's applicable for electric bikes/other "lower" electric vehicle types in US/CA. In parameter terms this could be legal_speed or similar.

Would you be generally okay with a contribution like that?

I can see speed_limit is already collected from maxspeed OSM tag and put into EdgeInfo.

There a few questions:

  • I think maxspeed:forward/backward should be collected too (?!)
  • Would the check go into DynamicCost::Allowed(Reverse)? I can't see EdgeInfo being used there (or in any other part of the actual path finding), but I'm quite sure you'd not like to extend the DirectedEdge interface with that info!?
  • Obviously maxspeed (and more so their directional siblings) are still fairly rare, so country-/roadclass-specific defaults would be nice to get some better coverage of speed_limit (I know it's been on your TODO for a while..). Would you accept a contribution in a first step without that enhancement? I'd be happy to look into it at some point, but I couldn't take care of that right now tbh.

Any thoughts/opinions?

Activity

  1. danpat commented on Feb 5, 2021

    @danpat
    Member

    OSM has a specific tag for roads where a actual minimum travel speed is required:

    https://wiki.openstreetmap.org/wiki/Key:minspeed

    AFAIK, this tag isn't parsed or stored anywhere, as it's not that common.

  2. nilsnolde commented on Feb 5, 2021

    @nilsnolde
    MemberAuthor

    True, another attribute that'll never see > 1 permille coverage;) Via maxspeed and a legal_speed request param would be more flexible I think. Though I understand that that's quite a special thing to ask for..

  3. danpat commented on Feb 5, 2021

    @danpat
    Member

    I think maxspeed:forward/backward should be collected too (?!)

    On this one - a space compromise has been made here. There aren't that many singly digitized roads that have differing speed limits in opposite directions. By storing speed_limit on EdgeInfo, we only need one copy per road. The penalty to this space saving is that we can't support the 0.001% of roads that need different limits in opposite directions.

  4. kevinkreiser commented on Feb 5, 2021

    @kevinkreiser
    Member

    @gknisely can correct me if im wrong but, we do support different speeds in different directions. its stored in directededge::speed. i forget if enhancer messes with this speed though so its possible its there but then gets modified later in the pipeline but technically we do support different speeds in different directions along the same stretch of singly digitized road

  5. nilsnolde commented on Feb 5, 2021

    @nilsnolde
    MemberAuthor

    Yes, for actual speed that's right @kevinkreiser. For speed_limit (which I'd be interested in here) it's not. But @danpat is right, it's a fraction of roads compared to those having a maxspeed tag. Also very secondary requirement.

    More interesting is how one would optimally get the speed_limit from edge_info, so it's available during the expansion. Would it have to go into the directededge interface? Eventually we'd have the country-/roadclass-specific defaults for legal speed_limit from the admin db so it could make sense? However, not so sure how many other use cases there are for legal speed limits..

  6. dnesbitt61 commented on Feb 5, 2021

    @dnesbitt61
    Member

    yea, anything used in pathfinding (expansion) would need to be in DirectedEdge. Having to look up EdgeInfo (which is not tightly packed in adjacent memory like the directed edges that leave a node) would I think be unacceptable performance loss.

  7. nilsnolde commented on Feb 5, 2021

    @nilsnolde
    MemberAuthor

    Hmpf was forgetting about the Lua step there.. Thanks for the pointers @kevinkreiser ! Is it an option for you to store a speed_limit on the directed edge? Not on the computer right now, but I think there are 64 bit spare. Would it be worth 8 of those? 😇

  8. dnesbitt61 commented on Feb 5, 2021

    @dnesbitt61
    Member

    the 64 bits is in DirectedEdgeExt which is not integrated with any path algorithms (as far as I know).

  9. kevinkreiser commented on Feb 6, 2021

    @kevinkreiser
    Member

    hmm maybe im misunderstanding what you are asking @nilsnolde but i thought the pointers i linked above proved that if the speed_type is SpeedType::kTagged then the stored speed IS the speed limit. in fact the only time the speed isnt the speed limit is when there is no maxspeed tag at all. what am i missing here?

  10. nilsnolde commented on Feb 6, 2021

    @nilsnolde
    MemberAuthor

    Yeah I should’ve stopped to listen.. was too focused on getting an answer before the weekend to what I thought the question was 😕 thanks for slamming it in my face😊

  11. danpat commented on Feb 6, 2021

    @danpat
    Member

    So in most cases, does this make speed_limit on EdgeInfo is redundant? If a maxspeed tag doesn't exist, then it won't be set, if maxspeed does exist, then speed_type will let us know that DirectedEdge::speed_ contains the value.

    When is EdgeInfo::speed_limit useful?

  12. kevinkreiser commented on Feb 6, 2021

    @kevinkreiser
    Member

    As I was saying at the very beginning I'm pretty sure we "enhance" the speed to account for urban vs rural speed limit adherence. Basically we make urban ones slower and rural ones faster. The good news is, for the tagged (ie speed limit speeds) this update is very deterministic and doesnt even care about urban vs rural: https://github.com/valhalla/valhalla/blob/master/src/mjolnir/graphenhancer.cc#L116-L150

    So to get the actual speed limit back without going to the edgeinfo object we can simply reverse this transform. Honestly it seems like a bit of an oversight. I highly doubt that adding that if block costing would dramatically change the runtime of the path algorithms. We probably could have just let the speed limit out of edge info and added the surface penalty on the fly in costing.

    Seems like an artifact of hysterical raisins or plans that never fully came to be. I mean maybe we can even refactor a bit to make it so that we always get speed limit out of the directed edge and forget about edge_info while still keeping the tile format backwards compatible. I have to brainstorm that a bit. The other option is to leave the format as is and as i said about undo the transform to get the speed limit.

  13. dnesbitt61 commented on Feb 6, 2021

    @dnesbitt61
    Member

    Yea, as @kevinkreiser says this was added to support future enhancements and perhaps did not need to occur. The thought was that adding speed_limit to EdgeInfo would protect in future cases where the DirectedEdge speed might be modified from the OSM tagged speed limit. The idea was that the speed in DirectedEdge would provide the base speed used in costing for routes in absence of any traffic based speeds - even if this speed was not the actual speed limit. The thought was that speed limits would always be available even if not used in any costing methods.

  14. nilsnolde commented on Feb 28, 2021

    @nilsnolde
    MemberAuthor

    Having looked at it again, it seems to me there actually isn't a way currently to reliably retrieve the actual maxspeed from an edge: if maxspeed:advisory or maxspeed:practical is set, it's also a "tagged speed" and is favored over maxspeed:

    // set the speed
    if (has_average_speed_) {
    way_.set_speed(average_speed_);
    } else if (has_advisory_speed_) {
    way_.set_speed(advisory_speed_);
    } else if (has_max_speed_ && max_speed_ != kUnlimitedSpeedLimit) {
    // don't use unlimited speed limit for default edge speed
    way_.set_speed(max_speed_);
    } else if (has_default_speed_ && !way_.forward_tagged_speed() && !way_.backward_tagged_speed()) {
    way_.set_speed(default_speed_);
    }

    Of course, it's pretty unlikely: combined those two tags occur ~60k times currently. And the good thing is they should definitely underestimate the legal max speed, so in worst case it'd take an unnecessary detour, rather than routing through forbidden roads.

    But still, I'd prefer an accurate implementation. So I ended up extending the DirectedEdge interface with max_speed_ and using up 8 of the last 9 spare bits, then checking in Cost::Allowed(Reverse) if the set legal speed is higher than the edge's max_speed_. Less invasive ideas welcome. I can PR soon if you'd accept smth like that.

  15. nilsnolde commented on Feb 18, 2023

    @nilsnolde
    MemberAuthor

    super niche case, I take it back:)

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