Algorithm Design
Algorithm Design
Algorithm Design
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
404<br />
Chapter 7 Network Flow<br />
to cross from A to B, and now it does not cross from A’ to B’. But since gx~ > O,<br />
this means that (A’, B’) has smaller capacity than (A, B), again contradicting<br />
our assumption that (A, B) is a minimum cut. So, if both x and y belong to T,<br />
then Uxy ~ A.<br />
Thus we have established the following conclusion, based on the fact that<br />
(A, B) is a minimum cut: uxy ~ A if and only if both x, y ~ T.<br />
Now we just need to work out the minimum-cut capacity c(A, B) in terms<br />
of its constituent edge capacities. By the conclusion in the previous paragraph,<br />
we know that edges crossing from A to B have one of the following two forms:<br />
o edges of the form (v x, t), where x ~ T, and<br />
o edges of the form (s, Uxy), where at least one of x or y does not belong<br />
to r (in other words, {x, y} ~ r).<br />
Thus we have<br />
x~T<br />
x~T<br />
{x,y}~T<br />
x,y~T<br />
Since we know that c(A, B) = g’ < g*, this last inequality implies<br />
and hence<br />
x,y~T<br />
For example, applying the argument in the proof of (7.59) to the instance<br />
in Figure 7.21, we see that the nodes for New York and Toronto ~re on the<br />
source side of the minimum cut, and, as we saw earlier, these two teams<br />
indeed constitute a proof that Boston has been eliminated.<br />
* 7.13 A Further Direction: Adding Costs to the<br />
Matching Problem<br />
Let’s go back to the first problem we discussed in this chapter, Bipartite<br />
Matching. Perfect matchings in a bipartite graph formed a way to model the<br />
problem of pairing one kind of obiect with another--iobs with machines, for<br />
example. But in many settings, there are a large number of possible perfect<br />
matchings on the same set of objects, and we’d like a way to express the idea<br />
that some perfect matchings may be "better" than others.<br />
7.13 A Further Direction: Adding Costs to the Matching Problem<br />
~ The Problem<br />
A natural way to formulate a problem based on this notion is to introduce<br />
costs. It may be that we incur a certain cost to perform a given job on a given<br />
machine, and we’d like to match jobs with machines in a way that minimizes<br />
the total cost. Or there may be n fire trucks that must be sent to n distinct<br />
houses; each house is at a given distance from each fire station, and we’d<br />
like a matching that minimizes the average distance each truck drives to its<br />
associated house. In short, it is very useful to have an algorithm that finds a<br />
perfect matching "of minimum total cost.<br />
Formaliy, we consider a bipartite graph G = (V, E) whose- node set, as<br />
usual, is partitioned as V = X U Y so that every edge e ~ E has one end in X<br />
and the other end in Y. Furthermore, each edge e has a nonnegafive cost c e.<br />
For a matching M, we say that the cost of the matching is the total cost of a!l<br />
edges in M, that is, cost(M) = ~e~v~ Ce" The Minimum-Cost Perfect Matching<br />
Problem assumes that IXI = IYI = n, and the goal is to find a perfect matching<br />
of minimum cost.<br />
~ <strong>Design</strong>ing and Analyzing the <strong>Algorithm</strong><br />
We now describe an efficient algorithm to solve this problem, based on the<br />
idea of augmenting paths but adapted to take the costs into account. Thus, the<br />
algorithm will iteratively construct matchings using i edges, for each value of i<br />
from ! to n. We will show that when the algorithm concludes with a matching<br />
of size n, it is a minimum-cost perfect matching. The high-level structure of the<br />
algorithm is quite simple. If we have a minimum-cost matching of size i, then<br />
we seek an augmenting path to produce a matching of size i + 1; and rather<br />
than !ooking for any augmenting path (as was sufficient in the case without<br />
costs), we use the cheapest augmenting path so that the larger matching wil!<br />
also have minimum cost.<br />
Recall the construction of the residual graph used for finding augmenting<br />
paths. Let M be a matching. We add two new nodes s and t to the graph. We<br />
add edges (s, x) for all nodes x ~ X that are unmatched and edges (y, t) for all<br />
nodes y ~ Y that are unmatched. An edge e = (x, y) ~ E is oriented from x to<br />
y if e is not in the matching M and from y to x if e ~ M. We will use G M to<br />
denote this residual graph. Note that all edges going from Y to X are in the<br />
matching M, while the edges going from X to Y are not. Any directed s-t path<br />
P in the graph G M corresponds to a matching one larger than M by swapping<br />
edges along P, that is, the edges in P from X to Y are added to M and all edges<br />
in P that go from Y to X are deleted from M. As before, we will call a path P in<br />
G M an augmenting path, and we say that we augment the matching M using<br />
the path P.<br />
405