Cs 312 algorithm analysis
This presentation is the property of its rightful owner.
Sponsored Links
1 / 51

CS 312: Algorithm Analysis PowerPoint PPT Presentation


  • 54 Views
  • Uploaded on
  • Presentation posted in: General

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.

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


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

Announcements

  • Homework #23 due now

  • Project #7: TSP

    • Budget about 15 hours

    • ASAP: Read Instructions

    • Today: We discuss main ideas

    • Thursday: Help session 10am Tues 1066 TMCB

    • Read the helpful “B&B for TSP Notes” linked from the schedule in the reading column

    • Thurs: Early day

    • Friday: due


Objectives

Objectives

  • Understand the difference between backtracking and branch and bound

  • Understand bounding functions

  • Develop a branch and bound algorithm for the Job Assignment Problem


Backtracking v b b

Backtracking v. B&B


Backtracking v b b1

Backtracking v. B&B


Bounding function

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).”


Bssf best solution so far

BSSF = Best Solution So Far

cost of actual solution is somewhere in here

better

worse

Cost of BSSF

bound B(s)


Pruning scenario 1

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”


Pruning scenario 2

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”


Job assignment problem

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


Minimization

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


Example

Example


Example1

Example

How to represent a state?


Example2

Example

First, generate a solution (not necessarily optimal)

and call that your best solution so far (BSSF). How?


Cs 312 algorithm analysis

Hint

First, generate a solution (not necessarily optimal)

and call that your best solution so far (BSSF). How?


Cs 312 algorithm analysis

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?).


Lower bound

Lower Bound

BSSF: 73

Next, compute a lower bound on all solutions. How?


Cs 312 algorithm analysis

Hint

  • Bounding function:

  • Easy to evaluate

  • True bound

BSSF: 73

Next, compute a lower bound on all solutions. How?


Lower bound1

Lower Bound

BSSF: 73

  • Next, compute a lower bound on all solutions. How?

  • Add the smallest entry in each column

  • LB = 58

  • Other alternatives?


Lower bound2

Lower Bound

BSSF: 73

  • Next, compute a lower bound on all solutions. How?

  • Add the smallest entry in each column

  • LB = 58

  • Our situation:


Lower bound3

Lower Bound

BSSF: 73

  • Next, compute a lower bound on all solutions. How?

  • Add the smallest entry in each column

  • LB = 58

  • What if the LB == BSSF?

  • What if LB > BSSF?


State space search

State-Space Search

BSSF: 73

Now, make an assignment to agent A

A:1

(58)


Example3

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.

A:1 (60)

(58)


Example4

Example

BSSF: 73

A:1 (60)

A:2 (58)

same for assigning job 2 to A.

(58)


Example5

Example

BSSF: 73

A:1 (60)

A:2 (58)

A:3 (65)

(58)


Example6

Example

BSSF: 73

A:1 (60)

A:2 (58)

A:3 (65)

A:4 (78)

(58)

What can we say about the last option?


Example7

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)


Example8

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)


Example9

Example

BSSF: 73

A:1 (60)

A:2 (58)

A:3 (65)

A:4 (78)

(58)


Example10

Example

BSSF: 73

A:1 (60)

A:2 (58)

A:3 (65)

A:4 (78)

A:2, B:1 (68)

(58)


Example11

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)


Example12

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.


Example13

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?


Example14

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!


Example15

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)


Example16

Example

That’s the basic idea. Many details have been left out.

Let’s add a few.


Details

Details

  • What should each state contain?

    • Just as for backtracking 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)


Recall iterative dfs

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()


Recall breadth first search

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)


B b using a priority queue work in progress

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?


Use bound as priority

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?


Adapt for on the fly state space search

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?


Keep check bssf

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?


V1 prune unpromising nodes lazily

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?


Know when to stop

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?


V2 prune early when bssf is updated

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?


Generalize agenda

Generalize: 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


Critical elements of a b b algorithm

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


B b for minimization

B&B for Minimization

Minimization

True solution’s actual cost could be lower than BSSF.

actual

cost

B(s) islower

bound

BSSF

Low

High

Maximization ?


B b for maximization

B&B for Maximization

Minimization

True solution’s actual cost could be lower than BSSF.

actual

cost

B(s) islower

bound

BSSF

Low

High

Maximization

True solution’s actual cost could be higher than BSSF.

actual

cost

B(s) isupper

bound

BSSF

B(s) must always be optimistic.


Completeness and optimality

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?


  • Login