6.4 Maximum Flow 笔记+理解

Mincut Problem

Given a edge-weighted (positive capacity) digraph, with a source vertex s and a target vertex t,

Defs:

  • An st-cut is a cut that partitions the vertices into one subset A containing s and the other one B containing t.
  • A cut's capacity is the sum of the capacities of edges from A to B (don't count the edges from B to A).
  • A minimum st-cut (mincut) problem is to find the cut with minimum capacity.

Maxflow Problem

Assume: no flow into s and no flow out from t

Defs:

  • An st-flow (flow) is an assignment of flows to the edges s.t.
    • capacity constraint: 0 \leq \text{edge's flow} \leq \text{edge's capacity}
    • low equilibrium: for each vertex, flow in = flow out (except for s and t)
  • the value of a flow is the sum of flows into t
  • maxflow problem is to find the flow with maximum value.

Maxflow-mincut Theorem

def: A net flow across a cut(A,B) is the sum of flows from A to B minus the sum of flows from B to A.

Flow-value Lemma: Let f be any flow, and let (A,B) be any cut, then net flow across (A,B) = value of f.
Pf:

  • by induction, base case from B = {t} when the net flow across (A,B) = inflows to t = value of f
  • because of the local equilibrium, adding any other vertices into B won't change the net flow


Weak Duality: value of f \leq cut capacity
Pf: value of f = (1) net flow across (A,B) \leq (2) cut capacity:

  • (1) because the flow-value lemma
  • (2) note: given a cut(A, B), net flow is flow from A to B minus flow from B to A, but cut capacity only add up the capacities from A to B and never subtract anything.

Def: An augmenting path is an undirected path from s to t that no forward edge is full and no backward edge is empty.

Augmenting Path Theorem: A flow is the maxflow iff no augmenting paths.
Maxflow-mincut Theorem: Value of the maxflow = capacity of the Mincut.
Pf: Show the following three conditions are equivalent for any flow f:

  1. There's a cut whose capacity = the value of flow f
  2. f is a maxflow
  3. no augmenting paths w.r.t f

[1 \Rightarrow 2]: value of f \leq cut capacity (weak duality), so the equality holds when f is the maxflow.
[2 \Rightarrow 3]: if there's another augmenting path, there'll be another flow f' with a larger value, so f is not a maxflow, so contradiction.
[3 \Rightarrow 1]:

  • no augmenting paths means s is blocked from f by some full forward edges and some empty backward edges
  • so can find a cut (A,B) where the edges between A and B are all full/empty edges (if not, there can be an augmenting path through that non-full/non-empty edge, so contradiction)
  • then, the capacity of that cut = sum of edge capacities from A to B = sum of edge flows from A to B (edges are full)
  • the net flow across (A,B) = sum of edge flows from A to B - sum of edge flows from B to A ( which is 0 since backward edges are empty so the flows = 0)
  • therefore, the capacity of (A,B) = the net flow across (A,B) = value of f
  • and by weak duality (value of f \leq cut capacity), the capacity is min. and the cut is the mincut.

Ford-Fulkerson algorithm

  • Start from 0 flow
  • While there's another augmenting path:
    • find an augmenting path
    • calculate the bottleneck capacity of that path
    • increase flow on that path by bottleneck capacity

Simplification: the edge capacities and flows are all integers, so that: Number of augmentations \leq the value of the maxflow.

Potential Problem:

Using the augmenting paths through the capacity 1 edge will make the number of augmentations rather large

Solution: use shortest/fattest path

Implementation (shortest path version)

Flow Edge API

Use Residual capacity:

  • forward: C_e - f_e
  • backward: C_e
    i.e. convert edges from:

    to:
FlowEdge API
public double residualCapacityTo(int v) {
    if (v == from()) { return flow() } // backward
    if (v == to()) { return capacity() - flow() } // forward
    throw new IllegalArgumentException();
}

public void addResidualFlowTo(int v, double delta) {
    if (v == from()) { this.flow -= delta; }
    if (v == to()) { this.flow += delta; }
    throw new IllegalArgumentException();
}

Flow Network API

-- similar to the implementation of an undirected graph:

  • adjacency-lists representation
  • add edge e=v \to w to both v and w (even if e has direction)

Find augmenting path:

shortest path version uses BFS

private boolean hasAugmentingPath(FlowNetwork G, int s, int t) {
    edgeTo = new FlowEdge[G.V()];
    marked = new boolean[G.V()];
    Queue<Integer> q = Queue<>(); // queue for BFS
    q.enqueue(s); // start from the source
    while (!q.isEmpty()) {
        int v = q.dequeue(); 
        for (FlowEdge e : G.adj(v)) {
            int w = e.other(v);
            // check is it full/empty or is it visited
            if (e.residualCapacityTo(w) > 0 && !marked[w]) {
                marked[w] = true;
                edgeTo[w] = e;
                q.enqueue(w);
            }
        }
    }
    return marked[t]; // whether target t can be reached
}

The Algorithm:

public class FordFulkerson {
    private boolean[] marked; // true if s->v path in residual network
    private FlowEdge[] edgeTo; // last edge on s->v path
    private double value; // value of flow

    public FordFulkerson(FlowNetwork G, int s, int t) {
        value = 0.0;
        while (hasAugmentingPath()) {
            double bottle = INFINITY;
            // calculate the bottleneck capacity
            for (int v = t; v != s; v = edgeTo[v]) {
                bottle = Math.min(edgeTo[v].residualCapacityTo(v), bottle);
            }
            // augment flow
            for (int v = t; v != s; v = edgeTo[v]) {
                edgeTo[v].addResidualFlowTo(v, bottle);
            }
            value += bottle;
        }
    }
    
    private boolean hasAugmentingPath(FlowNetwork G, int s, int t) { 
        /* See method above. */ 
    }
}

Running time:

digraph with V vertices, E edges, and integer capacities between 1 and U

TO BE COMPLETED: two applications.

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 202,723评论 5 476
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,080评论 2 379
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 149,604评论 0 335
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,440评论 1 273
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,431评论 5 364
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,499评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,893评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,541评论 0 256
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,751评论 1 296
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,547评论 2 319
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,619评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,320评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,890评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,896评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,137评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,796评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,335评论 2 342

推荐阅读更多精彩内容

  • min cut there is an edge-weighted digraph, source vertex ...
    西部小笼包阅读 72评论 0 0
  • 我是黑夜里大雨纷飞的人啊 1 “又到一年六月,有人笑有人哭,有人欢乐有人忧愁,有人惊喜有人失落,有的觉得收获满满有...
    陌忘宇阅读 8,520评论 28 53
  • 人工智能是什么?什么是人工智能?人工智能是未来发展的必然趋势吗?以后人工智能技术真的能达到电影里机器人的智能水平吗...
    ZLLZ阅读 3,761评论 0 5
  • 上周六在压力下实在需要释放,去西塘躲了两天,真是好地方,很优雅的江南古镇,而且与周庄比开发不算过度。 我们是周五半...
    聚塔阅读 798评论 2 2
  • 首先介绍下自己的背景: 我11年左右入市到现在,也差不多有4年时间,看过一些关于股票投资的书籍,对于巴菲特等股神的...
    瞎投资阅读 5,639评论 3 8