Modul Maximum Flow
Modul Maximum Flow
Augmenting Path
Here is a version of the pseudo-code that explains the flow augmentation more in depth:
flow = 0
1 for each edge (u, v) in G:
2
flow(u, v) = 0
3 while there is a path, p, from s -> t in residual network G_f:
4 residual_capacity(p) = min(residual_capacity(u, v) : for (u, v) in p)
5 flow = flow + residual_capacity(p)
6 for each edge (u, v) in p:
7 if (u, v) is a forward edge:
8 flow(u, v) = flow(u, v) + residual_capacity(p)
9 else:
10 flow(u, v) = flow(u, v) - residual_capacity(p)
11 return flow
12
An edge in the residual graph is a 'forward edge' if the edge existed in the original graph G. If it is a
reversal of an original edge, it is called a 'backwards edge.'
Edmonds-Karp Algorithm
Edmonds-Karp improves the runtime of Ford-Fulkerson, which is O(∣E∣⋅f∗) to O(∣V∣⋅∣E∣2). BFS finds the
path with least number of vertices visited from source to sink.
1 inputs
2 C[n x n] : Capacity Matrix
3 E[n x n] : Adjacency Matrix
4 s : source
5 t : sink
6 output
7 f : maximum flow
8 Edmonds-Karp:
9 f = 0 // Flow is initially 0
10 F = [n x n] // residual capacity array
11 while true:
12 m, P = Breadth-First-Search(C, E, s, t, F)
13 if m = 0:
14 break
15 f = f + m
16 v = t
while v != s:
17 u = P[v]
18 F[u, v] = F[u, v] - m
19 F[v, u] = F[v, u] + m
20 v = u
21 return f
22
Dinic Algorithm
1) Initialize residual graph G as given graph.
1) Do BFS of G to construct a level graph (or assign levels to vertices) and also check if more flow is
possible.
a) If more flow is not possible, then return.
b) Send multiple flows in G using level graph until blocking flow is reached. Here using level graph
means, in every flow, levels of path nodes should be 0, 1, 2... (in order) from s to t.
A flow is Blocking Flow if no more flow can be sent using level graph, i.e., no more s-t path exists
such that path vertices have current levels 0, 1, 2… in order.