Class FordFulkerson
- java.lang.Object
-
- edu.princeton.cs.algs4.FordFulkerson
-
public class FordFulkerson extends java.lang.ObjectTheFordFulkersonclass represents a data type for computing a maximum st-flow and minimum st-cut in a flow network.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()andvalue()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 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
-
-
Constructor Summary
Constructors Constructor and Description FordFulkerson(FlowNetwork G, int s, int t)Compute a maximum flow and minimum cut in the networkGfrom vertexsto vertext.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description booleaninCut(int v)Returns true if the specified vertex is on thesside of the mincut.static voidmain(java.lang.String[] args)Unit tests theFordFulkersondata type.doublevalue()Returns the value of the maximum flow.
-
-
-
Constructor Detail
-
FordFulkerson
public FordFulkerson(FlowNetwork G, int s, int t)
Compute a maximum flow and minimum cut in the networkGfrom vertexsto vertext.- Parameters:
G- the flow networks- the source vertext- the sink vertex- Throws:
java.lang.IllegalArgumentException- unless0 <= s < Vjava.lang.IllegalArgumentException- unless0 <= t < Vjava.lang.IllegalArgumentException- ifs == tjava.lang.IllegalArgumentException- if initial flow is infeasible
-
-
Method Detail
-
value
public double value()
Returns the value of the maximum flow.- Returns:
- the value of the maximum flow
-
inCut
public boolean inCut(int v)
Returns true if the specified vertex is on thesside of the mincut.- Parameters:
v- vertex- Returns:
trueif vertexvis on thesside of the micut;falseotherwise- Throws:
java.lang.IllegalArgumentException- unless0 <= v < V
-
main
public static void main(java.lang.String[] args)
Unit tests theFordFulkersondata type.- Parameters:
args- the command-line arguments
-
-
DataMelt 3.0 © DataMelt by jWork.ORG