• Ford–Fulkerson algorithm


    The Ford–Fulkerson method or Ford–Fulkerson algorithm (FFA) is a greedy algorithm that computes the maximum flow in a flow network. It is sometimes called a “method” instead of an “algorithm” as the approach to finding augmenting paths in a residual graph is not fully specified[1] or it is specified in several implementations with different running times.[2] It was published in 1956 by L. R. Ford Jr. and D. R. Fulkerson.[3] The name “Ford–Fulkerson” is often also used for the Edmonds–Karp algorithm, which is a fully defined implementation of the Ford–Fulkerson method.

    The idea behind the algorithm is as follows: as long as there is a path from the source (start node) to the sink (end node), with available capacity on all edges in the path, we send flow along one of the paths. Then we find another path, and so on. A path with available capacity is called an augmenting path.

    1 Algorithm

    Let {\displaystyle G(V,E)}G(V,E) be a graph, and for each edge from u to v, let {\displaystyle c(u,v)}c(u,v) be the capacity and {\displaystyle f(u,v)}f(u,v) be the flow. We want to find the maximum flow from the source s to the sink t. After every step in the algorithm the following is maintained:

    Capacity constraints {\displaystyle \forall (u,v)\in E:\ f(u,v)\leq c(u,v)}{\displaystyle \forall (u,v)\in E:\ f(u,v)\leq c(u,v)} The flow along an edge cannot exceed its capacity.
    Skew symmetry {\displaystyle \forall (u,v)\in E:\ f(u,v)=-f(v,u)}{\displaystyle \forall (u,v)\in E:\ f(u,v)=-f(v,u)} The net flow from u to v must be the opposite of the net flow from v to u (see example).
    Flow conservation {\displaystyle \forall u\in V:u\neq s{\text{ and }}u\neq t\Rightarrow \sum {w\in V}f(u,w)=0}\forall u\in V:u\neq s{\text{ and }}u\neq t\Rightarrow \sum {w\in V}f(u,w)=0 The net flow to a node is zero, except for the source, which “produces” flow, and the sink, which “consumes” flow.
    Value(f) {\displaystyle \sum {(s,u)\in E}f(s,u)=\sum {(v,t)\in E}f(v,t)}\sum {(s,u)\in E}f(s,u)=\sum {(v,t)\in E}f(v,t) The flow leaving from s must be equal to the flow arriving at t.
    This means that the flow through the network is a legal flow after each round in the algorithm. We define the residual network {\displaystyle G
    {f}(V,E
    {f})}G
    {f}(V,E
    {f}) to be the network with capacity {\displaystyle c
    {f}(u,v)=c(u,v)-f(u,v)}c
    {f}(u,v)=c(u,v)-f(u,v) and no flow. Notice that it can happen that a flow from v to u is allowed in the residual network, though disallowed in the original network: if {\displaystyle f(u,v)>0}f(u,v)>0 and {\displaystyle c(v,u)=0}c(v,u)=0 then {\displaystyle c_{f}(v,u)=c(v,u)-f(v,u)=f(u,v)>0}c_{f}(v,u)=c(v,u)-f(v,u)=f(u,v)>0.

    Algorithm Ford–Fulkerson
    Inputs Given a Network {\displaystyle G=(V,E)}G=(V,E) with flow capacity c, a source node s, and a sink node t
    Output Compute a flow f from s to t of maximum value
    {\displaystyle f(u,v)\leftarrow 0}f(u,v)\leftarrow 0 for all edges {\displaystyle (u,v)}(u,v)
    While there is a path p from s to t in {\displaystyle G_{f}}G_{f}, such that {\displaystyle c_{f}(u,v)>0}c_{f}(u,v)>0 for all edges {\displaystyle (u,v)\in p}(u,v)\in p:
    Find {\displaystyle c_{f}§=\min{c_{f}(u,v):(u,v)\in p}}c_{f}§=\min{c_{f}(u,v):(u,v)\in p}
    For each edge {\displaystyle (u,v)\in p}(u,v)\in p
    {\displaystyle f(u,v)\leftarrow f(u,v)+c_{f}§}f(u,v)\leftarrow f(u,v)+c_{f}§ (Send flow along the path)
    {\displaystyle f(v,u)\leftarrow f(v,u)-c_{f}§}f(v,u)\leftarrow f(v,u)-c_{f}§ (The flow might be “returned” later)
    “←” denotes assignment. For instance, “largest ← item” means that the value of largest changes to the value of item.
    “return” terminates the algorithm and outputs the following value.
    The path in step 2 can be found with, for example, a breadth-first search (BFS) or a depth-first search in {\displaystyle G_{f}(V,E_{f})}G_{f}(V,E_{f}). If you use the former, the algorithm is called Edmonds–Karp.

    When no more paths in step 2 can be found, s will not be able to reach t in the residual network. If S is the set of nodes reachable by s in the residual network, then the total capacity in the original network of edges from S to the remainder of V is on the one hand equal to the total flow we found from s to t, and on the other hand serves as an upper bound for all such flows. This proves that the flow we found is maximal. See also Max-flow Min-cut theorem.

    If the graph {\displaystyle G(V,E)}G(V,E) has multiple sources and sinks, we act as follows: Suppose that {\displaystyle T={t\mid t{\text{ is a sink}}}}{\displaystyle T={t\mid t{\text{ is a sink}}}} and {\displaystyle S={s\mid s{\text{ is a source}}}}{\displaystyle S={s\mid s{\text{ is a source}}}}. Add a new source {\displaystyle s{*}}s{} with an edge {\displaystyle (s{*},s)}(s{},s) from {\displaystyle s{*}}s{} to every node {\displaystyle s\in S}s\in S, with capacity {\displaystyle c(s^{},s)=d_{s};(d_{s}=\sum {(s,u)\in E}c(s,u))}c(s^{*},s)=d{s};(d_{s}=\sum {(s,u)\in E}c(s,u)). And add a new sink {\displaystyle t{*}}t{} with an edge {\displaystyle (t,t{*})}(t,t{}) from every node {\displaystyle t\in T}t\in T to {\displaystyle t{*}}t{}, with capacity {\displaystyle c(t,t^{})=d{t};(d_{t}=\sum {(v,t)\in E}c(v,t))}c(t,t^{*})=d{t};(d_{t}=\sum _{(v,t)\in E}c(v,t)). Then apply the Ford–Fulkerson algorithm.

    Also, if a node u has capacity constraint {\displaystyle d_{u}}d_{u}, we replace this node with two nodes {\displaystyle u_{\mathrm {in} },u_{\mathrm {out} }}{\displaystyle u_{\mathrm {in} },u_{\mathrm {out} }}, and an edge {\displaystyle (u_{\mathrm {in} },u_{\mathrm {out} })}{\displaystyle (u_{\mathrm {in} },u_{\mathrm {out} })}, with capacity {\displaystyle c(u_{\mathrm {in} },u_{\mathrm {out} })=d_{u}}{\displaystyle c(u_{\mathrm {in} },u_{\mathrm {out} })=d_{u}}. Then apply the Ford–Fulkerson algorithm.

    2 Complexity

    3 Integral example

    4 Non-terminating example

    5 Python implementation of Edmonds–Karp algorithm

    6 See also

  • 相关阅读:
    java面试题
    边缘计算与图像识别:实现高效实时处理的新途径
    micro-app-源码解析4-数据通信篇-终篇
    仿牌独立站如何通过PayPal.Me亲友付进行收款
    centos 安装 docker
    暑假加餐|有钱人和你想的不一样(第12天)+配电网与微电网中虑需求响应的研究【基于价格型需求响应】(Python代码实现)
    【Rust日报】2022-10-17 谷歌宣布推出 Rust 开发的 KataOS 操作系统
    尾矿库监测 GNSS北斗高精度定位终端机应用
    MCE | 丙型肝炎病毒的终结之路
    非线性方程求根方法总结——(从二分法、试位法到牛顿迭代、弦截法、二次插值等)
  • 原文地址:https://blog.csdn.net/qq_66485519/article/details/128096722