Skip to content

Add Dial’s shortest-path algorithm for non-negative integer weights - #1265

Open
BenWilbert66 wants to merge 3 commits into
jgrapht:masterfrom
BenWilbert66:feature/dial-shortest-path
Open

BenWilbert66 wants to merge 3 commits into
jgrapht:masterfrom
BenWilbert66:feature/dial-shortest-path

Conversation

@BenWilbert66

@BenWilbert66 BenWilbert66 commented Sep 17, 2025 •

Copy link
Copy Markdown

This PR adds DialShortestPath<V,E> under org.jgrapht.alg.shortestpath and introduces a regression test for AllDirectedPaths (issue #1247

Highlights:

DialShortestPath

 - Implements ShortestPathAlgorithm<V,E> with getPaths, getPath, and getPathWeight.

 - Works on graphs with non-negative integer edge weights up to maxEdgeWeight.

 - Complexity: O(m + n·C) where C = max edge weight.

 - Includes validation for negative or non-integer weights.

 - Full JUnit 5 test suite (DialShortestPathTest) with parity checks against DijkstraShortestPath, plus edge cases (zero-                       weight edges, disconnected graphs, invalid weights).

Regression Test

 - Infinite loop case in issue #1247 is fixed

 - Adds AllDirectedPathsRegressionTest covering the infinite loop case reported in #1247.

 - Ensures the issue is reproducible and protects against regressions once fixed.

Motivation

- Dial’s algorithm is often faster than heap-based Dijkstra when edge weights are small integers.

- The regression test strengthens coverage for path enumeration and provides a reproducible case for a known bug.

Feedback welcome on naming, documentation, or placement!

@jsichi jsichi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix checkstyle error.

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.

2 participants