MIT6 046JS15 Pset7sols
MIT6 046JS15 Pset7sols
March 0, 2015
6.046J/18.410J
Problem Set 7 Solutions
In this problem, you will design an algorithm that takes the following inputs:
A ow network F = (G, c), where G = (V, E) is a graph with source vertex s and target
vertex t, and c is a capacity function mapping each directed edge of G to a nonnegative
integer;
A maximum ow f for F ; and
A triple (u, v, r), where u and v are vertices of G and r is a nonnegative integer = c(u, v).
The algorithm should produce a maximum ow for ow network F / = (G, c/ ), where c/ is identical
to c except that c/ (u, v) = r. The algorithm should run in time O(k (V +E)), where |c(u, v)r| =
k. The algorithm should behave differently depending on whether r > c(u, v) or r < c(u, v).
(a) [4 points] Start by proving the following basic, general results about ow networks:
1. Increasing the capacity of a single edge (u, v) by 1 can result in an increase of at
most 1 in the max ow.
2. Increasing the capacity of a single edge (u, v) by a positive integer k can result in
an increase of at most k in the max ow.
3. Decreasing the capacity of a single edge (u, v) by 1 can result in a decrease of at
most 1 in the max ow.
4. Decreasing the capacity of a single edge (u, v) by a positive integer k can result
in a decrease of at most k in the max ow.
Repeat k times:
First reduce the ow on (u, v) by 1. Then, using DFS, search backwards from vertex
u, following incoming edges with positive (incoming) weight, looking for a simple
reverse path to s, t, or v. To see why such a path exists, proceed step by step from
u, each time following some incoming edge with positive (incoming) weight. Such
an edge must exist unless we have reached one of the three listed vertices, because
we started with a ow satisfying the ow conservation property. Subtract 1 from the
ows along each of the edges in this path.
If the path we found ended in v, we have already restored the ow conservation condi
tion throughout the network. Otherwise, vertex v still does not satisfy ow conserva
tion. So in this case, we use DFS again to search forwards from v, following outgoing
edges with positive (outgoing) weight, looking for a simple path to t or s. Subtract 1
from the ows along each of the edges in this path.
At this point, we have restored the ow conservation condition while reducing the
ow on (u, v) by 1. We repeat this a total of f (u, v) r times, reducing the ow on
(u, v) to r and restoring the ow conservation condition.
The result of this reduction is now a valid ow for the new network F / = (G, c/ );
however, it needs not to be maximum.
Analysis: In Phase 1, each reduction of capacity by 1 takes time O(V +E), using DFS
for the two searches. Thus, Phase 1 takes time O(k (V + E)). Phase 2 is like Part
(b), and so takes time O(k (V + E)).
Proof: As we noted, after Phase 1, we have a valid ow. Moreover, in each reduction,
we have reduced the value of the ow by at most 1. Therefore, in all, we have reduced
the value of the ow by at most k.
The value of the max ow can be anywhere between the value of the ow after Phase
1 and the value of the original max ow. The difference between these two values is
at most k, so k iterations are enough to restore the max.
Problem 7-2. Disjoint Roads [15 points]
A number k of trucking companies, c1 , . . . , ck , want to use a common road system, which is mod
eled as a directed graph, for delivering goods from source locations to a common target location.
Each trucking company ci has its own source location, modeled as a vertex si in the graph, and the
common target location is another vertex t. (All these k + 1 vertices are distinct.)
The trucking companies want to share the road system for delivering their goods, but they want
to avoid getting in each others way while driving. Thus, they want to nd k edge-disjoint paths
in the graph, one connecting each source si to the target t. We assume that there is no problem if
trucks of different companies pass through a common vertex.
Design an algorithm for the companies to use to determine k such paths, if possible, and otherwise
return impossible.
Solution: Model this as a max ow problem. Add a special source vertex s, with edges to all
the individual sources si , each with capacity 1. Also associate capacity 1 with every other edge, as
shown in the following gure:
Figure 2: Graph model for problem 7-3, in which a1 prefers b1 , a2 prefers b1 and bm ,... an prefers
b2 and bm .
Include special vertices s and t as usual. Have a rst layer of n vertices corresponding to the
customers, and a second layer of m vertices corresponding to the foods. Include an edge from
s to each customer, with capacity 1. Include an edge from customer ai to food item bj exactly if
j Ai ; this will also have capacity 1. Include an edge from food item bj to t with capacity qj .
Proof: A ow f on this network yields an assignment of food items to customers that satises the
customer and food quantity constraints. Specically, for each customer ai , if some edge f (ai , bj )
has ow 1, then assign food item bj to customer ai . Note that each customer ai can get at most one
food item, because ai has incoming ow at most 1, so its outgoing ows must also total at most
1. Since all ows are integral, only one outgoing edge can have positive ow. Also note that each
food item bj cannot be assigned to more than qj customers, because bj has outgoing ow at most
qj , so its incoming ows must also total at most qj . Thus, the food assignment arising from ow f
satises all the customer and food constraints.
Conversely, any food assignment satisfying all these constraints corresponds directly to a ow
through the network: Assign ow 1 to edge (ai , bj ) exactly if customer a1 gets assigned food item
bj . Assign ows to the edges from s and to t to achieve ow conservation.
Moreover, a max ow through this network satises the maximum number of customers, because
the denition of a max ow says that it maximizes the total ow out of s (which corresponds to
the number of customers satised).
Algorithm: So, all we need to do is run a max ow algorithm on this network, produce an integral
max ow f , and interpret it as a food assignment. The maximum number of satised customers
yields the minimum number of vouchers.
Analysis: The number of edges is E = O(mn). The max ow |f | n. Using the Ford-Fulkerson
algorithm, the time complexity is O(E|f |) = O(mn2 ).
MIT OpenCourseWare
http://ocw.mit.edu
For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.