public class FordFulkerson extends Object
This implementation uses the Ford-Fulkerson algorithm with the shortest augmenting path heuristic. The constructor takes time proportional to E V (E + V) in the worst case and extra space (not including the network) proportional to V, where V is the number of vertices and E is the number of edges. In practice, the algorithm will run much faster. Afterwards, the inCut() and value() methods take constant time.
If the capacities and initial flow values are all integers, then this implementation guarantees to compute an integer-valued maximum flow. If the capacities and floating-point numbers, then floating-point roundoff error can accumulate.
For additional documentation, see Section 6.4 Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
| Constructor and Description |
|---|
FordFulkerson(FlowNetwork G,
int s,
int t)
Compute a maximum flow and minimum cut in the network G
from vertex s to vertex t.
|
public FordFulkerson(FlowNetwork G, int s, int t)
G - the flow networks - the source vertext - the sink vertexIndexOutOfBoundsException - unless 0 <= s < VIndexOutOfBoundsException - unless 0 <= t < VIllegalArgumentException - if s = tIllegalArgumentException - if initial flow is infeasiblepublic double value()
public boolean inCut(int v)
IndexOutOfBoundsException - unless 0 <= v < Vpublic static void main(String[] args)
Copyright © 2014. All Rights Reserved.