Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 312: Algorithm Analysis Lecture #33: Branch and Bound, Job Assignment This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported.

Similar presentations


Presentation on theme: "CS 312: Algorithm Analysis Lecture #33: Branch and Bound, Job Assignment This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported."— Presentation transcript:

1 CS 312: Algorithm Analysis Lecture #33: Branch and Bound, Job Assignment This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.Creative Commons Attribution-Share Alike 3.0 Unported License Slides by: Eric Ringger, with contributions from Mike Jones, Eric Mercer, and Sean Warnick

2 Announcements  Project #6:  Due today by 5pm  Homework #23 optional  Homework #24 due Wednesday  Project #7: TSP  Budget about 15 hours (mean)  ASAP: Read Instructions  Today: We discuss main ideas  Tuesday: Help session at 5pm in 1066 TMCB  By Wednesday: Read the helpful “B&B for TSP Notes” linked from the schedule in the reading column  Next Wednesday: Early day  Week from Friday: due

3 Objectives  Understand the difference between backtracking and branch and bound  Understand bounding functions  Develop a branch and bound algorithm for the Job Assignment Problem

4 State-space Search Backtracking Purpose:Existence, Enumeration Answer:Yes/No, Count, Set Idea:Avoid searching the entire state-space Main tool:Feasibility function

5 State-space Search BacktrackingBranch and Bound Purpose:Existence, EnumerationOptimization Answer:Yes/No, Count, Set(Good, better,) best Idea:Both avoid searching the entire state-space Main tool:Feasibility functionBounding function

6 Bounding Function “From this state s, I can do no better than B(s).” better worse bound B(s) cost of actual solution is somewhere in here Given some state s in the search space, compute a bound B(s) on the cost/goodness of all solutions that descend from that state.

7 BSSF = Best Solution So Far better worse Cost of BSSFbound B(s) cost of actual solution is somewhere in here

8 Pruning Scenario #1 better worse Cost of BSSF Would you explore this state s with bound B(s)? bound B(s) BSSF = “Best Solution So Far” cost of actual solution is somewhere in here

9 Pruning Scenario #2 better worse Cost of BSSF Would you explore this state s’ with bound B(s’)? BSSF = “Best Solution So Far” cost of actual solution is somewhere in here bound B(s’)

10 Job Assignment Problem  Given n tasks and n agents.  Each agent has a cost to complete each task  Assign each agent one task; each task one agent;  A 1:1 mapping  Minimize cost

11 Minimization  The cost of the BSSF  Is an Upper Bound on the optimal solution  B(): Bounding function for evaluating any state s  Is a Lower Bound on potential solutions reachable from s  Usually involves solving a relaxed form of the problem  s 0 : Initial state  LB = B(s 0 )  Is a Lower Bound on all potential solutions reachable from the initial state  Tight bounds:  Why would you want the upper and lower bounds to be tight? better worse Cost of BSSF LB

12 Example

13 How to represent a state?

14 Example First, generate a solution (not necessarily optimal) and call that your best solution so far (BSSF). How?

15 Hint First, generate a solution (not necessarily optimal) and call that your best solution so far (BSSF). How?

16 BSSF BSSF: 73 First, generate a solution (not necessarily optimal) and call that your best solution so far (BSSF). How? One possible way: Assign jobs along the diagonals – take the lower one. Something quick (at worst linear?).

17 Lower Bound BSSF: 73 Next, compute a lower bound on all solutions. How?

18 Hint BSSF: 73 Next, compute a lower bound on all solutions. How? Bounding function: Easy to evaluate True bound

19 Lower Bound BSSF: 73 Next, compute a lower bound on all solutions. How? Add the smallest entry in each column LB = 58 Other alternatives?

20 Lower Bound BSSF: 73 Next, compute a lower bound on all solutions. How? Add the smallest entry in each column LB = 58 Our situation:

21 Lower Bound BSSF: 73 Next, compute a lower bound on all solutions. How? Add the smallest entry in each column LB = 58 Initial questions: What if the LB == BSSF? What if the assignment underlying the LB is a solution? What if LB > BSSF?

22 Search A:1 BSSF: 73 Now, make an assignment to agent A  (58)

23 A:1 (60) Then apply the bounding function: add the smallest values in each column. This is a lower bound on the cost of any solution with job 1 assigned to A. It’s not a solution! BSSF: 73 Example  (58)

24 A:1 (60) A:2 (58) same for assigning job 2 to A. BSSF: 73 Example  (58)

25 A:1 (60) A:2 (58) A:3 (65) BSSF: 73 Example  (58)

26 A:1 (60) A:2 (58) A:3 (65) A:4 (78) BSSF: 73 What can we say about the last option? Example  (58)

27 A:1 (60) A:2 (58) A:3 (65) A:4 (78) BSSF: 73 Example  (58) How to proceed from here? Many options: Breadth-first Depth-first Most promising first

28 A:1 (60) A:2 (58) A:3 (65) A:4 (78) BSSF: 73 Example  (58) How to proceed from here? Many options: Breadth-first Depth-first Most promising first – we’ll try this one today Other possibilities

29 A:1 (60) A:2 (58) A:3 (65) A:4 (78) BSSF: 73 Example  (58)

30 A:1 (60) A:2 (58) A:3 (65) A:4 (78) A:2, B:1 (68) BSSF: 73 Example  (58)

31 A:1 (60) A:2 (58) A:3 (65) A:4 (78) A:2, B:1 (68) A:2, B:3 (59) A:2, B:4 (64) Example  (58) BSSF: 73

32 A:1 (60) A:2 (58) A:3 (65) A:4 (78) A:2, B:1 (68) A:2, B:3 (59) A:2, B:4 (64) A:2, B:3, C:1, D:4 (64) A:2, B:3, C:4, D:1 (65) When you reach a solution, update the BSSF if better. Example  (58) BSSF: 73

33 A:1 (60) A:2 (58) A:3 (65) A:4 (78) A:2, B:1 (68) A:2, B:3 (59) A:2, B:4 (64) BSSF: 64 A:2, B:3, C:1, D:4 (64) A:2, B:3, C:4, D:1 (65) When you reach a solution, update the BSSF if better. Then what? Example  (58)

34 A:1 (60) A:2 (58) A:3 (65) A:4 (78) A:2, B:1 (68) A:2, B:3 (59) A:2, B:4 (64) BSSF: 64 A:2, B:3, C:1, D:4 (64) A:2, B:3, C:4, D:1 (65) Example  (58) Prune!

35 A:1 (60) A:2 (58) A:3 (65) A:4 (78) A:2, B:1 (68) A:2, B:3 (59) A:2, B:4 (64) BSSF: 64 A:2, B:3, C:1, D:4 (64) A:2, B:3, C:4, D:1 (65) Example  (58)

36 That’s the basic idea. Many details have been left out. Let’s add a few. Example

37 Details  What should each state contain?  Just as for backtracking state-space search, we need enough information in each state to generate its children in the state space  The value of the bound on this state  How to store the set of states visited but remaining to be explored (i.e., “frontier of the search”)?  A set, sometimes called the “agenda” or “open list”  DFS: use a stack  BFS: use a queue  Most Promising First: use a priority queue  Other possibilities (e.g., hybrids)

38 function DFS(v) P  empty-stack visited(v)  true P.push(v) while !P.empty() do while there exists w adjacent to P.top() (in ascending order) such that !visited(w) do visited(w)  true P.push(w) // w is the new P.top() P.pop() Recall: Iterative DFS

39 Recall: Breadth First Search function BFS(v) Q  empty-queue visited(v)  true Q.enqueue(v) while !Q.empty() do u  Q.first() Q.dequeue() for each w adjacent to u (in ascending order) do if !visited(w) then visited(w)  true Q.enqueue(w)

40 B&B using a Priority Queue: Work in Progress function BandB-draft(v) Q  empty-priority-queue visited(v)  true Q.enqueue(v) while !Q.empty() do u  Q.first() Q.dequeue() for each w adjacent to u (in ascending order) do if !visited(w) then visited(w)  true Q.enqueue(w) What’s missing? Remember: a priority queue is not the only possible representation of the agenda.

41 Use Bound as Priority function BandB-draft(v) Q  empty-priority-queue visited(v)  true v.b  bound(v) // LB Q.enqueue(v, v.b) while !Q.empty() do u  Q.first() Q.dequeue() for each w adjacent to u (in ascending order) do if !visited(w) then visited(w)  true w.b  bound(w) Q.enqueue(w, w.b) What’s missing?

42 Adapt for On-the-fly State-Space Search function BandB-draft(v) Q  empty-priority-queue // visited(v)  true v.b  bound(v) Q.enqueue(v, v.b) while !Q.empty() do u  Q.first() Q.dequeue() children = generate_children_ascending(u) for each w in children do // if !visited(w) then // visited(w)  true w.b  bound(w) Q.enqueue(w, w.b) What’s missing?

43 Keep & Check BSSF function BandB-draft(v) BSSF  quick-solution(v) // BSSF.cost holds cost Q  empty-priority-queue v.b  bound(v) Q.enqueue(v, v.b) while !Q.empty() do u  Q.first() Q.dequeue() children = generate_children_ascending(u) for each w in children do w.b  bound(w) if (w.b < BSSF.cost) then if criterion(w) then BSSF  w else if partial_criterion(w) then Q.enqueue(w, w.b) return BSSF What’s missing?

44 V1: Prune Unpromising Nodes Lazily function BandB(v) BSSF  quick-solution(v) // BSSF.cost holds cost Q  empty-priority-queue v.b  bound(v) Q.enqueue(v, v.b) while !Q.empty() do u  Q.first() Q.dequeue() if u.b < BSSF.cost then children = generate_children_ascending(u) for each node w in children do w.b  bound(w) if (w.b < BSSF.cost) if criterion(w) then BSSF  w else if partial_criterion(w) then Q.enqueue(w, w.b) return BSSF What’s missing? Remember: this version only works for best-first; i.e., when a priority queue is the agenda.

45 Know when to Stop! function BandB(v) BSSF  quick-solution(v) // BSSF.cost holds cost Q  empty-priority-queue v.b  bound(v) Q.enqueue(v, v.b) while !Q.empty() do u  Q.first() Q.dequeue() if u.b < BSSF.cost then children = generate_children_ascending(u) for each node w in children do w.b  bound(w) if (w.b < BSSF.cost) if criterion(w) then BSSF  w else if partial_criterion(w) then Q.enqueue(w, w.b) else break return BSSF What’s missing? Remember: this version only works for best-first; i.e., when a priority queue is the agenda.

46 V2: Prune Early when BSSF is updated function BandB(v) BSSF  quick-solution(v) // BSSF.cost holds cost Q  empty-priority-queue v.b  bound(v) Q.enqueue(v, v.b) while !Q.empty() do u  Q.first() Q.dequeue() children = generate_children_ascending(u) for each w in children do w.b  bound(w) if (w.b < BSSF.cost) then if criterion(w) then BSSF  w Q.prune(BSSF.cost) else if partial_criterion(w) then Q.enqueue(w, w.b) return BSSF What’s missing?

47 Generalize: Arbitrary Agenda function BandB(v) BSSF  quick-solution(v) // BSSF.cost holds cost Agenda.clear() v.b  bound(v) Agenda.add(v, v.b) while !Agenda.empty() do u  Agenda.first() Agenda.remove_first() children = generate_children_ascending(u) for each w in children do w.b  bound(w) if (w.b < BSSF.cost) then if criterion(w) then BSSF  w Agenda.prune(BSSF.cost) else if partial_criterion(w) then Agenda.add(w, w.b) return BSSF

48 Critical Elements of a B&B Algorithm  BSSF  Bounding function  Representation of the frontier on an agenda  Select state from the agenda  Generate children  By copying parent and making one more decision  Calculate the bound  Handle children that are solutions  Place promising children on the agenda  Prune the losers  Repeat until  Agenda is empty Required for Project #7

49 B&B for Minimization BSSF Minimization Maximization ? HighLow B(s) is lower bound True solution’s actual cost could be lower than BSSF.

50 B&B for Maximization B(s) is upper bound B(s) is lower bound BSSF Minimization Maximization HighLow True solution’s actual cost could be lower than BSSF. True solution’s actual cost could be higher than BSSF. B(s) must always be optimistic.

51 Completeness and Optimality Important properties of search:  Completeness:  Is your search guaranteed to find a solution when one exists?  Optimality:  Does your search find the optimal (i.e., minimum or maximum cost) solution?  Does your search only prune sub-optimal states?

52 Assignment  Homework #24  B&B  due Wednesday  Required: Read B&B Notes & Project #7 instructions!  Then you’re ready to solve Project #7


Download ppt "CS 312: Algorithm Analysis Lecture #33: Branch and Bound, Job Assignment This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported."

Similar presentations


Ads by Google