|
| 1 | +--- |
| 2 | +tags: |
| 3 | + - OMSCS |
| 4 | + - Algorithms |
| 5 | + - Alg-Graph |
| 6 | +--- |
| 7 | +# 05.2 - Max Flow - Max-Flow Min-Cut |
| 8 | +## Outline |
| 9 | +1. max-flow = min st-cut theorem |
| 10 | + 1. image segmentation |
| 11 | +2. Correctness of Ford-Fulkerson algorithm |
| 12 | + |
| 13 | +## Ford-Fulkerson Alg |
| 14 | +**input:** flow network |
| 15 | +- directed graph: $G=(V,E)$ |
| 16 | +- start node and end node: $s,t \in V$ |
| 17 | +- capacities: $c_e > 0$ |
| 18 | + |
| 19 | +**output:** |
| 20 | +- flow $f^*$ of max size |
| 21 | +- $size(f)=f_{out}(s)=f_{in}(t)$ |
| 22 | + |
| 23 | +When does Ford-Fulkerson stop? It stops when there is no augmenting path in residual $G^{f^*}$. |
| 24 | + |
| 25 | +**Lemma:** For a flow $f^*$, if no augmenting path in $G^{f^*}$ exists, then $f^*$ is a max-flow in $G$ |
| 26 | + |
| 27 | +## Verifying Max Flow |
| 28 | +> **Q:** Given a flow network and a flow $f$, what is the time to check whether or not $f$ is a max flow? |
| 29 | +> |
| 30 | +> **A:** $O(n+m)$ |
| 31 | +
|
| 32 | +There is no augmenting path in $G^{f^*}$ if there is no path from $s$ to $t$. This can be accomplished with a DFS, which is $O(n+m)$. |
| 33 | + |
| 34 | +## Min-Cut Problem |
| 35 | +- A $cut$ is a partition of $V=L \cup R$ |
| 36 | +- An "st-cut" is a cut where $s \in L$ and $t \in R$ |
| 37 | +- Neither $L$ nor $R$ needs to be a connected set. |
| 38 | + |
| 39 | +![[Pasted image 20260311195056.png]] |
| 40 | + |
| 41 | +Below is the "capacity" of the cut. This is the sum of edges $vw$ where $v$ is in $L$ and $w$ is in $R$. |
| 42 | + |
| 43 | +$$capacity(L,R)=\sum_{vw \in E, \space v \in L, \space w \in R}c_{vw}$$ |
| 44 | + |
| 45 | +## Problem Formulation |
| 46 | +**input:** flow network |
| 47 | + |
| 48 | +**output:** |
| 49 | +- st-cut$(L,R)$ with minimum capacity. |
| 50 | + |
| 51 | +On the flow network from [[05.1.1 - Max Flow - FF]], the screenshot below demonstrates the minimum cut. The minimum cut is 12, which equals the max flow on the same flow network. This proves the max-flow = min-cut theorem (/s). |
| 52 | + |
| 53 | +![[Pasted image 20260311195427.png]] |
| 54 | + |
| 55 | + |
| 56 | +## Theorem |
| 57 | +> For a given flow network, the size of the max flow equals the minimum capacity of an st-cut. |
| 58 | +
|
| 59 | +### Proof 1 - max-flow $\le$ min st-cut |
| 60 | +For any flow $f$ and any st-cut$(L,R)$: |
| 61 | + |
| 62 | +$$size(f) \le capacity(L,R)$$ |
| 63 | +$$ |
| 64 | +\max_f \{size(f)\} \le \min_{(L,R)} \{capacity(L,R)\}$$ |
| 65 | + |
| 66 | +**Claim:** $size(f) = f_{out}(L) - f_{in}(L)$ |
| 67 | + |
| 68 | +$$f_{out}(L)-f_{in}(L)=$$ |
| 69 | +$$\sum_{vw \in E, \space v \in L, \space w \in R} f_{vw} - \sum_{wv \in E, \space w \in R, \space v \in L }f_{wv}+\sum_{vw \in E, \space v \in L, \space w \in L } f_{vw}-\sum_{wv \in E, \space w \in L, \space v \in L}f_{wv}$$ |
| 70 | + |
| 71 | +- First summation |
| 72 | + - The sum of the flows for each edge (v,w) where v is in L and w is in R. |
| 73 | + - This is the sum of the flows leaving L to R |
| 74 | +- Second term |
| 75 | + - The sum of the flows for each edge (w,v) where w is in R and v is in L. |
| 76 | + - This is the sum of flows leaving R to L |
| 77 | +- Third term |
| 78 | + - The sum of the flows for each edge (v,w) where v is in L and w is in L |
| 79 | + - This is the sum of flows which are internal to L |
| 80 | +- Fourth term |
| 81 | + - The sum of flows for each edge (w,v) where w is in L and v is in L |
| 82 | + - This is another sum of flows which are internal to L |
| 83 | +- The third term and fourth term appear to cancel out. |
| 84 | + |
| 85 | +The first and third terms give us $f_{out}(L)$. |
| 86 | +$$f_{out}(L)=\sum_{v \in L}f_{out}(v)$$ |
| 87 | + |
| 88 | + The second and fourth terms give us $f_{out}(v)$ |
| 89 | +$$f_{out}(v)=\sum_{v \in L}f_{in}(v)$$ |
| 90 | + |
| 91 | +The set $L$ contains the source vertex $s$. We know that the flow in to $s$ is $0$, and that the flow out of $s$ contains the flow out of $L$. |
| 92 | + |
| 93 | +$$f_{out}(L)-f_{in}(L)=\bigg(\sum_{v \in (L - s)}\big(f_{out}(v)-f_{in}(v)\big)\bigg) + f_{out}(s)$$ |
| 94 | + |
| 95 | +What do we know about the summation? We know that the flow out of any vertex must equal the flow in to the vertex. That's one of the conditions for a valid flow. Therefore, we can drop the whole summation. |
| 96 | + |
| 97 | +$$\sum_{v \in (L - s)}\big(f_{out}(v)-f_{in}(v)\big)=0$$ |
| 98 | +$$f_{out}(L)-f_{in}(L)=f_{out}(s)=size(f)$$ |
| 99 | + |
| 100 | +$$size(f)=f_{out}(L)-f_{in}(L) \le f_{out}(L) \le cap(L,R)$$ |
| 101 | + |
| 102 | +### Proof 2 - max-flow $\ge$ min st-cut |
| 103 | + |
| 104 | +$$\max_f \{ size(f) \} \ge \min_{(L,R)} cap(L,R)$$ |
| 105 | + |
| 106 | +- Take flow $f^*$ from Ford-Fulkerson alg |
| 107 | +- $f^*$ has no st-path in residual $G^{f^*}$ |
| 108 | +- we'll construct $(L,R)$ where: |
| 109 | + |
| 110 | +$$\max_f \{ size(f) \} \ge size(f^*) = cap(L,R) \ge \min_{(L,R)} cap(L,R)$$ |
| 111 | + |
| 112 | +The operative bit in this proof is $size(f^*) = cap(L,R)$. Take flow $f^*$ with no st-path in residual $G^{f^*}$. Let $L=$ vertices reachable from $s$ in $G^{f^*}$. |
| 113 | +- We know $t \notin L$. |
| 114 | +- Let $R = V - L$ |
| 115 | + |
| 116 | +What are the properties of the cut we just constructed? |
| 117 | +- Flow $f^*$ with no st-path in $G^{f^*}$ |
| 118 | +- $L=$ vertices reachable from $s$ in $G^{f^*}$ |
| 119 | + |
| 120 | +See below for an example graph with residuals labelled on the original graph. The graph on the right is the residual network where only some amount of capacity remains. |
| 121 | + |
| 122 | +The set $L$ is labelled on the graph. The remaining 3 vertices are set $R$. The edge capacities are no longer important. We can view the graph as an unweighted directed graph, and simply check for connectivity via DFS / BFS / SCC. |
| 123 | + |
| 124 | +![[Pasted image 20260311223624.png]] |
| 125 | + |
| 126 | +Notice how edges $sc$, $dc$, and $dt$ do not appear in the residual network. This means that in this residual graph, $f^*_{out}(L)=cap(L,R)$. |
| 127 | + |
| 128 | +Notice also how edge $ef$ DOESN'T appear in the residual network. That's because there is no flow running along edge $fe$. If there was flow running along that edge, then $f$ would be included in the residual network. From this, we can conclude that $f^*_{in}(L)=0$ |
| 129 | + |
| 130 | +$$size(f^*)=cap(L,R)-0$$ |
| 131 | + |
0 commit comments