Presentation is loading. Please wait.

Presentation is loading. Please wait.

MS&E 211 Lecture 5: Basic Feasible Solutions; Shortest Paths Ashish Goel.

Similar presentations


Presentation on theme: "MS&E 211 Lecture 5: Basic Feasible Solutions; Shortest Paths Ashish Goel."— Presentation transcript:

1 MS&E 211 Lecture 5: Basic Feasible Solutions; Shortest Paths Ashish Goel

2 The Knapsack problem

3 A thief wants to rob a warehouse, but only has a small knapsack to carry her loot back. What should she carry? – The warehouse has many goods, all divisible, so she can take 50% of a good (for example) and sell it for 50% of the total value. Examples: gold dust, diamonds, sugar, oil, cash – The knapsack has a limited capacity for the amount of weight, but not for the amount of volume – The thief wants to maximize her profit The thief asks you, the optimization expert, to help her figure out what goods to carry

4 Modeling: Step 1a Name the quantities that are given to you as part of the problem. i.e. the parameters W: The capacity of the knapsack N: The number of goods v i : The value of the i-th good w i : The weight of the i-th good

5 Modeling: Step 1b Name the quantities that you are free to choose, i.e., the decision variables x i : The fraction of the i-th good carried away by the thief

6 Define your goal; i.e. what is your objective in solving the problem First in English: Maximize the total value of the goods the thief can carry away Then in Math, to obtain your objective Function Maximize Σ v i x i Modeling: Step 2a N i=1

7 Then, define the restrictions placed on you by the problem, i.e. the constraints You can not carry more of a good than you have available You can not carry more total weight than the knapsack capacity You can not carry negative amounts of any good Modeling: Step 2b For all i, 1 ≤ i ≤ N: x i ≥ 0 For all i, 1 ≤ I ≤ N: x i ≤ 1 Σ w i x i ≤ W N i=1

8 Then, define the restrictions placed on you by the problem, i.e. the constraints You can not carry more of a good than you have available You can not carry more total weight than the knapsack capacity You can not carry negative amounts of any good Modeling: Step 2b For all i, 1 ≤ i ≤ N: x i ≥ 0 For all i, 1 ≤ I ≤ N: x i ≤ 1 Σ w i x i ≤ W N i=1

9 Then, define the restrictions placed on you by the problem, i.e. the constraints You can not carry more of a good than you have available You can not carry more total weight than the knapsack capacity You can not carry negative amounts of any good Modeling: Step 2b For all i, 1 ≤ i ≤ N: x i ≥ 0 For all i, 1 ≤ i ≤ N: x i ≤ 1 Σ w i x i ≤ W N i=1

10 Then, define the restrictions placed on you by the problem, i.e. the constraints You can not carry more of a good than you have available You can not carry more total weight than the knapsack capacity You can not carry negative amounts of any good Modeling: Step 2b For all i, 1 ≤ i ≤ N: x i ≥ 0 For all i, 1 ≤ i ≤ N: x i ≤ 1 Σ w i x i ≤ W N i=1

11 Then, define the restrictions placed on you by the problem, i.e. the constraints You can not carry more of a good than you have available You can not carry more total weight than the knapsack capacity You can not carry negative amounts of any good Modeling: Step 2b For all i, 1 ≤ i ≤ N: x i ≥ 0 For all i, 1 ≤ i ≤ N: x i ≤ 1 Σ w i x i ≤ W N i=1

12 Then, define the restrictions placed on you by the problem, i.e. the constraints You can not carry more of a good than you have available You can not carry more total weight than the knapsack capacity You can not carry negative amounts of any good Modeling: Step 2b For all i, 1 ≤ i ≤ N: x i ≥ 0 For all i, 1 ≤ i ≤ N: x i ≤ 1 Σ w i x i ≤ W N i=1

13 Putting it all together The end result of modeling: A mathematical statement of the knapsack problem. subject to: Maximize Σ v i x i N i=1 For all i, 1 ≤ i ≤ N: x i ≤ 1 Σ w i x i ≤ W N i=1 For all i, 1 ≤ i ≤ N: x i ≥ 0

14 Putting it all together The end result of modeling: A mathematical statement of the knapsack problem. subject to: Maximize Σ v i x i N i=1 Σ w i x i ≤ W N i=1 ( i): x i ≤ 1 ( i): x i ≥ 0

15 An Instance An instance of a problem is where we actually give values to all the parameters. Example: – Three goods: gold, diamond dust, and silver. – Weights: (2, 3, 4) and Values: (5, 20, 3), respectively. – Knapsack capacity: 4 Maximize5x 1 + 20x 2 + 3x 3 Subject to: 2x 1 + 3x 2 + 4x 3 ≤ 4 x 1 ≤ 1 x 2 ≤ 1 x 3 ≤ 1 x 1, x 2, x 3 ≥ 0

16 The Knapsack Instance – Optimal solution: x 1 = 0.5, x 2 = 1.0, x 3 = 0 Only one fractional value. Will this always be true? Three decision variables, hence need three linearly independent “binding” or “tight” constraints. N decision variables: need N linearly independent binding constrains => At most one fractional variable in a bfs Maximize5x 1 + 20x 2 + 3x 3 Subject to: 2x 1 + 3x 2 + 4x 3 ≤ 4 x 1 ≥ 0 x 1 ≤ 1 x 2 ≥ 0 x 2 ≤ 1 x 3 ≥ 0 x 3 ≤ 1

17 The Knapsack Instance – Optimal solution: x 1 = 0.5, x 2 = 1.0, x 3 = 0 Only one fractional value. Will this always be true? Three decision variables, hence need three linearly independent “binding” or “tight” constraints. N decision variables: need N linearly independent binding constrains => At most one fractional variable in a bfs Maximize5x 1 + 20x 2 + 3x 3 Subject to: 2x 1 + 3x 2 + 4x 3 ≤ 4 x 1 ≥ 0 x 1 ≤ 1 x 2 ≥ 0 x 2 ≤ 1 x 3 ≥ 0 x 3 ≤ 1

18 BFS and LP Solvers The Simplex method returns a BFS when possible Most (all?) modern LP solvers return a BFS when possible by default Hence, if you solve the knapsack problem using Excel, or pretty much any modern LP solver, you will get at most one fractional decision variable in the optimum solution

19 Example: Matching Marry every man to exactly one woman, and vice-versa, while maximizing compatibility C i,j : Compatibility of man i with woman j x i,j : Decision variable indicating whether man i and woman j are married (perhaps fractionally) COMPATIBILTYHelenGloriaIris Dave100.5 Eddy0.7521 Frank0.52.51.5

20 Example: Matching

21 One optimum solution: x 11 = x 22 = x 33 = 1, everything else 0 Another: x 11 = x 23 = x 32 = 1, everything else 0 A third: x 11 = 1, = x 22 = x 33 = x 23 = x 32 = 0.5, everything else 0 COMPATIBILTYHelenGloriaIris Dave100.5 Eddy0.7521 Frank0.52.51.5

22 Example: Matching One optimum solution: x 11 = x 22 = x 33 = 1, everything else 0 Another: x 11 = x 23 = x 32 = 1, everything else 0 A third: x 11 = 1, = x 22 = x 33 = x 23 = x 32 = 0.5, everything else 0 COMPATIBILTYHelenGloriaIris Dave100.5 Eddy0.7521 Frank0.52.51.5

23 Example: Matching One optimum solution: x 11 = x 22 = x 33 = 1, everything else 0 Another: x 11 = x 23 = x 32 = 1, everything else 0 A third: x 11 = 1, = x 22 = x 33 = x 23 = x 32 = 0.5, everything else 0 COMPATIBILTYHelenGloriaIris Dave100.5 Eddy0.7521 Frank0.52.51.5

24 Example: Matching One optimum solution: x 11 = x 22 = x 33 = 1, everything else 0 Another: x 11 = x 23 = x 32 = 1, everything else 0 A third: x 11 = 1, = x 22 = x 33 = x 23 = x 32 = 0.5, everything else 0 COMPATIBILTYHelenGloriaIris Dave100.5 Eddy0.7521 Frank0.52.51.5

25 Exercise Which of the three optimum solutions x 11 = x 22 = x 33 = 1, everything else 0 x 11 = x 23 = x 32 = 1, everything else 0 x 11 = 1, x 22 = x 33 = x 23 = x 32 = 0.5, everything else 0 can not be a basic feasible solution?

26 Example: Matchings In this example, every basic feasible solution is integral In general, for the problem of finding a perfect matching, every basic feasible solution is integral, and the polytope is bounded => Excel will always return an integer solution as long as you solve the problem as an LP

27 The Shortest Path problem

28 6 2 4 s t p q r 1 2 3 4

29 Shortest Path Problem Find the shortest path from s to t – Using linear programs Many direct applications – Web applications to compute routes Indirect applications – Currency arbitrage – Most reliable path Beautiful structure: BFSs, duality Generalizes to Min-cost Flows

30 Notation Given a directed graph G – V = Set of nodes in the graph, eg. {s, p, q, r, t} – N = Number of nodes, eg. N = 5 6 2 4 s t p q r 1 2 3 4

31 Notation Given a directed graph G – E = Set of edges, eg. {(s,p), (p,s), (s,q), (q,s),(p,t), (q,r), (r,t)} – M = Number of edges, eg. M = 7 6 2 4 s t p q r 1 2 3 4

32 Notation Given a directed graph G – c(u,v) = Cost of edge from u to v, eg. c(s,p) = 4, whereas c(s,t) is undefined 6 2 4 s t p q r 1 2 3 4

33 Notation Given a directed graph G – Assume that s is the “start” and t the “terminating point” of the path we want to find 6 2 4 s t p q r 1 2 3 4

34 6 2 4 s t p q r 1 2 3 4 Notation Given a directed graph G – Assume that “s” is the start and t the “terminating point” of the path we want to find G, V, E, N, M, c, s, t are all just a convention; we will use other symbols where necessary G, V, E, N, M, c, s, t are all just a convention; we will use other symbols where necessary

35 Linear Program? Decision Variables? – A variable for every path? s t Number of s-t paths in this graph = 70 Number of s-t paths in 10 X 10 grid = 184,756 In 20 X 20 grid = 137,846,528,820

36 Linear Program? Decision Variables? – A variable for every edge x(u,v): The amount of edge (u,v) used in the path, perhaps fractionally x(u,v) = 1 : The edge is used on the path x(u,v) = 0 : The edge is not used x(u,v) = ½ : The edge is used half the time x(u,v): Leave u, enter v

37 Solution for Example x(s,q) = x(q,r) = x(r,t) = 1; all other x’s are 0 6 2 4 s t p q r 1 2 3 4

38 Constraints x(u,v) ≥ 0 x(u,v) ≤ 1 If you enter a vertex other than s or t, you must leave it You must leave s once You must enter t once

39 Constraints x(u,v) ≥ 0 x(u,v) ≤ 1 If you enter a vertex other than s or t, you must leave it exactly as much as you enter it You must leave s once more than you enter it You must enter t once more than you leave it

40 A Useful Mnemonic We will employ the following useful shorthand notation for the number of times we leave a node u in solution x: OUT x (u) = Sum of x(u,v) for all edges (u,v) We will use the following useful shorthand notation for the number of times we enter a node u in solution x: IN x (u) = Sum of x(v,u) for all edges (v,u)

41 6 2 4 s t p q r 1 2 3 4

42 The Linear Program

43 Insights into The Shortest Path LP

44 Uniqueness? Must there always exist a unique shortest path? 6 2 4 s t p q r 1 2 3 4

45 Existence? Must there always exist a shortest path? 6 2 4 s t p q r 1 2 3 4

46 Properties of the Solution Which of the following is true? 1.There can not be a feasible solution which has a positive value for any variable x(v,s). 2.There can not be a feasible solution which has a value of zero for all variables x(v,s). 3.There can not be a feasible solution which has a value of zero for all variables x(v,t). 4.There can not be a feasible solution which has a positive value for any x(t,v).

47 Another Useful Mnemonic d(u) = “Demand” of node u, i.e., how many more times must we enter node u compared to how many times we leave it d(t) = +1 d(s) = -1 d(u) = 0 for all other nodes u

48 The Linear Program

49 Even Simpler We don’t need the x ≤ 1 constraint M decision variables, one for each edge N constraints (other than x ≥ 0), one for each node – Called “conservation constraints” since they conserve movement into and out of a node, except for the source and the terminus

50 Negative Cycles We saw that the shortest path problem can be infeasible. But can it have an unbounded optimum solution? Sadly, yes, when there is a negative cost cycle.

51 Negative Cost Cycles 6 -6 4 s t p q r 1 2 3 4

52 Negative Cost Edges? Negative cost edges are ok, as long as there is no negative cost cycle -6 2 4 s t p q r 1 2 3 4

53 Next Solving the example problem numerically Min-Cost Flow Remember: This LP formulation gives us the edges on the shortest path, but not in any specific order


Download ppt "MS&E 211 Lecture 5: Basic Feasible Solutions; Shortest Paths Ashish Goel."

Similar presentations


Ads by Google