We want to find (design) a maximum flow from the source to the sink:
flow of the maximum total amount, while flow on each edge is not greater than capacity of the edge
continuous flow of the maximum total rate, while rate of flow on each edge is not greater than the capacity of this edge
Slide 4-5: problem of representatives and reduction to maximum-flow
Other flow problems
Flow-feasibility problem: find a feasible flow that satisfies edge capacities and specified supply / demand values at the nodes.
This problem is ‘equivalent’ to maximum flow problem.
Minimum-cost flow & multi-commodity flow problems
Flows
We assume that if (u,v)∈E, then (v,u)∈/E.
If there are ‘antiparallel’ edges, we can convert the network into an equivalent with no antiparallel edges by adding an additional vertex:
Flow
A flow is a function f:E→R where f(u,v)≥0 is the flow on edge (u,v) with properties:
Capacity constraints: for each edge (u,v)∈E, 0≤f(u,v)≤c(u,v)
Flow conservation: for each node v∈V−{s,t}:
The total flow into v is equal to total flow out of vflow ina+b+c(x,v)∈E∑f(x,v)=flow out=d+e=(v,z)∈E∑f(v,z)
i.e. net flow into v is equal to 0net flow into va+b+c−d−e(x,v)∈E∑f(x,v)−(v,z)∈E∑f(v,z)=0=0=0
A flow f can be ‘decomposed’ into at most m paths from s to t and cycles, where m is the number of edges in G.
Example: decompose following flow into paths
The algorithm works by selecting and removing (from current flow) ‘maximal’ s−t path flows. Each path removes all remaining flow from at least one edge, so at most m paths.
The algorithm can be extended to the case where there are flow cycles.
One flow path (or cycle) can be found in O(n) time, and there are at most m paths / cycles selected, so total running time is O(nm). (less than the time needed to find maximum flow)
Flow-feasibility problem
In the Flow-Feasibility problem, we are given an input G=(V,E,c,d) where V and E are sets of nodes and edges; for each (v,u)∈E,c(v,u≥0) is the capacity of edge (v,u); for each v∈V, d(v) indicates the supply / demand at node v.
d(v)>0: supply of d(v) units at v
d(v)<0: demand of ∣d(v)∣ units at v
d(v)=0: ‘transitional’ node; flow only passes through
We assume ∑v∈Vd(v)=0, total supply equals demand.
And hence we want to find a feasible flowf that is a flow within edge capacities and such that for each node v∈V, the net flow from v equals d(v) (flow convervation property). ∑(v,x)∈Ef(v,x)−∑(z,v)∈Ef(z,v)=d(v)
Reduction from flow-feasibility to maximum-flow problem
For a given input G=(V,E,c,d) of the flow-feasibility problem, we construct the input G′=(V′,E′,C′,s,t) where:
V′=V∪{s,t} where s and t are new nodes
E' = E \cup \{ (s,v): v \in V, d(v) > 0 \} \cup \{ (u,t): u \in V, d(u) < 0 \}$$
Create edges from stosupplynodesandfromdemandnodestot$.
c′(v,u)=c(v,u);c′(s,v)=d(v);c′(u,t)=−d(u)
Set the capacity of the edges equal to the supply / demand of the respective nodes.
Hence compute a maximum flow f′ in G′:
A maximum flow in G′ saturates all edges outgoing from s iff there is a feasible flow in G.
If a maximum flow f′ in G′ saturates all edges outgoing from s, then we can remove added nodes / edges to get a feasible flow in G.
If f is a feasible flow in G, then saturate all edges outgoing from s / incoming to t to get a maximum flow in G′.
Residual capacity & networks
Residual capacity of an edge
Let f be a flow in a flow network G=(V,E,c,s,t).
The residual capacity of an edge(u,v)∈E is defined as cf(u,v)=c(u,v)−f(u,v)
The residual network of G induced by flow f is the flow network Gf=(V,Ef,cf,s,t) where cf are the residual capacities and Ef is the set of residual edges.
A residual path is a simple path in the residual network Gf.
The augmenting path is a residual path from s to t.
The residual capacity of an augmenting path p is the maximum amount of flow that can be sent along path p: cf(p)=min{cf(u,v)∣(u,v) is an edge on p}
Let p be an augmenting path in Gf. The (path) flow fp in Gf is: fp(u,v)={cf(p)0if (u,v) is on potherwise
The value of flow fp is ∣fp∣=cf(p)>0.
Example: increase flow using residual network
Input network G and flow f of value 7
Residual network Gf
Flow f′ of value 1 in residual network Gf
Input network G and flow h=f↑f′ of values 7+1=8.
Augmenting current flow by flow in residual network
If f is a flow in G and f′ is a flow in the residual network Gf, then we can augment f by f′ to get a new greater flow h in G.
The new flow h=f↑f′ in G is defined in the following way:
h(u,v)={f(u,v)+f′(u,v)−f′(v,u)0if (u,v)∈Eotherwise
This definition of f↑f′ works also if both f′(u,v) and f′(v,u) are positive.
∣f↑f′∣=∣f∣+∣f′∣: the value of flow f↑f′ (net flow from source) is equal to sum of values of flows f and f′.
General approach to finding maximum flow
Start with zero flow and keep iteratively increasing flow by flows in residual network:
Construct residual network Gf
Find a non-zero flow f′ in Gf
If there is none, exit
f←f↑f′ (augmentation)
Most max-flow algorithms follow this general approach.
Ford-Fulkerson method
Fold-Fulkerson method
def ford_fulkerson(G): # G = (V, E, c, s, t) f = zero flow # f(u, v) = 0 for each (u, v) in E while True: G_f = # (1) construct residual network P = # (2) find an augmenting path in G_f (DFS) if P is None: return f f = f ^ f_p # (3) path augmentation
Running time of Fold-Fulkerson method
Given n is the number of nodes, and m is the number of edges.
The running time of one iteration is O(m):
construct Gf: Θ(m) or O(n) if incremental
search Gf to find augmenting path: O(m)
update the flow: O(n)
Number of iterations depends on selection strategy in step (2).
Number of iterations in Ford-Fulkerson
The number of iterations in Ford-Fulkerson method depends on strategy of selecting an augmenting path p in each iteration. If the algorithm is run on a network such that all edge capacities are integral:
Residual capacities are integral throughout the computation, so the value of the current flow in G increases in each iteration by some integer, at least 1.
If f∗ denotes a maximum flow, then the number of iterations is at most ∣f∗∣.
Hence total running time is O(∣f∗∣m) (does not depend on selection strategy).
No general bound on number of iterations which would depend only on size of network (n and m).
Cuts
A cut(S,T) in a network G: S⊆V,T=V−S,s∈S,t∈T.
That is, a cut is a partitioning of the set of nodes V into two disjoint sets S and T such that the source node s is in the set S and the sink node t is in the set T.
The capacity of a cut(S,T) is the sum of the capacities of the edges from S to T: c(S,T)=∑(u,v)∈E:u∈S,v∈Tc(u,v)
If f is a flow, then the net flow across the cut(S,T) is: f(S,T)=∑(u,v)∈E:u∈S,v∈Tf(u,v)−∑(u,v)∈E:u∈S,y∈Sf(x,y)
For each cut (S,T), f(S,T)=∣f∣, that is, the net flow across the cut is equal to the net flow into the sink t.
Example of a cut
For this cut (S,T) and flow f:
c(S,T)=4+7+7+1+6=25
f(S,T)=7+3+1−2=9=∣f∣
Theorem 1. Max-flow Min-cut theorem
For any flow f and any cut (S,T): ∣f∣=f(S,T)≤c(S,T) (the net flow across a cut cannot be greater than the capacity of this cut).
Therefore, the value of a maximum flow is not greater than the minimum capacity of a cut.
max{∣f∣:f is a flow in G}≤min{c(S,T):(S,T) is a cut in G}
This cut (S,T) is a minimum capacity cut, c(S,T)=5+2+2+1=10, so the maximum value of flow for t his network is not greater than 10.
Theorem 2.
For a flow f in G, the following three conditions are equivalent.
a. f is a maximum flow in G
b. there is no augmenting path in the residual network Gf
c. for some cut (S,T) in G, ∣f∣=c(S,T)
We can prove this by showing implications (a)⇒(b)⇒(c)⇒(a)
(a)⇒(b): assume f is a maximum flow in G
If there is an augmenting path, then the flow cannot be maximum because we can use such a path to increase the value of the flow.
(b)⇒(c): assume no augmenting path in Gf
Let S be the set of nodes reachable from s in the residual network Gft is not in S
All edges from S to T=V−S are saturated.
All edges from T to S have zero flow.
Therefore, ∣f∣=f(S,T)=c(S,T).
(c)⇒(a): let (S,T) be a cut as in (c)∣f∣=f(S,T)=c(S,T) but there is no flow of value greater than c(S,T) so f is a maximum flow
Theorem 1 follows from Theorem 2
(a)⇒(c), so for a maximum flow f, there is a cut (S,T) such that ∣f∣=f(S,T)=c(S,T)≥min{c(S′,T′):(S′,T′) is a cut in G}