CS4820 Problem Set 5

Liyuan Gao, lg342 March 7, 2012

Collaborators: Detian Shi and Nicholas Beaumont



Even more Ford-Fulkerson

(1a) Max-flow detection. Algorithm: We first construct a residual graph Gf of the given input G, which should take no more than O(n) time. We then do a breadth-first traversal from Gf starting at node s and terminating when all nodes have been marked or when we hit node t. If we were successful in finding an s − t path, then we output N O as G is not max-flow. Otherwise, we output Y ES Complexity: The residual graph Gf contains at most 2m edges and the same set of nodes as G, where m is the number of edges in G, and since the edges in Gf can be constructed directly from G, it will take at most O(m) time to contruct Gf . Since there are only n nodes in Gf , then breadth-fist search will take O(n) time, so the total time for the algorithm to run is O(m + n). Correctness: We refer to lemma (7.9) from the text book, which states that (7.9) If f is an s-t-flow such that there is no s-t path in the residual graph Gf , then there is an s-t cut (A∗ , B ∗ ) in G for which v(f ) = c(A∗ , B ∗ ). Consequently, f has the maximum value of any flow in G. hence, if G has no s − t path in its residual graph Gf , which is what the breadth-first search finds on termination, then by (7.9), we know that G has maximum flow. (1b) Flow improvement. Algorithm: As with above, we construct the residual graph Gf and run depth-first search on it starting at s, ending at t, and marking all of the nodes on the path from s to t. Let’s call this path P . Next, we call augment(P, f ), defined in the book as increasing the flow of the forward edges in path P in G by the bottleneck while decreasing the flow of the backward edges in path P in G by the same amount. Finally, we return the flow f that was returned from augment and terminate.


Complexity: Since the first two steps are nearly identical to that of (1a), we know that they take O(m + n) collectively. Augment first calls bottleneck, which takes O(m) time to go through all of the edges on P and find the bottleneck, which takes O(m) time, and finally the for-loop goes through each of the O(m) edges of P again and updates their corresponding entry in f (e), which takes constant time. Hence the final runtime is again O(m + n). Correctness What we have done is essentially perform the first step of Ford-Fulkerson. By the converse of (7.9), we know that since our flow f isn’t maximal, then there must be at least one s − t path in the residual graph Gf . Once we find this path P , we can then show, using lemma (7.3) from the book, that f is more maximal than f , or that v(f ) > v(f ). (7.3) Let f be a flow in G, and let P be a simple s-t path in Gf , then v(f ) = v(f ) + bottleneck(P, f ); and since bottleneck(P, f ) > 0, we have v(f ) > v(f ). Hence, the f returned by our algorithm will always be more optimal than f.



Doctors Without Weekends (again)

(7.19a) [Optional] No-slack bipartite matching Let’s consider the following arrangement AB 1 2 1 1 1 2 3 1 Which gives us the following bipartite 3 4 5 1 1 1 1 1 1 graph Days Doctors 1 1 s 2 3 3 4 5 t 2

Where the capacity for each of the edges coming out of s is the number of days that the doctor has agreed to work with, or |Li |, and the capacity for each of the edge going into t is pi . This then gives us a very natural algorithm to find a good scheduling of the doctors by finding the maximum flow of the above graph G, and if the capacity of the pi edges are not saturated, then we report that there is no set of lists that satisfies our criterions. (7.19b) Scheduling with slacks We can now very naturally extend off of the algorithm presented for (7.19a) by making the following observation: • Each doctor may potentially be called up anyday if his original schedule was too restrictive in order to fill in the quota. 4

• Each doctor may not be schedule more than c days outside of his preferred days. • In (7.19a), the edge capacity of the Doctor → Days are all ones, hence the only reason that such an edge e will ever have no flow is if its destination day is already at full capacity. Similarly, the only reason that a pi edge is not completely filled is because not enough edges are inbound to that day. Hence, if we were to create a second graph with c units of supply sources with connections of every edge not in L, and the sinks have demand pi − f (ei ), where f (ei ) is the amount of personels satisfied by the schedule in (7.19a), then no matter how the graph looks in (7.19a), this graph will always be the same. From this we can come up with another graph G2 , a bipartite matching required to fill in the residual days, that looks something like this. AB 1 2 1 1 2 1 3 1 3 4 1 1 5 1

And we can again construct a bipartite flow graph with the source supplying c days of supply and the sinks demanding pi − f (ei ) more doctors

Days Doctors 1 1 s 2 3 3 4 5 t 2


From the above observations, we can generate our algorithm as follows. Algorithm: We first construct the vertices for each doctor and each day and add in edges connecting doctors with the days that they can work in Li , each with an edge capacity of 1. We then create a new vertex s and add in an edge between s and each doctor with an edge capacity of |Li |, that is the number of days that each doctor is willing to work. Furthermore, we add in edges from the days to another vertex t with an edge capacity of pi . We then find the maximal flow of this graph, and if any of the pi edges are not saturated, we need to generate the compensation Li sets. Next, we derive a second graph G2 with the same set of vertices, and build another bipartite matching between the doctors and the days without any of the edges in Li with each edge having a capacity of 1. The key difference from the original graph is that each of the out-edge from s has a capacity of c while each of the in-edge of t has a capacity of the residual pi from the last graph, that is pi − fG (pi ). We then find the maximal flow of G2 and if the flow has a value equaling to the sum of the residual pi s, then we return the union of the two edge sets, otherwise we report that it’s impossible. Complexity: Since there are O(nk) elements in the incidence table, it takes O(nk) time to construct the graph G. We then run Ford-Fulkerson on G, which takes O(nk i pi ). Furthermore, an additional O(nk) time is required to construct the second graph G2 , which also has O(nk) elements in its incidence table and O( i pi ) iterations in the Ford-Fulkerson algorithm, so the overall runtime is still just O(nk i pi ). Proof of Correctness: Lemma 2.1 An edge in the maximum flow bipartite matching of G between the doctors and the edges will only be unmatched if its destination day is already saturated. Let’s assume that the destination day is not saturated, then if we match the currect doctor with that day, then that day’s output flow will have increased, meaning that the original flow wasn’t a maximum flow, a contradiction. Lemma 2.2 A day can only be unsaturated in the maximal flow of G if there aren’t enough input edges to that day, or there aren’t enough doctors willing to work on that day. 6

Since the total number of edges between the doctors and the days is the maximum possible flow of G as the s-t cut between the days and the doctor has a total capacity of the number of edges in the original graph, and since the source doctors can saturate all of those edges, then the only times when a day’s outgoing pi isn’t saturated is when there aren’t enough edges coming into that day. From the above observations, we can see that the maximum flow basically checks to see if there are enough in-edges to each day if there are, to mark some arbitrary set of them of length pi with equal probability in order to saturate the outgoing pi . Hence, any maximum flow will generate a subset of the Li s such that there are exactly pi doctors working on day i as long as the flow on the edge with capacity pi is saturated. Lemma 2.3 The second maximal flow graph returns a valid assignment of the doctors on the remaining days that they are not ”willing” to work on, but are not completely unacceptable. Since the main edges in G2 are still binary, each of the pi , where pi is the ¯ ¯ residual days left, flow are still determined by how many incoming edges there are into day i. Since each doctor now supplies c units of flow, and the remaining days to be filled, pi , are the demands of the days, then a ¯ maximal flow will by the same observations as above attempt to saturate all of the demands. However, we limit the amount of extra days each doctor can work additionaly by only c possible edges (again, units of flow are equivalent to number of edges saturated by above observation). This then satisfies the property that all of the remaining days are assigned if possible, and that each doctor cannot put in more than c extra days. Lemma 2.4 The union L = LG LG 2 , where LG is the set of Li found in the first part of the algorithm in G, and LG 2 is the set of Li found in G2 , satisfies the condition that Lj contains at most c days that do not appear on the list Lj First we make the observation that only when a doctor will work on day i will that edge have flow in any of the maximal flow. We then contend that none of the c days will be used in the first algorithm, as it only matches doctors to days that he/she is willing to work on, hence no matches not on Lj can ever be made and none of the c ’slack’ days will ever be used. Next, we see that the maximal flow in the second graph can at the very most make c matchings for each doctor since that’s the amount of supply each source doctor can push out. Since the number of matchings corresponds to the number of days that this doctor will have to work extra, 7

we then have an upperbound c on the extra days that each doctor can be made to work. Lemma 2.5 The union L = LG LG 2 satisfies the condition that exactly p(i) doctors are present on day i. From the above, we see that LG is the maximal set of docotors matched to their willing days, and LG 2 is the set of extra doctors required to fill in the remaining days, then the union of these two is obviously the set of doctors needed to fill in exactly p(i) doctors on day i as long as the sink days are all saturated. Lemma 2.6 The algorithm correctly returns when no matching can be found. The only way that a matching cannot be made is, from (2.2), when there aren’t enough input edges into that day. From (2.1) and (2.2), the only unsaturated edges returned from a maximal flow of G are those that leads into days that are already at full capacity. Since these edges couldn’t have made an impact anyhow, their lack of appearance in G2 doesn’t impact the ability of the algorithm to predict whether there can be matchings made. In G2 , a maximal flow will have to saturate the sinks unless one of two cases happen: 1. Some of the sink edges have higher capacity than the input edges to the sinks, or there exists a day such that demands more doctors than there exists. 2. The total supply is less than what can satisfy the demand, of there are not enough doctor-days to satisfy the total demand for each day These are precisely the only cases for which there can be no way of scheduling the doctors, hence if the maximal flow in G2 have unsaturated sinks, we can correctly say that there are no valid scheduling.



Evacuation plan for Algoropolis

(3a) Design an algorithm to create an evacuation plan. Algorithm: Let d = i=0,n j=0,n p(i, j), or the total population living in Algoropolis. We first take each of the neighborhood xij in Algoropolis and add it into the graph G and add two edges between each of the adjacent vertices. Let S = i=0,n j=0,n xij and T = i=0,n j=0,n xij such that S is the set of nodes that contain people and T is the set of bordering nodes that all the people must be evacuated to. Next, we create a new vertex s∗ , and for each node xij in S, add an edge from s∗ to xij with an edge capacity of p(i, j). We then create another vertex t∗ and for each yij in T , we add an edge from yij to t∗ with an edge capacity of c. ¯ Finally, we find the maximum flow f on G using Ford-Fulkerson and if ¯ v(f ) = d, then we know that the flow of the people evacuating the city contains everyone, and hence we can output the flow associated with each ¯ edge. However, if v(f ) < d, then we know that not all people made it out of the city, and hence we report that it’s impossible to evacuate the city. Complexity: There are roughly O(n2 ) nodes and edges to consider in the construction of the graph on top of another O(n2 ) edges to consider in the construction of the supply s∗ edges and a further O(n) border edges outgoing to t∗ . Finally, since the maximum edge capacity is c and the Ford-Fulkerson terminates in ¯ ¯ roughtly O(v(f )) time, then the upperbound on v(f ) is O(cn), which gives a time complexity for the Ford-Fulkerson algorithm to run in O(cn3 ) as there are O(n2 ) edges and O(cn) iterations of augment that runs linear to the number of edges. So totally, the algorithm takes roughly O(cn3 ) to run. Proof of Correctness: This algorithm is very similar to a circulation with demand problem. A key point to note here is that there can never be a s ∗ −t∗ flow with value greater than d, as the (A, B) cut with A = s∗ has edge capacity of d. In order to fully evacuate the entire city, we need to send out all d people in the city, that is we need to achieve a flow of value equaling to d. Since the maximum flow value of G is already d as established above, we then can ¯ contend that a maximum flow f must have a value of d if all d people in the city are to be able to be evacuated, and the associated flow value in each 9

street is one feasible evacuation plan. However, if the maximum flow is less than d, then we know that there are source neighborhoods that cannot send out all of its people, and hence it’s immposible to evacuate everyone. (3b) Showing the correctness of HOT SP OT .


Sign up to vote on this title
UsefulNot useful