AcyclicShortestPaths
com.phasmidsoftware.gryphon.traverse.AcyclicShortestPaths
object AcyclicShortestPaths
Computes shortest paths in a weighted DAG using topological relaxation.
The algorithm:
- Topologically sort the DAG.
- Relax all outgoing edges of each vertex in topological order.
Since edges are relaxed in topological order, every predecessor of a vertex has already been processed when we reach it — guaranteeing optimal substructure without a priority queue. This gives O(V+E) time and correctly handles negative edge weights (unlike Dijkstra).
The edge-weight type E requires only a Monoid (for the zero distance and addition) and an Ordering (for comparison) — a lighter constraint than Numeric, consistent with RelaxableVertex and WeightedUnionFind.
NOTE: the graph must be a DAG. If it contains a cycle, TopologicalSort.sort returns None and this method throws IllegalArgumentException.
Attributes
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
AcyclicShortestPaths.type
Members list
In this article