类 FordFulkerson
- java.lang.Object
-
- edu.princeton.cs.algs4.FordFulkerson
-
public class FordFulkerson extends java.lang.Object
TheFordFulkerson
class 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.
-
-
构造器概要
构造器 构造器 说明 FordFulkerson(FlowNetwork G, int s, int t)
Compute a maximum flow and minimum cut in the networkG
from vertexs
to vertext
.
-
-
-
构造器详细资料
-
FordFulkerson
public FordFulkerson(FlowNetwork G, int s, int t)
Compute a maximum flow and minimum cut in the networkG
from vertexs
to vertext
.- 参数:
G
- the flow networks
- the source vertext
- the sink vertex- 抛出:
java.lang.IllegalArgumentException
- unless0 <= s < V
java.lang.IllegalArgumentException
- unless0 <= t < V
java.lang.IllegalArgumentException
- ifs == t
java.lang.IllegalArgumentException
- if initial flow is infeasible
-
-
方法详细资料
-
value
public double value()
Returns the value of the maximum flow.- 返回:
- the value of the maximum flow
-
inCut
public boolean inCut(int v)
Returns true if the specified vertex is on thes
side of the mincut.- 参数:
v
- vertex- 返回:
true
if vertexv
is on thes
side of the micut;false
otherwise- 抛出:
java.lang.IllegalArgumentException
- unless0 <= v < V
-
main
public static void main(java.lang.String[] args)
Unit tests theFordFulkerson
data type.- 参数:
args
- the command-line arguments
-
-