Skip to content

Fix speed limits on edges copied for via-way turn restrictions - #3441

Open
ZainnQureshii wants to merge 1 commit into
graphhopper:masterfrom
ZainnQureshii:fix/via-way-copied-edge-speed
Open

ZainnQureshii wants to merge 1 commit into
graphhopper:masterfrom
ZainnQureshii:fix/via-way-copied-edge-speed

Conversation

@ZainnQureshii

Copy link
Copy Markdown

This contribution falls under the Apache License 2.0 as outlined in the contribution guide.

The patch adds ZainnQureshii to CONTRIBUTORS.md:101 for this first contribution.

Fixes #2914

With speed-limit estimation and turn costs enabled, a permitted turn can force a route onto a copied via-way edge (core/src/main/java/com/graphhopper/routing/util/parsers/RestrictionSetter.java:83 and :113). The old calculator read zero from the copy's unwritten temporary speed entry and cleared both directions when either limit was missing (core/src/main/java/com/graphhopper/routing/util/MaxSpeedCalculator.java:158 on master). That left the copied segment without the car model's max_speed * 0.9 cap (core/src/main/resources/com/graphhopper/custom_models/car.json:17).

The calculator now applies each estimate and its directional flags to the source edge and its copies, and preserves tagged directions when there is no estimate (core/src/main/java/com/graphhopper/routing/util/MaxSpeedCalculator.java:162 and :164 in this patch). In the routing probe, max_speed changed from null to 100 km/h with max_speed_estimated: true in one way orientation, and from null to the tagged 70 km/h with max_speed_estimated: false when the way was reversed.

GraphHopper.postImportOSM() is the production entry point for speed estimation (core/src/main/java/com/graphhopper/GraphHopper.java:928). RestrictionSetter creates the via-way copies through the sole production call to copyEdge(). The other callers of forEdgeAndCopiesOfEdge() handle elevation smoothing, geometry sorting, or turn weights and leave max_speed untouched. Existing graphs need a fresh OSM import because loading a saved graph skips import processing (core/src/main/java/com/graphhopper/GraphHopper.java:799).

The full Maven reactor passed on JDK 25.0.5.1 with mvn -B -ntp clean test verify. Core reported 3,346 tests, including 20 skipped, with zero failures or errors.

Both regression tests passed with Maven 3.9.6 and JDK 25.0.5.1.

mvn -o -B -ntp -pl core -am \
  '-Dtest=MaxSpeedCalculatorTest#testEstimatedMaxSpeedOnCopiedEdge+testDirectionalMaxSpeedOnCopiedEdge' \
  -Dsurefire.failIfNoSpecifiedTests=false test

The POM-pinned Checkstyle and Forbidden APIs checks passed on both changed Java files with a scratch-only configuration. Stock Checkstyle failed on the existing LineLength configuration, and stock Forbidden APIs flagged deprecated Locale constructors in web-api on both revisions. The linked Eclipse formatter ran on copies of both files and reformatted the base and patched versions. The added Java lines meet the checked EditorConfig rules.

Prepared with AI assistance (Codex and Claude Code) and reviewed with GitHub Copilot.

🤖 Generated with Claude Code

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Problem when using speed limit estimation and turn restrictions

1 participant