lgorithms and ata tructures 0 xercises and s Week Linear programming. onsider the following linear program. maximize x y 0 x + y 7 x x 0 y 0 x + 3y Plot the feasible region and identify the optimal solution. Just for checking: x = and y =.. cargo plane can carry a maximum weight of 00 tons and a maximum olume of 0 cubic meters. here are three materials to be transported, and the cargo company may choose to carry any amount of each, upto the maximum aailable limits gien below. Material has density tons/cubic meter, maximum aailable amount 0 cubic meters, and reenue e.000 per cubic meter. Material has density tons/cubic meter, maximum aailable amount 30 cubic meters, and reenue e.00 per cubic meter. Material 3 has density 3 tons/cubic meter, maximum aailable amount 0 cubic meters, and reenue e.000 per cubic meter. Write a linear program that optimizes reenue within the constraints. We introduce ariables,, and 3 representing the olumes of the respectie materials. he requested linear program is then gien by maximize 000 + 00 + 000 3 + + 3 3 00 + + 3 0 0 30 3 0,, 3 0. 3. You are gien the following points (x i, y i ) in the plane: (, 3), (, ), (3, 7), (, ), (7, ), (8, ), (0, 9). uppose you want to determine a line ax + by = c that approximately passes through these points (it might not contain all the points). Write a linear program to find a line that minimizes the maximum absolute error, being max ax i + by i c 0<i 7
We introduce a ariable z to replace the formula max 0<i 7 ax i + by i c. It remains to constrain z such that z = max 0<i 7 ax i + by i c. ince we are minimizing z, it is sufficient to hae z max 0<i 7 ax i + by i c, which is equialent to the requirements z ax i + by i c for 0 < i 7. o get rid of the absolute alues, we split each of those requirements into z ax i + by i c and z ax i by i + c. Note that because z is greater than certain absolute alues, we can add the restriction z 0 without affecting the solution. In standard form, the linear program is gien by maximize z z + x i a + y i b c 0 0<i 7 z + x i a + y i b c 0 0<i 7 a, b, c, z 0.. he following figure shows a graph with four nodes on the left representing boys and four nodes on the right representing girls. here is an edge between a boy and girl if they like each other (for instance, l likes all the girls). his kind of graph, in which the nodes can be partitioned into two groups such that all edges are between the groups, is called bipartite. Is it possible to choose couples so that eeryone has exactly one partner? In graph-theoretic jargon, is there a perfect matching? Write a linear program that soles the matching problem. We turn the graph into a directed graph, choosing to direct the edges towards the girls. urthermore, we add nodes s and t to the graph with for eery boy an edge from s to that boy and for eery girl an edge from that girl to t. or all nodes i and j, we hae a constant c ij that is 0 if there is no edge and if there is an edge from i to j. inally, we introduce ariables f ij for all nodes i and j. he problem has turned into a maximum flow problem (after soling it as such, we simply check if the size of the flow equals the number of boys), where s is the source node, t the sink node, c the capacities and f the flow. hus, the problem can be modelled by a linear program as explained during the lecture.. In the last lecture, we saw the single-source-single-target shortest path problem being formulated as a linear maximization problem. lternatiely, one can derie the following dual minimization ariant: minimize x u w(u, ) (u,) Here, x u = if the edge (u, ) is part of the shortest path, and x u = 0, otherwise. Write down the corresponding constraints. he constraints are x s x s = x t x t =
and, for all w / {s, t}, x w x w = 0. Here s is the source node and t is the target node. o make this a linear problem, we need to replace the assertion x u {0, } for all u and by x u 0. Note that there may now be solutions with non-integer alues for some x u. his means that the flow is diided oer multiple paths between certain nodes, but because of the minimization it can only be diided if these paths hae the same length. hus, any path along which all x u are nonzero will be a shortest path.. onert the following linear program into standard form: minimize x + 7x + x 3 x x 3 = 7 3x + x x 0 x 3 0 We first switch from minimization to maximization by multiplying the objectie function by. Now obsere that x has no nonnegatiity constraint, so we replace it by x x. he same goes for x 3, but we can exploit the x 3 0 constraint to simply replace x 3 by x 3. Now we replace the equality constraint. maximize x + x 7x + x 3 x x + x 3 = 7 3x 3x + x x, x, x, x 3 0 maximize x + x 7x + x 3 x x + x 3 7 x x + x 3 7 3x 3x + x x, x, x, x 3 0 inally, we fix the constraints with opposite signs. maximize x + x 7x + x 3 x + x x 3 7 x x + x 3 7 3x + 3x x x, x, x, x 3 0 7. onert the following linear program into slack form: maximize x x 3 x + x x 3 7 3x x 8 x + x + x 3 0 x, x, x 3 0
What are the basic and nonbasic ariables? irst we conert to standard form. maximize x x 3 x + x x 3 7 3x + x 8 x x x 3 0 x, x, x 3 0 Now we introduce slack ariables x, x, and x and display the program in slack form. z = x x 3 x = 7 x x + x 3 x = 8 + 3x x x = x + x + x 3 hose are the basic ariables. he nonbasic ariables are x, x, and x 3. 8. ole the following linear program using IMPLX maximize 8x +.x x + x 0 x x x, x 0 We first conert to slack form. z = 8x +.x x 3 = 0 x x x = x x = x he ariable x has a positie coefficient in the objectie function. With respect to x, the second constraint is the most restrictie. hus, we substitute x using x = x. z = +.x 8x x 3 = 8 x + x x = x x = x he ariable x has a positie coefficient in the new objectie function, and now the first constraint is the most restrictie. We replace it by x = 8 x 3 + x and substitute x eerywhere else. z = 3.x 3.x x = 8 x 3 + x x = x x = 8 + x 3 x Now all coefficients are negatie, so the basic solution, with x = and x = 8, is optimal.
9. or the following network, with edge capacities as shown, find the maximum flow from to, along with a matching cut. 0 0 0 cut partitions the ertices of a graph into two disjoint subsets, say L and R. he capacity of a cut is the total capacity of the edges from L to R. cut is said to match a flow if the size of the flow is equal to the capacity of the cut. follows. ending a flow of oer the path (,,,, ), the residual graph is as 0 0 8 0 possible choice of the rest of the paths is shown below, along with the additional flow each path admits and the final residual graph that results from all this. Path low (,,,,, ) (,,,, ) (,,, ) (,,,,, ) ogether, the size of the flow is 3. matching cut can be found by taking for L the nodes that in the final residual graph can be reached from, i.e., L = {,, }. 9 3