Skip to content

Add multi-level Dijkstra routing index - #414

Merged
trasch merged 5 commits into
mainfrom
413-multi-level-dijkstra
Nov 5, 2026
Merged

trasch merged 5 commits into
mainfrom
413-multi-level-dijkstra

Conversation

@trasch

@trasch trasch commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a reusable multi-level Dijkstra (MLD) routing index to the opt-in Graph API.

  • graph.multiLevelIndex(levels:baseRows:baseColumns:) builds nested rectangular cell partitions with sparse first-boundary overlays.
  • Graph.MultiLevelIndex.shortestPath(from:to:) answers queries with a level-aware bidirectional search: original edges in the endpoint cells, per-node query-level overlays elsewhere.
  • graph.shortestPathViaMultiLevel(from:to:...) is a one-shot convenience.
  • Directed graphs use reverse adjacency and backward overlays.
  • Queries with blockedNodes or edgeFilter fall back to plain Dijkstra.
  • The shared rectangular tiling math was extracted into an internal helper used by both partition(...) and the new index.

Closes #413.

Tests

  • swift test --traits EnableGraphAPI — 3089 tests in 211 suites pass.
  • New coverage: all four projections, directed graphs, weighted and parallel edges, same-cell out-and-back routes, antimeridian data, real-world Immenstadt fixtures, deep 3-level hierarchies, and the existing exhaustive Floyd-Warshall oracle.
  • python3 scripts/check_documentation.py — no diagnostics.
  • swift package diagnose-api-breaking-changes origin/main --products GISTools — no breaking changes.
  • swiftformat --lint — clean on the new files.

Benchmark note

Grid fixtures are the worst case for multi-level overlays because every cell-perimeter node is a boundary node. At 1M grid edges the index build takes ~16 s and the query ~0.148 s versus ~0.089 s for plain Dijkstra. Real road networks have much sparser cell boundaries; partition-size tuning is documented as a follow-up lever.

Adds Graph.MultiLevelIndex with nested rectangular partitions, sparse boundary overlays and a level-aware bidirectional query search. Supports directed graphs and falls back to plain Dijkstra for blocked nodes and edge filters.

Refs #413
@trasch trasch self-assigned this Nov 5, 2026
@trasch trasch added the enhancement New feature or request label Nov 5, 2026
Adds a DocC guide that explains how the graph, direct searches, contraction, routing indices, landmark routing and multi-level Dijkstra fit together. Covers mode-specific graphs, constraints, custom costs and tuning parameters, and links the guide from the Graph API, performance notes, README and changelog.
Exercises multi-level routing on the Munich and Paris fixtures and on a cycling-filtered Munich graph. Shares real-world fixture graphs through GraphTestHelper and adds multi-level build/query benchmarks for Allgäu, Munich, Munich directed and Paris to the real-world suite.
Moves the unreleased changes under 3.1.0, refreshes current GISTools dependency examples to 3.1.0 and updates the release audit example. Companion package versions and the historical migration guide are unchanged.
SwiftFormat 0.63.0 counted this file's legacy violations nondeterministically (26 or 27), so merely touching the file could trip the format gate. Fix all pre-existing violations in the helper so the count is stable at zero.
@trasch
trasch merged commit 8e52051 into main Nov 5, 2026
6 checks passed
@trasch
trasch deleted the 413-multi-level-dijkstra branch November 5, 2026 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add multi-level Dijkstra (MLD) routing index to the Graph API

1 participant