|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Johnson's algorithm for all-pairs shortest paths. More...
#include <ah-graph-concepts.H>#include <Dijkstra.H>#include <Bellman_Ford.H>#include <tpl_graph.H>#include <tpl_dynList.H>#include <tpl_dynMapTree.H>#include <ah-errors.H>#include <algorithm>#include <concepts>#include <cstdint>#include <limits>#include <stdexcept>#include <type_traits>#include <utility>#include <vector>Go to the source code of this file.
Classes | |
| struct | Aleph::johnson_detail::Wide |
| An integer of 128 bits, in two words of 64. More... | |
| class | Aleph::Johnson< GT, Distance, Ait, NAit, SA > |
| Johnson's algorithm for all-pairs shortest paths. More... | |
| struct | Aleph::Johnson< GT, Distance, Ait, NAit, SA >::Shown_Arc |
| struct | Aleph::Johnson< GT, Distance, Ait, NAit, SA >::Kept_Source |
Namespaces | |
| namespace | Aleph |
| Main namespace for Aleph-w library functions. | |
| namespace | Aleph::johnson_detail |
Johnson's algorithm for all-pairs shortest paths.
Implements Johnson's algorithm combining Bellman-Ford and Dijkstra for finding all-pairs shortest paths in sparse graphs, including graphs with negative edge weights. O(VE log V) complexity.
Johnson's algorithm works in the following steps:
With an integer distance type, w' and the sums of Dijkstra are kept in the unsigned type of the same width: as lowest() <= h <= 0, w' is at most max() + max() + 1, and d'(s,t) fits whenever d(s,t) fits. If a potential is below lowest(), the potentials, w' and the sums are kept in an integer of 128 bits instead, where they fit too. So every distance that fits in the type is given, and only one that does not makes a query throw.
| Phase | Time |
|---|---|
| Bellman-Ford | O(VE) |
| V × Dijkstra | O(V E log V) |
| Total | O(V E log V) |
For sparse graphs (E = O(V)), this is O(V² log V), better than Floyd-Warshall's O(V³).
Definition in file Johnson.H.