Skip to content

Move access flag checks into Weighting #1835

Closed

Description

@easbar

As part of #1776 we need to stop using the access encoded values check if a road is accessible for a given vehicle and instead purely rely on the edge weight calculated by the Weighting. Otherwise returning a finite weight in Weighting might have no effect in case the access flag of the corresponding road/direction is set to false.
This is not a trivial task especially with performance in mind.

Just to make sure: Do we really need to do this for #1776 already ? What if we had something like a flexible encoder that simply uses fwd/bwd=true for all roads, while some of the 'classic' vehicle profiles like car or bike continue to use the access flags (but cannot be used with flexible/configurable weighting). In this case using fwd/bwd=false and at the same time returning a finite weight would be considered a bug, and to offer the configurable weighting option the encoder must set all access flags to true.

Activity

  1. added this to the 1.0 milestone on Dec 29, 2019
  2. karussell commented on Dec 29, 2019

    @karussell
    Member

    This is not a trivial task especially with performance in mind.

    Why do you think this is complicated because of performance?

    What if we had something like a flexible encoder that simply uses fwd/bwd=true for all roads

    That would work, but would be ugly as we would check the access in the EdgeFilter and then again in the configurable Weighting.

    while some of the 'classic' vehicle profiles like car or bike continue to use the access flags

    Yes, we can use them as "base" and then, once a road is inaccessible for these "base vehicles", you cannot enable these roads via the Weighting. Actually I did this in the various branches when I implemented a preliminary version of it and the experience was okay.

    The remaining problem is still issue #729 where we need to replace the EdgeFilter with the Weighting, otherwise it can happen that the LocationIndex returns edges that are blocked due to the configurable Weighting.

    BTW: should we rename this issue to "make access flags optional"? As this is not about removing the access flags and more about moving the access flags check into the Weighting. I.e. we can still implement access restrictions via pre-calculated bits in the edge flags, but also calculate it dynamically via some EncodedValues.

  3. easbar commented on Dec 30, 2019

    @easbar
    MemberAuthor

    Why do you think this is complicated because of performance?

    Ok, as long as you have some access flags and can check them within weighting quickly the performance should in principle stay the same. But do you not have to set (at least most of) the access flags to true to be able to have a real 'configurable' weighting ? Edges with access=false cannot be unblocked by a configurable weighting in my current understanding (or you ignore them but then there is no quick exit and hence performance will decrease).

    What I think is 'not trivial' is figuring out what the problems are and finding a good solution for all things we would like to achieve (performance & flexibility mostly). For example it took me quite some time to find a solution to the access flags issue just for the CH preparation, #1837.

    That would work, but would be ugly as we would check the access in the EdgeFilter and then again in the configurable Weighting.

    You mean ugly because its slower or whats ugly about it ? But yes I agree it would be nicer to strictly move all access checks inside the weighting.

    Yes, we can use them as "base" and then, once a road is inaccessible for these "base vehicles", you cannot enable these roads via the Weighting.

    Ok this makes sense now.

    The remaining problem is still issue #729 where we need to replace the EdgeFilter with the Weighting,

    Its probably similar also for DirectionResolver. I think we can do this step by step. For CH preparation I did #1837 now, for CH algorithms I think I'll do it in a similar way.

    As this is not about removing the access flags and more about moving the access flags check into the Weighting

    Ok now its more clear to me. I renamed the issue to just that.

  4. changed the title [-]Remove access flags[/-] [+]Move access flag checks into Weighting[/+] on Dec 30, 2019
  5. karussell commented on Dec 30, 2019

    @karussell
    Member

    But do you not have to set (at least most of) the access flags to true to be able to have a real 'configurable' weighting ?

    Yes. Hopefully this won't be much or one always has the option to pick the base vehicle (like car or bike). Likely this "base vehicle" selection is required to reduce other problems as well like the subnetwork removal.

    For example it took me quite some time to find a solution to the access flags issue just for the CH preparation, #1837.

    Yeah, it is a big conceptual change and agree on the handling (do this issue here independent). I also have a fix for #729 without bigger changes: #1838

    You mean ugly because its slower or whats ugly about it ?

    Ugly in the sense that two things are responsible where only one should be.

  6. easbar commented on Dec 30, 2019

    @easbar
    MemberAuthor

    Ugly in the sense that two things are responsible where only one should be.

    Agreed. I thought it could be acceptable to state that using a flexweighting only works when the access flags are set to true or something, but sure moving the access checks into weighting entirely is cleaner.

  7. karussell commented on Dec 30, 2019

    @karussell
    Member

    BTW: I think this will also fix those "speed == 0 vs. access == true" issues, like #1234

  8. added a commit that references this issue on Jan 4, 2020
  9. easbar commented on Apr 29, 2020

    @easbar
    MemberAuthor

    For 1.0 this does not seem so important, because CustomWeighting always inherits the access flags from some base encoder and there is no way to change it. We can block additional edges (e.g. using priority), but opening up restricted edges is not possible anyway.

  10. modified the milestones: 1.0, 2.0 on May 1, 2020
  11. modified the milestones: 2.0, 3.0 on Sep 29, 2020
  12. karussell commented on Dec 1, 2020

    @karussell
    Member

    because CustomWeighting always inherits the access flags from some base encoder and there is no way to change it.

    I played a bit with this and I don't think this depends on changing the FlagEncoder classes. We only need to avoid the implicit edge filters. Let me try to explain this :)

    Let's assume we check against car.access in calcEdgeWeight as the very first step for all Weighting implementations. Then, when we remove all the implicit EdgeFiltering like in createEdgeExplorer we should be able to make this configurable for CustomWeighting without the need to change the FlagEncoder classes.

    We could introduce some new options like default_access: true to ignore car.access as a first step:

    default_access: true
    default_average_speed: car
    
    # now avoid the reverse direction e.g. for a police car or similar
    priority:
      car.access: { false: 0.5 }

    The reverse direction will get the speed of the forward direction but it is unknown what happens to the average_speed of newly accessible roads like pedestrian. To solve this problem we could provide a fallback mechanism:

    default_access: true
    default_average_speed: car, foot
    
    priority:
      car.access: { false: 0.5 }

    which could mean that if car has no estimated speed in the reverse direction then use the speed from foot and if no foot.access then skip the edge. I.e. the accessibility is "allowed car" minus "forbidden foot". This would replace profile: car and the FlagEncoder classes are just used as tag parsers that fill xy.access and xy.average_speed.

    For more flexibility we could define an average_speed_map like we do for max_speed and use that as custom fallback in default_average_speed to allow certain road segments like pedestrian roads or private roads that would be otherwise disallowed from car.

    default_access: true
    default_average_speed: car, custom
    average_speed_map:
      road_class: { pedestrian: 6 } # 6km/h
    
    priority:
      road_class: { pedestrian: 0.5 } # allow "wrong" pedestrian roads but assign low prio

    Now the reverse direction for all roads would be automatically allowed. We could introduce a separate flag for that, but with janino scripting we can express more complicated expressions:

    default_access: true
    default_average_speed: car, custom
    average_speed_map:
      road_class == PEDESTRIAN: 6
    
    priority:
      first_match:                    # Pick the first matching conditions:
        road_class == PEDESTRIAN: 0.5 # allow pedestrian before we ...
        car.access == false: 0        # ... disallow everything that car disallows.
        car.access == true: 1         # No need for this line as 1 is the default.
  13. easbar commented on Feb 26, 2021

    @easbar
    MemberAuthor

    Interesting to see how much the syntax has changed :)

    The reverse direction will get the speed of the forward direction but it is unknown what happens to the average_speed of newly accessible roads like pedestrian.

    This is true, when we open up roads without access we have no speed value we can use. Maybe we could use, e.g., foot$average_speed as right-hand value, like this (or similar)?

    speed:
      - if: some_condition
        set to: foot$average_speed
    

    Or maybe even use car$access in the condition, like this:

    speed:
      - if: car$access == false
        set to: foot$average_speed
    

    At first it seems useful to use the other average speed values if none are available for the base vehicle (because this is better than 'nothing'). But on the other hand I wonder in which case we actually want to do this? Do we ever want to fall back to foot speed when we go by car? Could we not just set the speed to something like 5km/h in this case (no matter what the real value for foot$average_speed is)?

  14. easbar commented on Feb 26, 2021

    @easbar
    MemberAuthor

    Btw I am currently working on this issue. Maybe we can replace FastestWeighting by something like this at some point:

    speed:
      - if: car$access == true
        set to: car$average_speed
      - else:
        set to: 0
    
  15. easbar commented on Feb 27, 2021

    @easbar
    MemberAuthor

    Also should we rename DefaultEdgeFilter -> AccessEdgeFilter (or just AccessFilter)? Filtering by access should no longer be the 'default'. There certainly are cases where we want to filter by access, but there also are cases where we rather filter by weight, see the FiniteWeightFilter I just added.

  16. modified the milestones: 3.0, 4.0 on Apr 6, 2021
  17. modified the milestones: 4.0, 5.0 on Sep 29, 2021
  18. removed this from the 5.0 milestone on Aug 30, 2022
  19. added this to the 8.0 milestone on Sep 7, 2023
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