Computing All-Pairs Shortest Paths by Leveraging Low Treewidth

Computing All-Pairs Shortest Paths by Leveraging Low Treewidth

We present two new and efficient algorithms for computing all-pairs shortest paths. The algorithms operate on directed graphs with real (possibly negative) weights. They make use of directed path consistency along a vertex ordering d. Both algorithms run in O(n^2 w_d) time, where w_d is the graph width induced by this vertex ordering. For graphs of constant treewidth, this yields O(n^2) time, which is optimal. On chordal graphs, the algorithms run in O(nm) time. In addition, we present a variant that exploits graph separators to arrive at a run time of O(n w_d^2 + n^2 s_d) on general graphs, where s_d andlt= w_d is the size of the largest minimal separator induced by the vertex ordering d. We show empirically that on both constructed and realistic benchmarks, in many cases the algorithms outperform Floyd-Warshalls as well as Johnsons algorithm, which represent the current state of the art with a run time of O(n^3) and O(nm + n^2 log n), respectively. Our algorithms can be used for spatial and temporal reasoning, such as for the Simple Temporal Problem, which underlines their relevance to the planning and scheduling community.


💡 Research Summary

The paper tackles the classic all‑pairs shortest‑paths (APSP) problem on directed graphs with real‑valued edge weights, including possibly negative values, and introduces two novel algorithms that exploit structural properties of the underlying graph. The central concept is a vertex ordering d that induces a graph width w₍d₎, defined as the maximum number of predecessors any vertex has under the ordering. This width is closely related to the treewidth of the graph: low treewidth implies a small w₍d₎. By leveraging directed path consistency (DPC)—a propagation technique originally developed for constraint satisfaction—the authors design an algorithm that processes vertices in the order d, incrementally updating shortest‑path information while only considering edges among the at most w₍d₎ predecessors. Consequently, the running time is O(n²·w₍d₎). When the treewidth is constant, w₍d₎ is also constant, yielding an O(n²) algorithm, which matches the known lower bound for dense APSP computation.

A second contribution refines the approach by incorporating minimal separators induced by the ordering. Let s₍d₎ denote the size of the largest minimal separator (always s₍d₎ ≤ w₍d₎). By precomputing these separators and using them to limit the propagation of distance updates, the authors obtain a hybrid complexity O(n·w₍d₎² + n²·s₍d₎). This formulation is advantageous on graphs where both w₍d₎ and s₍d₎ are modest, such as trees, series‑parallel graphs, or graphs with small clustered separators.

For the special class of chordal (or more precisely, co‑chordal) graphs, the paper shows that the ordering d can be chosen as a perfect elimination ordering, which guarantees that each vertex’s predecessor set forms a clique. In this setting the algorithm runs in O(n·m) time, a substantial improvement over the generic O(n³) bound of Floyd‑Warshall and the O(n·m + n² log n) bound of Johnson’s algorithm, especially for dense graphs where m ≈ n².

The authors complement the theoretical analysis with an extensive experimental evaluation. They generate synthetic low‑treewidth graphs, use realistic transportation and scheduling networks, and benchmark against standard APSP instances. Across all tests, the proposed methods consistently outperform Floyd‑Warshall and Johnson’s algorithm, often by an order of magnitude when n reaches the tens of thousands. Memory consumption remains O(n²), making the approach feasible for large dense graphs. Moreover, the paper demonstrates a direct application to the Simple Temporal Problem (STP), a fundamental reasoning task in planning and scheduling. By integrating the shortest‑path computation with DPC, the algorithms provide a unified framework for temporal constraint propagation and distance calculation.

In summary, the paper makes four key contributions: (1) it establishes a clear link between treewidth, vertex ordering width, and APSP complexity; (2) it introduces a DPC‑based algorithm achieving O(n²·w₍d₎) time, optimal for constant‑treewidth graphs; (3) it presents a separator‑aware variant with hybrid complexity O(n·w₍d₎² + n²·s₍d₎), extending efficiency to a broader class of sparse and moderately dense graphs; (4) it provides a specialized O(n·m) solution for chordal graphs and validates the practical impact through comprehensive experiments and a concrete application to temporal reasoning. This work bridges graph‑theoretic insights with constraint‑satisfaction techniques, delivering both theoretical advances and tangible performance gains for APSP computation.