1 / 52

CS 312: Algorithm Analysis

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

senwe
Download Presentation

CS 312: Algorithm Analysis

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. CS 312: Algorithm Analysis Lecture #33: Branch and Bound, Job Assignment 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

  5. State-space Search

  6. Bounding Function 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. cost of actual solution is somewhere in here better worse bound B(s) “From this state s, I can do no better than B(s).”

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

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

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

  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 worse • 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 • s0: Initial state • LB = B(s0) • 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? Cost ofBSSF LB better

  12. Example

  13. Example 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 • Bounding function: • Easy to evaluate • True bound BSSF: 73 Next, compute a lower bound on all solutions. How?

  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 BSSF: 73 Now, make an assignment to agent A A:1 (58)

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

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

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

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

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

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

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

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

  31. Example BSSF: 73 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) (58)

  32. Example BSSF: 73 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) (58) When you reach a solution, update the BSSF if better.

  33. Example BSSF: 64 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) (58) When you reach a solution, update the BSSF if better. Then what?

  34. Example BSSF: 64 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) (58) Prune!

  35. Example BSSF: 64 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) (58)

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

  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. Recall: Iterative DFS function DFS(v) P  empty-stack visited(v)  true P.push(v) while !P.empty() do while there existsw 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()

  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 functionBandB-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) Remember: a priority queue is not the only possible representation of the agenda. What’s missing?

  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-flyState-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 childrendo // 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 childrendo w.b  bound(w) if (w.b < BSSF.cost) then if criterion(w)then BSSF  w else ifpartial_criterion(w) then Q.enqueue(w, w.b) return BSSF What’s missing?

  44. V1: Prune Unpromising Nodes Lazily functionBandB(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() ifu.b < BSSF.costthen • children = generate_children_ascending(u) for each node w in childrendo w.b  bound(w) if(w.b < BSSF.cost) if criterion(w) then BSSF  w else ifpartial_criterion(w) then Q.enqueue(w, w.b) return BSSF Remember: this version only works for best-first; i.e., when a priority queue is the agenda. What’s missing?

  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 childrendo 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 Remember: this version only works for best-first; i.e., when a priority queue is the agenda. What’s missing?

  46. V2: Prune Earlywhen 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 childrendo 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 childrendo 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 Minimization True solution’s actual cost could be lower than BSSF. B(s) islower bound BSSF Low High Maximization ?

  50. B&B for Maximization Minimization True solution’s actual cost could be lower than BSSF. B(s) islower bound BSSF Low High Maximization True solution’s actual cost could be higher than BSSF. B(s) isupper bound BSSF B(s) must always be optimistic.

More Related