最大流最小割問題

本節的內容是最大流 (Max Flow) - 最小割 (Mini-Cut) 問題,涉及的算法是 Ford-Fulkerson 算法。

Definitions

Flow Network

流網絡 (Flow Network) ,即圖 \(G = (V,E,s,t,c)\) :

  • \(s\) 是源點,\(t\) 是終點。
  • \(\forall{e \in E}, c(e) > 0\) ,邊的權值 \(c(e)\) 表示該邊的最大流量。

Max Flow 問題:找到給定的 \(G\) 中,\(s\)\(t\) 的最大流量。例如在下圖中,最大流量爲 30 (在點 \(u\) ,20 的流量分爲 10 + 10 走 2 個不同的邊)。

定義 \(st-flow\) 函數 \(f\)\(f(e)\) 表示實際流過該邊的流量。

Minimum Cut

嚴格來說是最小的 \(st-cut\) ,即:給定 \(s,t \in V\) ,求出權值最小的割集(即邊割集)\(S\) ,使得圖分爲 \(A,B\) 兩部分,且 \(s \in A, t \in B\) .

顯然,\(S\) 中的所有邊,一端在 \(A\) 中,另外一端在 \(B\) 中。

最大流-最小割已被證明是對偶問題,因此求出最大流即求出最小割。

Greedy Algorithm

Greedy Algorithm:

  • Start with \(f(e)=0\) for each edge \(e \in E\).
  • Find a \(s \rightarrow t\) path \(P\) where each edge has \(f(e) < c(e)\).
  • Augment flow along path \(P\).
  • Repeat until you get stuck.

通過一個例子說明貪心策略是如何工作的。

  1. 給定的圖如下。
  1. \(f(e) = 0\) 的邊開始找路徑。
  1. 修改每個邊的實際流量爲該路徑上的邊的最大權值
  1. 從另外的 \(f(e) = 0\) 的邊開始找路徑,重複上述過程。
  1. 再重複一遍。
  1. 最終結果。

上述貪心算法得到的最大流爲 16 ,而實際上,我們的最大流其實是可以達到 19 。

貪心算法得不到最優的原因:Once greedy algorithm increases flow on an edge, it never decreases it. And we need some mechanism to undo a bad decision.

比如上面的 2/2 這條邊,相當於「走錯路」了,但是貪心算法無法消除這種錯誤,這是與 Ford-Fulkerson 算法的本質區別。

Ford-Fulkerson Algorithm

Residual Network

大白話:在另外一個圖中,構造一個額外的反向邊,權值是實際流過原邊的流量 \(f(e)\)

Augmenting Path

不少地方把 Augmenting Path 翻譯爲「增廣路徑」,注意與二分圖中的增廣路徑區分。

殘留網絡 \(G_f\) 具有下列性質:

  • An augmenting path \(P\) is a simple \(s \rightarrow t\) path in the residual network \(G_f\) .
  • The bottleneck capacity of an augmenting path \(P\) is the minimum residual capacity of any edge in \(P\).

Ford-Fulkerson

該算法的時間複雜度爲 \(O(VEC)\) ,經過優化之後可以達到 \(O(E^2\log{C})\) .

Augment

Example

來自 CLRS 的《算法導論》的一個例子。

注意,在圖 e 和 圖 f 中,\((s, v_2)\) 之間的 2 條邊的權值標註應該是反過來的(這應該是書本的謬誤)。

觀察從 \(t\) 出來的 2 個反向邊,根據定義,這 2 條邊的權值就是流入 \(t\) 的流量,因此此處例子的最大流爲 23 。

前面提到,貪心算法失效的原因是:一旦選定了一條「錯誤」的邊(即不在最優解中的邊),貪心策略無法消除這種錯誤。而這裏的 Ford-Fulkerson 算法是怎麼做到這一點的呢?

在圖 (a) 中,原圖 \(G\) 給定的一邊爲 \(v_2 \rightarrow v_1\) ,在算法執行過程中,在 Residual Network 中,會產生一個反向邊 \(v_1 \rightarrow v_2\)

  • 在圖 (b) 中,選擇了一個 Augmenting Path,包括了 \(v_2 \rightarrow v_1\) 這條邊,執行 \(Augment(f,c,P)\) 之後,產生反向邊 \(v_1 \rightarrow v_2\)
  • 在圖 (c) 中,選擇了一個 Augmenting Path,包括了反向邊 \(v_1 \rightarrow v_2\) ,這表明在之前的步驟中,流量流經 \(v_2 \rightarrow v_1\) 是錯誤的選擇,這就是 Ford-Fulkerson 「錯誤修正」的方式。

引用自 Refs [4] 的一個圖解:

如果只是學這個算法去做題的話,看到這裏已經可以了。

Max-Flow Min-Cut Theorem

Lemma Let \(f\) be any flow and let \((A, B)\) be any cut. Then, the value of the flow \(f\) equals the network flow across the cut \((A, B)\).

\[val(f) = \sum_{\text{out of } A} f(e) - \sum_{\text{in to } A} f(e) \]

設把最大流的起點和終點分別爲 \(s,t\) , 並且 \(s \in A, t \in B\) ,那麼有:

\[\begin{aligned} val(f) &= \sum_{\text{out of } s} f(e) - \sum_{\text{in to } s} f(e) \\ &= \sum_{v \in A} (\sum_{\text{out of } v} f(e) - \sum_{\text{in to } v} f(e) ) \\ &= \sum_{\text{out of } A} f(e) - \sum_{\text{in to } A} f(e) \end{aligned} \]

第一個等號是根據 \(st-flow\) 函數 \(f\) 的定義;第二個等號 Flow Network 的性質;第三個等號根據集合的定義。

Theorem - Weak Duality

Corollary

Max-Flow Min-Cut Theorem

最大流 / 最小割的 3 個等價條件。

  • [\(\text{i} \Rightarrow \text{ii}\)] : 根據上述的 Weak Duality 性質和 Corollary 。

  • [\(\text{ii} \Rightarrow \text{iii}\)] : 證明其逆否命題,即 \(\lnot \text{iii} \Rightarrow \lnot\text{ii}\) .

    • 假設 \(G_f\) 中存在一個 Augmenting Path \(P\) ,那麼在路徑 \(P\) 上,我們還能繼續向 \(G_f\) 增加流量,這就意味着 \(f\) 不是一個 Max Flow 。證明成立。
  • [\(\text{iii} \Rightarrow \text{i}\)]

    • Let \(f\) be a flow with no augmenting paths.
    • Let \(A\) be set of nodes reachable from \(s\) in residual network \(G_f\) . And \(B\) is the set containing the left nodes (and every node in \(B\) can reach \(t\) ).
    • By definition of \(A\) : \(s \in A\) .
    • By definition of flow \(f\) : \(t \notin A\) .
    • 如圖所示,\(G_f\) 中沒有 Augmenting Path,當且僅當,在原圖 \(G\) 中:
      • 所有 \(A \rightarrow B\) 的邊,\(f(e) = c(e)\)
      • 所有 \(B \rightarrow A\) 的邊,\(f(e) = 0\)
      • 爲什麼呢?如果 \(G\) 存在 \(A \rightarrow B\) 的邊 \(e\)\(f(e) < c(e)\),那麼在 \(G_f\) 中會存在 \(A \rightarrow B\) 的邊,權值爲 \(c(e) - f(e)\),使得 \(G_f\) 存在 Augmenting Path 。同理, \(G\) 所有 \(B \rightarrow A\) 的邊 \(f(e) = 0\),意味着它在 \(G_f\) 中 對應的 \(e^{\text{reverse}}\) (從 A 到 B 到邊)的權值均爲 0 ,同樣保證了 A 不能到達 B (即 \(G_f\) 沒有 Augmenting Path)。
    • 那麼就有:

    \[\begin{aligned} val(f) &= \sum_{e \text{ out of } A} f(e) - \sum_{e \text{ in to } A} f(e) \\ &= \sum_{e \text{ out of } A} f(e) - 0 \\ &= \text{cap(A, B)} \end{aligned} \]

Analysis

這一節的內容很陰間,我已經不想看了。

複雜度分析的大致想法是:每次找到路徑 \(P\),都會使得流量至少增加 1 個單位,但最大流量只能爲 \(|V|C\) (所以最多隻能有 \(|V|C\) 個 Augmenting Path),\(C\) 是圖中邊的最大流量(邊權最大值)。

每次通過 BFS/DFS 找到一個 Augmenting Path,需要在 \(O(E)\) 時間,因此總的時間複雜度爲 \(O(VEC)\) .

References

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章