算法设计与分析(实验班)第八次作业
Assignment 8
侵删。
1 Max Flow, Min Cut, and Duality
In this exercise, we will demonstrate that LP duality can be used to show the max-flow min-cut theorem.
Consider the following instance of max flow:
Let \(f_{1}\) be the flow pushed on the path \(\{S, A, T\}, f_{2}\) be the flow pushed on the path \(\{S, A, B, T\}\), and \(f_{3}\) be the flow pushed on the path \(\{S, B, T\}\). The following is an LP for max flow in terms of the variables \(f_{1}, f_{2}, f_{3}\) :
\[\begin{aligned} \max f_{1}+f_{2}+f_{3} & \\ f_{1}+f_{2} \leqslant 7 & \text { (Constraint for }(S, A)) \\ f_{3} \leqslant 5 & \text { (Constraint for }(S, B)) \\ f_{1} \leqslant 4 & \text { (Constraint for }(A, T)) \\ f_{2} \leqslant 4 & \text { (Constraint for }(A, B)) \\ f_{2}+f_{3} \leqslant 7 & \text { (Constraint for }(B, T)) \\ f_{1}, f_{2}, f_{3} \geqslant 0 & \end{aligned} \]
(a)
Find the dual of this LP, where the variables in the dual are \(x_{e}\) for each edge \(e\) in the graph.
原线性规划为:
其对偶线性规划为
若将其视为整数线性规划,则最小化式中, \(x_i\) 表示第 \(i\) 条边是否切掉。这样,第一条约束 \(x_1 + x_3 \ge 1\) ,在该规划是整数规划时,表示在路径 \(\{S,A,T\}\) 中, \((S,A)\) 和 \((A,T)\) 中至少需要切掉一条边。
同样,第 \(2,3\) 条约束也表示在路径 \(\{S,A,B,T\}\) 与路径 \(\{S,B,T\}\) 中,至少需要切掉一条边。
(b)
Show that the dual of the LP for any max-flow problem is an LP for the corresponding min-cut problem.
因为任何有环的流去掉环一定更优,故只需考虑从 \(s\) 到 \(t\) 的不包括环的路径(即简单路径),这些路径的总数小于 \((n+1)!\) ,其中 \(n\) 为节点数,设为 \(P_1, P_2, \ldots, P_m\)。
构造矩阵 \(A\) ,其中 \(A_{ij}\) 表示路径 \(P_i\) 是否包含边 \(E_j\)。
令 \(C = (c_i)_n\), \(F = (f_i)_m\),其中 \(c_i\) 代表边 \(E_i\) 的流量上限, \(f_i\) 代表流过路径 \(P_i\) 的流量,则网络流可以化作这样的线性规划:
其对偶线性规划为:
显然,\(x_i \le 1\)。否则,若 \(x_i > 1\),则令 \(x_i = 1\) 一定更优。
若将其视为整数线性规划,则最小化式中, \(y_i\) 表示第 \(i\) 条边是否切掉。
下面证明该整数线性规划和原对偶线性规划的解是一样的:
显然,该整数线性规划的解大于等于原对偶线性规划的解。因此,只需证明该整数线性规划的解小于等于对偶线性规划的解。
这个做法假掉了。
任取原线性规划的一个最优解 \(X\),将它调整成整数解。
若 \(X\) 中没有 \(x_i \in (0,1)\),则 \(X\) 已经是整数解,无需调整。
否则,取 \(i\) 使得 \(x_i \in (0,1)\),则对每一条包含 \(E_i\) 的路径 \(P_j\),都存在 \(P_j \ni E_k \ne E_i\) 使得 \(x_k \in (0,1)\),对每一条路径,取一条这样的边,去重构成边集 \(E'\)。
必然有 \(\sum_{E_j\in E'} c(E_j) \ge c(E_i)\)。通过反证法证明:
若 \(\sum_{E_j\in E'} c(E_j) < c(E_i)\),则可以构造比最优解 \(X\) 更优的解 \(X'\),从而产生矛盾:\[x'_k = \begin{cases} x_k, & E_k \ne E_i, E_k \notin E' \\ x_k - \varepsilon, & E_k = E_i \\ x_k + \varepsilon, & E_k \in E' \end{cases} \]
其中 \(\varepsilon > 0\)。
因此,必有 \(\sum_{E_j\in E'} c(E_j) = c(E_i)\)。可以这么操作:
(这个做法参考了斯坦福大学的CS261讲义[1])
考虑线性规划的一个最优解 \(X\),将边 \(e\) 的“长度”看作 \(x_e\),求出从源点 \(s\) 到所有点 \(u \in V\) 的最短路,记为 \(d_u\)。
由线性规划的意义,知对汇点 \(t\) 有 \(d_t \ge 1\)。
令均匀随机变量 \(t\sim I(0,1)\),将点集 \(V\) 划分为两个集合 \(S, T\):
显然 \(s\in S, t\in T\),则割 \((S, T)\) 的大小为:
而对 \(e:(u,v)\in E\),
其中,由最短路的三角不等式,有
因此,
由期望 \(\mathbb E(C)\) 的定义知,存在 \(t\) 使得割 \((S,T)\) 满足 \(C \le \sum_{e:(u,v)\in E}x_e c_e\)。
因为 \(C\) 是整数线性规划的解,故得证。
另证:由网络矩阵是全幺模矩阵,可证明该整数线性规划和原线性规划的解是一样的[2]——只不过过程极其繁琐。
2 Network Flow with Vertex Capacities
Let \(G=(V, E)\) be a directed graph with a source vertex \(s \in V\) and a sink vertex \(t \in V\). Whereas the standard network flow problem involves capacities for edges, here we suppose instead that every vertex \(v \in V\) has an integer capacity \(c_{v} \geqslant 0\). A vertex-capacitated flow in \(G\) is a function \(f: E \rightarrow[0,+\infty)\) such that
- (Capacity Constraint) For each vertex \(v \in V\), we have
\[\sum_{e \text { into } v} f(e) \leqslant c_{v} \text { and } \sum_{e \text { out of } v} f(e) \leqslant c_{v} \]
- (Conservation Constraint) For each vertex \(v \in V /\{s, t\}\), we have
\[\sum_{e \text { into } v} f(e)=\sum_{e \text { out of } v} f(e) \]As usual, the value of a flow is defined as \(\sum_{e \text { out of } s} f(e)\). Give an efficient algorithm to find a maximum vertex-capacitated flow in \(G\) from \(s\) to \(t\) and analyze its running time.
把点拆成边,将原问题转化为一个普通的最大流问题。
具体地,所有原图 \(G\) 中的 \(v\in V\),都对应新图 \(G'\) 中的两个点 \(v_{in}, v_{out}\),点间连有一条容量为 \(c_v\) 的有向边 \(v_{in} \stackrel{c}{\longrightarrow} v_{out}\)。
所有原图 \(G\) 中的有向边 \((u,v) \in E\),都对应新图 \(G'\) 中的一条容量为 \(+\infty\) 的有向边 \(u_{out} \stackrel{+\infty}{\longrightarrow} v_{in}\)。
新图的源点和汇点分别为 \(s_{in}\) 与 \(t_{out}\)。
显然,新图上的最大流问题等价于原图上的点最大流问题。\(\blacksquare\)
3 Restoring the Balance!
We are given a network \(G=(V, E)\) whose edges have integer capacities \(c(e)\), and a maximum flow \(f\) from source \(s\) to sink \(t\). Explicitly, \(f\) is given to us in the representations of integer flows along every edge \(e,(f(e))\).
However, we find out that one of the capacity values of \(G\) was wrong: for edge \((u, v)\), we used \(c(u, v)\) whereas it should have been \(c(u, v)-1\). This is unfortunate because the flow \(f\) uses that particular edge at full capacity (i.e., \(f(u, v)=c(u, v)\) ). We could rerun Ford-Fulkerson (or its improved versions) from scratch, but there shall be a faster way.
Design an algorithm to fix the max-flow for this network in \(O(|V|+|E|)\) time. Please give a 3-part solution.
退流+重新运行最大流即可。
退流:只考虑流 \(\ge 1\) 的边,从点 \(s\) 跑一遍 BFS,找到一条 \(s\) 到 \(u\) 的最短路。同样,找到一条 \(v\) 到 \(t\) 的最短路。在这样一条 \(s \longrightarrow u \to v \longrightarrow t\) 的路径上,将所有边上的流减去 \(1\)。
之后,再次运行最大流算法即可。
正确性:任何非最大流的残量网络中都可以找到一条增广流,故最终能得到新图的最大流。
时间复杂度:两次 BFS 都是 \(O(|V| + |E|)\) 的。另外,因为新图的最大流 \(\le\) 原图的最大流,至多增广一次,\(O(|V| + |E|)\)。总时间复杂度 \(O(|V| + |E|)\)。
4 Feasible Routing
In this problem, we explore a question called feasible routing. Given a directed graph \(G\) with edge capacities, there are a collection of supply nodes and a collection of demand nodes. The supply nodes want to ship out flow, while the demand nodes want to receive flow. The question is whether there exists a flow that satisfies all supply and demand.
Formally, we are given a capacitated directed graph \(G=(V, E)\), and each node is associated with a demand value, \(d_{v}\). We say that \(v\) is a supply node if it has a negative demand value (i.e., flow out \(>\) flow in), and a demand node, if it has a positive demand value (i.e., flow in \(>\) flow out). A node can be neither demand or supply node, where \(d_{v}=0\). Let \(c(u, v)\) be the capacity of the directed edge \((u, v)\). Define a feasible routing as a flow that satisfies
(Capacity Constraint) For each \((u, v) \in E\), we have \(0 \leqslant f(u, v) \leqslant c(u, v)\)
(Supply and Demand Constraint) For each vertex \(v \in V\), we have
\[\sum_{e \text { into } v} f(e)-\sum_{e \text { out of } v} f(e)=d_{v} \]Note that this is a feasibility problem, and the answer is simply yes or no, whereas the max-flow is an optimization problem, where the answer is a number (max flow value).
(a)
Let \(S\) denote the supply nodes and \(T\) the demand nodes. Define the total demand as \(\sum_{u \in T} d_{u}\) and total supply as \(\sum_{u \in S}-d_{u}\). Is there a feasible routing if total demand is not equal to total supply?
没有。
证明:累和即可。
得证。\(\blacksquare\)
(b)
Provide a polynomial-time algorithm to determine whether there is a feasible routing, given the graph, edge capacities, and node demand values. Please give a 3-part solution.
NOTE: We will refer to “design an algorithm, prove its correctness and analyze the running time” as a 3-part solution.
将它转换为普通的最大流问题即可。
设计:具体来说,建立一个超级源点 \(s_0\),一个超级汇点 \(t_0\)。将它们连源点集 \(S,T\) 的点:
设原图 \(G = (V,E)\),构造新图 \(G' = (V\cup \{s_0, t_0\}, E')\),其中
在新图上,以 \(s_0\) 为源点,以 \(t_0\) 为汇点,跑一次最大流即可。
若总流量 \(F =\) 总需求 \(\sum_{u \in T} d_{u} =\) 总供给 $ \sum_{u \in S}-d_{u}$,则原问题有解。否则原问题无解。
证明:相当于证明:(1)若原问题有解,则新问题必然有解;(2)若算法给出了解,则原问题必定有解。
只需证明两个问题的方案可以相互转换即可,而这是显然的(只需加上/去掉和 \(s_0/t_0\) 相连的所有边即可)
复杂度:新图的 \(|V'| = |V| + 2 = O(|V|)\),\(|E'| = |E| + |S| + |T| \le |E| + |V|\)。复杂度为 \(O(MaxFlow(|V|, |E| + |V|))\)。
Lecture 15: Stanford University — CS261: Optimization, February 24, 2011, Luca Trevisan ↩︎
Lecture 16 (Oct 14): TUM Matrices and Network Matrices, CMPUT 675: Topics in Combinatorics and Optimization Fall 2016, Zachary Friggstad. ↩︎