http://en.wikipedia.org/wiki/Ford%E2%80%93Fulkerson_algorithm
http://www.ugrad.cs.ubc.ca/~cs490/sec202/notes/flow/Flow%20Intro.pdf
http://www.ugrad.cs.ubc.ca/~cs490/sec202/notes/flow/Flow%20Intro.pdf
The Ford–Fulkerson method is an algorithm which computes the maximum flow in a flow network. The name "Ford–Fulkerson" is often also used for the Edmonds–Karp algorithm, which is a specialization of Ford–Fulkerson.
The idea behind the algorithm is as follows: As long as there is a path from the source (start node) to the sink (end node), with available capacity on all edges in the path, we send flow along one of these paths. Then we find another path, and so on. A path with available capacity is called an augmenting path.
Let be a graph, and for each edge from to , let be the capacity and be the flow. We want to find the maximum flow from the source to the sink . After every step in the algorithm the following is maintained:
Capacity constraints: The flow along an edge can not exceed its capacity. Skew symmetry: The net flow from to must be the opposite of the net flow from to (see example). Flow conservation: That is, unless is or . The net flow to a node is zero, except for the source, which "produces" flow, and the sink, which "consumes" flow. Value(f): That is, the flow leaving from or arriving at .
This means that the flow through the network is a legal flow after each round in the algorithm. We define the residual network to be the network with capacity and no flow. Notice that it can happen that a flow from to is allowed in the residual network, though disallowed in the original network: if and then .
Algorithm Ford–Fulkerson
- Inputs Given a Network with flow capacity , a source node , and a sink node
- Output Compute a flow from to of maximum value
- for all edges
- While there is a path from to in , such that for all edges :
- Find
- For each edge
- (Send flow along the path)
- (The flow might be "returned" later)
The path in step 2 can be found with for example a breadth-first search or a depth-first search in . If you use the former, the algorithm is calledEdmonds–Karp.
When no more paths in step 2 can be found, will not be able to reach in the residual network. If is the set of nodes reachable by in the residual network, then the total capacity in the original network of edges from to the remainder of is on the one hand equal to the total flow we found from to , and on the other hand serves as an upper bound for all such flows. This proves that the flow we found is maximal. See also Max-flow Min-cut theorem.
If the graph has multi Sources and Sinks, we act as follows. Suppose that and . Add a new source with an edge from to every node , with capacity . And add a new sink with an edge from to every node , with capacity . Then applying the Ford–Fulkerson algorithm.
Also if every nodes has constraint , we replace this node with two nodes , and an edge , with capacity . and then applying the Ford–Fulkerson algorithm.
http://blog.csdn.net/smartxxyx/article/details/9293665