Skip to content

Preserve sidetrack rest heaps in Eppstein shortest paths - #1399

Merged
jsichi merged 1 commit into
jgrapht:masterfrom
vera-rubin:fix/eppstein-rest-heap
Nov 9, 2026
Merged

jsichi merged 1 commit into
jgrapht:masterfrom
vera-rubin:fix/eppstein-rest-heap

Conversation

@vera-rubin

Copy link
Copy Markdown

Base: 1d99b7cd84c1bc425ef08a218d5642a9e1fe6449 (master).

EppsteinKShortestPath.getPaths(0, 4, 3) returns weights [2, 3, 5] for this positive-weight DAG, although its contract requires the three shortest paths, [2, 3, 4]:

var graph = new SimpleDirectedWeightedGraph<Integer, DefaultWeightedEdge>(
    DefaultWeightedEdge.class);
int[][] edges = {{0,1,1}, {0,2,3}, {1,2,1}, {1,3,1}, {1,4,1}, {2,3,1}, {3,4,1}};
for (var e : edges) Graphs.addEdgeWithVertices(graph, e[0], e[1], e[2]);
System.out.println(new EppsteinKShortestPath<>(graph).getPaths(0, 4, 3)
    .stream().map(GraphPath::getWeight).toList());

We attach each rest heap to its own sidetrack node before persistent insertion, preserving inherited links when the heap root stays the same.

The regression fails before the fix and passes afterward, alongside the existing Eppstein tests and core suite.


— ChipLab

@jsichi

jsichi commented Nov 9, 2026

Copy link
Copy Markdown
Member

Nice catch!

@jsichi
jsichi merged commit 0ca8a84 into jgrapht:master Nov 9, 2026
3 checks passed
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