Algorithms Demands and Bounds Demands and Bounds Design and Analysis of Algorithms Andrei Bulato
Algorithms Demands and Bounds 1- Demands In our flow network model there is only 1 source and sink Can we do something for seeral sources and sinks? More general: Eery ertex has a demand If demand is positie, the ertex requires that the amount of flow entering the ertex is greater than the outgoing flow If demand is negatie, it requires that the amount of outgoing flow is greater. It proides supply. d -3 3 3-3 4
Algorithms Demands and Bounds 1-3 Circulation with Demands Let S be the set of nodes with negatie demand (sources) Let T be the set of nodes with positie demand (sinks) A circulation with demands { d } is a function f that assigns a nonnegatie real numbers to each arc: (Capacity condition) For each e E we hae 0 f ( e) c e in out (Demand condition) For each V, we hae, f ( ) f ( ) = d -3-3 3 3 1 4 The Circulation with Demands Problem Instance: A digraph G, capacities and demands Objectie: Does there exist a circulation satisfying the Capacity and Demand conditions
Algorithms Demands and Bounds 1-4 Sum of Demands Lemma If there exists a feasible circulation with demands { d } then d = 0 V Proof Suppose f is a feasible circulation Then V d = f ( ) f ( ) V in In this expression the alue f(e) for each e E counted exactly twice, once positiely, and once negatiely. Thus the sum equals 0 out
Algorithms Demands and Bounds 1-5 Flow from Circulation and Back The idea is to add new source and sink Let D = T d = d S G s d u u S G T d t Lemma There is a feasible circulation with demands { d } in G if and only if the maximum flow in G has alue D. If all capacities and demands are integers and there is a feasible circulation then there is an integer feasible circulation
Algorithms Demands and Bounds 1-6 Flow s. Circulation Proof Obsere that the alue of any flow in G does no exceed D, for D is the capacity of the cut that isolates the source s If a feasible circulation in G exists we extend it by assigning the alue d u to eery edge (s,u), u S, and the alue du to eery edge (u,t), u T. The obtained function is a flow, and its alue is D. Suppose there is a flow of alue D in G. Eery edge out of s, and eery edge into t must be completely saturated with this flow. If we remoe these edges we obtain a circulation f in G with in out f ( ) f ( ) = d QED
Algorithms Demands and Bounds 1-7 Lower Bounds The problem can be generalized further Sometimes we need to hae some flow through certain arcs We consider a flow network with (i) capacities (ii) demands c e d (iii) lower bounds -3-3 3 3 4 l e, 0 l e c e A circulation f is feasible if (Capacity condition) For each e E we hae l f ( e) (Demand condition) For eery V we hae e c e in out f ( ) f ( ) = d
Algorithms Demands and Bounds 1-8 Eliminating Lower Bounds We reduce the problem to one without lower bounds Start with a flow that just satisfies the lower bound, i.e. We hae L = f 0 in out 0 ( ) f0 ( ) If L = then we are done f le Otherwise we need to add another flow such that f d in out 1 ( ) f1 ( ) = d L = e e into e out of f 1 l f e) = 0 ( l e This should be done in a network with capacities ce l e and demands d L
Algorithms Demands and Bounds 1-9 Eliminating Lower Bounds Let G be a flow network with capacities { c e }, demands { d }, and lower bounds { l e } Construct G by replacing capacities with ce l e replacing demands with d and remoing lower bounds L -3-1 3 3 1 3-3 -5 4 4
Algorithms Demands and Bounds 1-10 Satisfying Lower Bounds Theorem There is a feasible circulation in G if and only if there is a feasible circulation in G. If all demands, capacities, and lower bounds in G are integers, and there is a feasible circulation, then there is a feasible circulation that is integer alued. in Proof Suppose there is a circulation f in G. Define circulation in G by f ( e) = f '( e) + l e Then f satisfies the capacity condition in G, and out f ( ) f ( ) = ( l + f '( e)) ( l + f '( e)) = L + ( d L ) = e into e e e out of so it satisfies the demand condition as well. d
Algorithms Demands and Bounds 1-11 Satisfying Lower Bounds Proof (cntd) Suppose there is a circulation f in G. Define circulation in G by f '( e) = f ( e) Then f satisfies the capacity condition in G, and l e ( f ') in ( ) ( f ') out ( ) = ( f ( e) l ) e e into e out of so it satisfies the demand condition as well. ( f ( e) l e ) = d L QED
Algorithms Airline Scheduling Airline Scheduling Design and Analysis of Algorithms Andrei Bulato
Algorithms Airline Scheduling 11-13 The Problem An airline carrier wants to sere certain set of flights Example: Boston (6 am) - Washington DC (7 am), San Francisco (:15pm) - Seattle (3:15pm) Philadelphia (7 am) - Pittsburg (8 am), Las Vegas (5 pm) - Seattle (6 pm) Washington DC (8 am) Los Angeles (11 am) Philadelphia (11 am) - San Francisco ( pm) The same plane can be used for flight i and for flight j if - the destination of i is the same as origin of j and there is enough time for maintenance (say, 1 hour) - a flight can be added in between that gets the plane from the destination of i to the origin of j with adequate time in between
Algorithms Airline Scheduling 11-14 Formalism Boston (6 am) - Washington DC (7 am), Philadelphia (11 am) - San Francisco ( pm) Philadelphia (7 am) - Pittsburg (8 am), San Francisco (:15pm) - Seattle (3:15pm) Washington DC (8 am) Los Angeles (11 am), Las Vegas (5 pm) - Seattle (6 pm) BOS 6 DC 7 DC 8 LAX 11 LAS 5 SEA 6 PHL 7 PIT 8 PHL 11 SFO SFO :15 SEA 3:15 Flight j is reachable from flight i if it is possible to use the same plane for flight i, and then later for flight j as well. (or we can use a different set of rules, it does not matter)
Algorithms Airline Scheduling 11-15 The Problem The Airline Scheduling Problem Instance: A set of flights to sere, and a set of pairs of reachable flights, the allowed number k of planes Objectie: Is it possible to sere the required flights with k planes
Algorithms Airline Scheduling 11-16 The Idea Each airplane is represented by a unit of flow The required flights (arcs) hae lower bound 1, and capacity 1 If ( u i, i ) and ( u j, j ) are arcs representing required flights i and j, and j is reachable from i, then there is an arc connecting i to u j ; we assign this arc capacity 1 Extend the network by adding an external source and sink BOS 6 DC 7 DC 8 LAX 11 LAS 5 SEA 6 PHL 7 PIT 8 PHL 11 SFO SFO :15 SEA 3:15
Algorithms Airline Scheduling 11-17 Construction - For each required flight i, the graph G has two nodes and - G also has a distinct source s and a sink t - For each i, there is an arc ( u i, i ) with a lower bound 1 and capacity 1 - For each i and j such that flight j is reachable from flight i, there is an arc ( i, u j ) with a lower bound 0 and a capacity 1 - For each i there is an arc ( s, ui ) with a lower bound 0 and a capacity 1 - For each i there is an arc ( i, t) with a lower bound 0 and a capacity 1 - There is an arc (s,t) with lower bound 0 and capacity k - The node s has demand -k, and node t has demand k u i i
Algorithms Airline Scheduling 11-18 The Problem Theorem There is a way to perform all flights using at most k planes if and only if there is a feasible circulation in the network G. Proof DIY