- java.lang.Object
-
- org.jgrapht.alg.shortestpath.DagAllPathsCounter
-
public final class DagAllPathsCounter extends Object
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
IllegalArgumentExceptionis thrown otherwise.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <V,E>
BigIntegercountAllPaths(Graph<V,E> graph, V source, V target)Count the number of simple directed paths fromsourcetotargetin the given directed acyclic graph.
-
-
-
Method Detail
-
countAllPaths
public static <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.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
-
-