Skip to content

Handle turn restrictions with multiple via ways and overlapping restrictions - #3030

Merged
easbar merged 14 commits into
masterfrom
multi_via_restrictions
Jul 9, 2024
Merged

easbar merged 14 commits into
masterfrom
multi_via_restrictions

Conversation

@easbar

@easbar easbar commented Jun 25, 2024 •

Copy link
Copy Markdown
Member

This PR extends the turn restriction support to restrictions with multiple and/or overlapping via-edges. These include OSM turn relations with multiple via-ways, turn relations with a single via-way that are crossed by other ways (such that they must be split into multiple edges for routing) and turn relations that could not be handled so far because they share a common via-way.

Fixes #446 #3155
Closes #2695

Here are some examples:

  • overlapping via-way restrictions, with via-ways pointing in the same restriction (ignored so far): rel1, rel2, route

  • overlapping no-straight-on and no-u-turn, via-ways pointing in the same direction (ignored so far): rel1, rel2, route

  • two via-ways (because via-way is split into two for some reason): rel route

  • straight-ahead-only with two via-ways: rel route

  • straight-ahead-only with three via-ways: rel route

@easbar

easbar commented Jun 25, 2024 •

Copy link
Copy Markdown
Member Author

The concept is pretty simple, but covering all special cases is very tricky. If anyone is willing to do some testing this would be of huge help. By testing I mean checking out this branch, running an import and checking routes that are affected by different kinds of turn restrictions. Even collecting some of the more complicated working examples would be helpful.

So far I used these profiles for testing car and hgv restrictions:

  profiles:
    - name: car
      weighting: custom
      turn_costs:
        vehicle_types: ["motor_vehicle", "motorcar"]
        u_turn_costs: 160
      custom_model:
        priority:
          - if: "!car_access"
            multiply_by: "0"
        speed:
          - if: "true"
            limit_to: "car_average_speed"
    - name: car_hgv
      weighting: custom
      turn_costs:
        vehicle_types: ["goods", "hgv", "motor_vehicle"]
        u_turn_costs: 160
      custom_model:
        priority:
          - if: "!car_access"
            multiply_by: "0"
        speed:
          - if: "true"
            limit_to: "car_average_speed"

These overpass queries are useful to find turn relations:

// show all turn restrictions with more than one via-way in France
area["name:en"="France"];
relation(area)["type"="restriction"];
foreach -> .a (
  way(r.a:via);
  way._(if:count(ways) > 1);
  rel.a(bw);
  out geom;
);
// show all turn restrictions in the current bounding box
relation({{bbox}})["type"="restriction"];
out geom;

@matkoniecz

Copy link
Copy Markdown
Contributor

By testing I mean checking out this branch, running an import

is there somewhere step-to-step guide? (AFAIK I have never compiled graphhopper)

Looked at https://github.com/graphhopper/graphhopper/blob/master/CONTRIBUTING.md and it seems to have no such steps nor link to them

https://github.com/graphhopper/graphhopper?tab=readme-ov-file#installation has for installation of released code

(sorry if I missed it, I done quick check so far)

@easbar

easbar commented Jun 25, 2024 •

Copy link
Copy Markdown
Member Author

is there somewhere step-to-step guide? (AFAIK I have never compiled graphhopper)

With git, java and Maven installed it is just a matter of checking out the multi_via_restrictions branch and running

mvn package -DskipTests

from the root directory. The binary will be created as web/target/graphhopper-web-10.0-SNAPSHOT.jar. Run it with the following config file like:

java -Xmx4g -jar web/target/graphhopper-web-10.0-SNAPSHOT.jar server config.yml
# config.yml
graphhopper:
  # download a map from Geofabrik or similar and set the path here
  datareader.file: /path/to/your/map.osm.pbf
  graph.location: your-map-gh
  graph.encoded_values: car_access,car_average_speed

  profiles:
    - name: car
      weighting: custom
      turn_costs:
        vehicle_types: ["motor_vehicle", "motorcar"]
        u_turn_costs: 160
      custom_model:
        priority:
          - if: "!car_access"
            multiply_by: "0"
        speed:
          - if: "true"
            limit_to: "car_average_speed"
    - name: car_hgv
      weighting: custom
      turn_costs:
        vehicle_types: ["goods", "hgv", "motor_vehicle"]
        u_turn_costs: 160
      custom_model:
        priority:
          - if: "!car_access"
            multiply_by: "0"
        speed:
          - if: "true"
            limit_to: "car_average_speed"

  import.osm.ignored_highways: ''
  prepare.min_network_size: 200
server:
  register_default_exception_mappers: false
  application_connectors:
    - type: http
      port: 8989
      # for security reasons bind to localhost
      bind_host: localhost
  admin_connectors:
    - type: http
      port: 8988
      bind_host: localhost

logging:
  appenders:
    - type: file
      time_zone: UTC
      current_log_filename: logs/graphhopper.log
      log_format: "%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"
      archive: true
      archived_log_filename_pattern: ./logs/graphhopper%d.log.gz
      archived_file_count: 30
      never_block: true
    - type: console
      time_zone: UTC
      log_format: "%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"
  loggers:
    "com.graphhopper.osm_warnings":
      level: INFO
      additive: false
      appenders:
        - type: file
          currentLogFilename: logs/osm_warnings.log
          archive: false
          logFormat: '[%level] %msg%n'

There are more detailed instructions here: https://github.com/graphhopper/graphhopper/blob/master/docs/core/quickstart-from-source.md but just let me know if the above instructions do not work. I can also upload the jar if needed.

@lukasalexanderweber

lukasalexanderweber commented Jun 28, 2024 •

Copy link
Copy Markdown
Contributor

Thanks for keep working on this!

I had a quick look over the changes as notices that RestrictionSetter#addArtificialEdges was removed. It seems you have a new strategy to cover via way turn restrictions.

The concept is pretty simple

could you outline the concept in a few words or a sketch? In #2695 we thought about multiple artificial edges to support overlapping via way restrictions and multi via way restrictions. Is the approach now something completely different or close to multiple artificial edges?

Here is the failing test I included to demonstrate the problem with multi via way restriction. Have you used this to test your new implementation?

I've added another test to show when this approach does not work:

      a   b   c   d
    0---1---2---3---4
        |e  |f
        5   6

with the restrictions e via b to f and a via b via c to d.

when turning right from e, we'll be detoured on b'. However, we cannot reach d due to b' via 2 to c and c' via 3 to d of the second restriction. We should actually be able to reach d from e.

On the other hand, we can not reach f from a since b' via 2 to f is restricted by the first restriction.

SUMMARY

The presented approach will fail if a via way of a multi-via-way-restriction is already in use by another via-way-restriction. I tested that this is the case in 115 of 150 multi-via-way-restrictions in germany.

@easbar

easbar commented Jun 28, 2024

Copy link
Copy Markdown
Member Author

could you outline the concept in a few words or a sketch? In #2695 we thought about multiple artificial edges to support overlapping via way restrictions and multi via way restrictions. Is the approach now something completely different or close to multiple artificial edges?

No, it is still a very similar idea. The restrictions are implemented by adding artificial edges, but to handle multi-via and overlapping restrictions we do need to add multiple artificial copies of an edge, indeed. More precisely, there is now one artificial edge for every different incoming edge that is part of a restriction. This means there can be several paths leading to an edge that encode the different possible origins of the path. This way the routing algorithm 'knows' multiple previous steps only by looking at the previous edge and can apply the turn restrictions accordingly. The details become rather tricky, though (best seen in code).

Here is the failing test I included to demonstrate the problem with multi via way restriction. Have you used this to test your new implementation?

I added a few tests, but not this one exactly. But if you don't mind I will pick some of your tests and explanations to this branch.

@easbar
easbar marked this pull request as ready for review June 28, 2024 15:41
@easbar easbar added this to the 10.0 milestone Jun 28, 2024
@lukasalexanderweber

Copy link
Copy Markdown
Contributor

More precisely, there is now one artificial edge for every different incoming edge that is part of a restriction. This means there can be several paths leading to an edge that encode the different possible origins of the path.

      a   b   c   d
    0---1---2---3---4
        |e  |f
        5   6

so previously there was only one artificial b' which was used by e via b to f and a via b via c to d. What exactly is now the situation?

I added a few tests, but not this one exactly. But if you don't mind I will pick some of your tests and explanations to this branch.

Of cause feel free to take anything you need from the previous PR :)

@easbar

easbar commented Jul 1, 2024

Copy link
Copy Markdown
Member Author

so previously there was only one artificial b' which was used by e via b to f and a via b via c to d. What exactly is now the situation?

There are two. One that the route is forced to use when coming from a, and one the route is forced to use when coming from e. The original edge would only be used for other incoming edges for which there are no restrictions.

@lukasalexanderweber

Copy link
Copy Markdown
Contributor

okay great and if there would be another restriction

      a   b   c   d
    0---1---2---3---4
        |e  |f
        5   6
        |g  
        7   

g via e via b to c then for this restriction there would be an artificial e' and then there would be three artificial b's (coming from a, from e and e')?

@easbar

easbar commented Jul 1, 2024 •

Copy link
Copy Markdown
Member Author

g via e via b to c then for this restriction there would be an artificial e' and then there would be three artificial b's (coming from a, from e and e')?

Generally, yes, if we needed to distinguish whether the route is coming from e, e', or a there would be three artificial edges (one for each). However, since the restriction g-e-b-f is redundant (because e-b-f is already forbidden) the g-e-b-f restriction will be ignored entirely.

# Conflicts:
#	core/src/main/java/com/graphhopper/reader/osm/OSMReader.java
@easbar
easbar merged commit 45c0b62 into master Jul 9, 2024
@easbar
easbar deleted the multi_via_restrictions branch July 9, 2024 07:35

This branch was previously deployed

1 inactive deployment
benchmarks — 1618ac86 Deployed Jul 8, 2024 by easbar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants