java.lang.Object
org.jgrapht.alg.shortestpath.DagAllPathsCounter
Counts the number of simple directed paths in a Directed Acyclic Graph (DAG) between a given
source and target using dynamic programming in topological order.
For large graphs the number of paths can be extremely large; values are returned as
BigInteger.
Usage constraints: the provided graph must be directed and acyclic. An
IllegalArgumentException is thrown otherwise.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <V,E> BigInteger countAllPaths(Graph<V, E> graph, V source, V target) Count the number of simple directed paths fromsourcetotargetin the given directed acyclic graph.
-
Method Details
-
countAllPaths
Count the number of simple directed paths fromsourcetotargetin the given directed acyclic graph.Edge case semantics:
- If
sourceortargetis not contained in the graph, throwsIllegalArgumentException. - If
source.equals(target), the empty path (length 0) is counted as one path and paths that leavesourceand return to it cannot exist in a DAG, thus the result is 1. - If there is no path from
sourcetotarget, returnsBigInteger.ZERO.
- Type Parameters:
V- vertex typeE- edge type- Parameters:
graph- directed acyclic graphsource- source vertextarget- target vertex- Returns:
- number of simple directed paths from
sourcetotarget - Throws:
IllegalArgumentException- if the graph is not directed, not acyclic, or vertices are missing
- If
-