Computer Network Assignment Help
Computer Network Assignment Help
(b) Suppose that r > c(u, v). Describe your algorithm for this case in
detail, prove that it works correctly, and analyze its time complexity (in
terms of V , E , and k).
Solution: Then the max flow might increase; by Part (a) 2, it increases
by at most k. Algorithm: Regard the existing flow f as a flow in the new
flow network F / = (G, c/). Start with the residual network of F / for flow
f.
Repeat k times:
1.Look for an augmenting path in the residual network.
2.If you find one, add it to the existing flow, else return.
Analysis: Using DFS to search for an augmenting path, each pass
through the loop takes time O(V + E), so the total time is O(k · (V +
E)).
Proof: As noted, increasing the capacity of a single edge by k can
result in an increase of at most k in the value of the max flow. Each
time we find an augmenting path, it increases the flow by at least 1. So
within at most k tries, we reach the max flow.
(c) Suppose that r < c(u, v). Describe your algorithm for this case in
detail, prove that it works correctly, and analyze its time complexity.
Proof: Suppose we have any integral flow f on this graph; thus, the flow
on every edge is either 0 or 1. From f , we can obtain a collection of
disjoint paths to t from those individual sources s i such that f (s, s i ) = 1.
We can do this sequentially, one i at a time. Namely, consider any i such
that f (s, s i ) = 1. Since the flow into s i is 1, the flow out of s i is also 1, so
identify an edge (s i , u) such that f (s i , u) = 1.
Continue by identifying an edge out of u with f (u, v) = 1, and so on,
always choosing unused edges. Eventually, this must reach t, so we have
discovered a (not necessarily simple) path from s i to t. Now define a
reduced flow by changing all the flows along the discovered path, plus f (s,
si ), to 0. Repeat to identify another path, and continue until we have
exhausted all the flow from s to sources s i and identified paths from all s i .
Conversely, suppose we have a set of disjoint paths from some subset of the
individual sources to s i . Then we can define a flow on the network by
defining f (u, v) = 1 for any edge (u, v) that appears in any of the paths,
and f (u, v) = 0 for other edges.
Thus, we have an immediate correspondence between flows in the network
and sets of disjoint paths from subsets of the individual sources. A max flow
through this network yields the greatest number of paths, because the
definition of a max flow says that it maximizes the total flow out of s
(which here corresponds to the number of individual sources that have paths
to t).
Algorithm: So, to solve the problem, all we need to do is run a max flow
algorithm on the network derived from the truck problem, and interpret the
result as a set of paths. If the value of the flow is strictly less than k, we
return “impossible”.
Analysis: The max flow |f | < k. Using the Ford-Fulkerson algorithm, the
time complexity is
O(E |f |) = O(E k).
Solution: Model this as a max flow problem. Define a flow network as follows.
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 “first 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 a i to food
item bj exactly if j ∈ A i ; this will also have capacity 1. Include an edge
from food item bj to t with capacity qj .
Proof: A flow f on this network yields an assignment of food items to
customers that satisfies the customer and food quantity constraints.
Specifically, for each customer ai , if some edge f (ai , bj ) has flow 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 flow at most 1, so its
outgoing flows must also total at most
1. Since all flows are integral, only one outgoing edge can have positive
flow. Also note that each food item bj cannot be assigned to more than qj
customers, because bj has outgoing flow at most qj , so its incoming flows
must also total at most qj . Thus, the food assignment arising from flow f
satisfies all the customer and food constraints.
Conversely, any food assignment satisfying all these constraints
corresponds directly to a flow through the network: Assign flow 1 to edge
(ai , bj ) exactly if customer a1 gets assigned food item bj . Assign flows to
the edges from s and to t to achieve flow conservation.
Moreover, a max flow through this network satisfies the maximum number
of customers, because the definition of a max flow says that it maximizes
the total flow out of s (which corresponds to the number of customers
satisfied).
Algorithm: So, all we need to do is run a max flow algorithm on this
network, produce an integral max flow f , and interpret it as a food
assignment. The maximum number of satisfied customers yields the
minimum number of vouchers.
Analysis: The number of edges is E = O(mn). The max flow |f | ≤ n. Using
the Ford-Fulkerson algorithm, the time complexity is O(E|f |) = O(mn2 ).