32
Branch and bound Pasi Fränti 30.9.2014

Branch and bound Pasi Fränti 30.9.2014. Explore all alternatives Solution constructed by stepwise choices Decision tree Guarantees optimal solution Exponential

Embed Size (px)

Citation preview

Branch and bound

Pasi Fränti30.9.2014

Explore all alternatives• Solution constructed by stepwise choices• Decision tree• Guarantees optimal solution• Exponential time (slow)

Depth-first search• Implement as stack (push, pop, isempty)• Linear time memory

Breadth-first search• Implemented by queue (enqueue, dequeue,

isempty)

General search strategiesBacktracking

Traveling salesman problem

Input: graph (V,E)

Problem: Find shortest path via all nodes and returning to start node.

A

B C

D E F

G H

22

24 4

3 32

23

43 5

A

B C

D E F

G H

22

24 4

3 32

23

43 5

Traveling salesman problem

Solution = A-B-C-F-H-E-D-G-ALength = 22

Input: graph (V,E)

Output: path (p1, p2, ..., pn, pn+1)

Traveling salesman problem

Exercise task

Input: Weight of N items {w1, w2, ..., wn}

Cost of N items {c1, c2, ..., cn}Knapsack limit S

Output: Selection for knapsack: {x1,x2,…xn}

where xi {0,1}. Sample input:

wi={1,1,2,4,12}

ci ={1,2,2,10,4}

S=15

Knapsack problemProblem definition

Real example?

Max 15

Input: Weight of N items {w1, w2, ..., wn}

Knapsack limit SOutput: Selection for knapsack: {x1,x2,…xn}

where xi {0,1}. Sample input:

wi={2,3,5,7,11}

S=15

Knapsack problemSimplified

3

5

2

7

11

Max 15

0

5

0

12

12

Knapsack problemBranch-and-bound

2

2 3 0

5 2 0710 39

wi={2,3,5,7,11}

5 01131029

2

33

5 55 5

7777

13 2 14 3 011

11 11 11

Something hereWhen time

Plus the same for sorting decreasing order

wi={2,3,5,7,11}S=15

To be done...

Graph algorithms

136

170315

148 78

231

234

12089

131109

116

86

246

182

216110

117

199

121142

24279

191178

191

126149

17051 112

90163

59

14373

63 53

27135

10558

116

72

79

A

B

C

Empty space for notes

Branch and Bound Algorithm:

Scheduling Problem

Input of the problem:

A number of tasks

A number of resources

1

2

3

4

A B C

Output of the problem:

A sequence of feeding the tasks to resources

to minimize the required processing time

Material by A.Mirhashemi

Application 1Digital processing:Each resource is a processor. All tasks need to pass trough all processors in the fix sequence A,B,C but depending on the task it takes different time for each processor to process them. For example :

Processor A: ScanningProcessor B: Making a PDFProcessor C: Exporting a PDF

Task 1: A one page plain text documentTask 2: A 10 page document with picturesTask 3: A 5 page html document.Task 4: …

Production line:Each product (task) need to pass trough all machines (resources) in the production line but, the time depends on what kind of customization the customer has ordered for that production. For example:

Machine A: SoldingMachine B: PaintingMachine C: Packaging

Task 1: A black car with airbagTask 2: A red car without airbag with CD playerTask 3: A white car with leather seatsTask 4: …

Application 2

Different tasks take different timeto be processed in each resource

1

2

3

4

A B C

7 6 75 5 26 4 13 4 3

Tasks can be done in any order

N! Possible different sequences

12

34

3 1 4 2

2 1 4 3

NP

Decision tree (Brute force)

Greedy Algorithm

A possible greedy algorithm might start with selecting the fastest tasks for processor A.

1

2

3

4

A B C

7 6 7

5 5 2

6 4 1

3 4 3

4 2 3 1A :

4

4

4

2 3 1

2

2

3

3

1

1

Greedy solution T(4,2,3,1) = 34 1

2

3

4

A B C

7 6 7

5 5 2

6 4 1

3 4 3

4

4

4

1

1

1

2

2

2

3

3

3

1

2

3

4

A B C

7 6 7

5 5 2

6 4 1

3 4 3

Optimal solutionT(4,1,2,3) = 26

Branch and bound AlgorithmDefine a bounding criteria for a minimum time required by each branch of the decision tree

For level 1:

For level 2:

1

2

3

4

A B C

7 6 7

5 5 2

6 4 1

3 4 3

b(1)= 7+(6+5+4+4)+1=27b(2)= 5+(6+5+4+4)+1=25b(3)= 6+(6+5+4+4)+2=27b(4)= 3+(6+5+4+4)+1=23

Level 1

T ≥23T ≥27 T ≥27T ≥25Bounds:

Minimum

This next

b(4,1)= (3+7)+(6+5+4)+1=26b(4,2)= (3+5)+(6+5+4)+1=24b(4,3)= (3+6)+(6+5+4)+2=26

1

2

3

4

A B C

7 6 7

5 5 2

6 4 1

3 4 3

Bounds:

Level 2

T ≥26 T ≥24 T ≥26

Minimum

This next

1

2

3

4

A B C

7 6 7

5 5 2

6 4 1

3 4 3

T(4,2,1,3) = 29T(4,2,3,1) = 34

Tmin(4,2,x,x)= 29

Solve the branch 4-2-x-x

T ≥26 T ≥24 T ≥26Bounds:

Actual:

1

2

3

4

A B C

7 6 7

5 5 2

6 4 1

3 4 3

Bounds: T ≥26 T ≥24 T ≥26

Tmin(4,3,x,x)= 29Tmin(4,1,x,x)= 26Tmin(4,2,x,x)= 29

Solve the branch 4-2-x-x

T(4,1,2,3) = 26T(4,1,3,2) = 28

T(4,3,1,2) = 29T(4,3,2,1) = 34

Actual: Actual:

1

2

3

4

A B C

7 6 7

5 5 2

6 4 1

3 4 3

Actual Time: T = 26Bounds: T ≥27 T ≥25 T ≥23T ≥27

Must besolved

Can beskipped

Solve the other branches

b(2,1)= (5+7)+(6+4+4)+1=27b(2,3)= (5+6)+(6+4+4)+3=28b(2,4)= (5+3)+(6+4+4)+1=23

1

2

3

4

A B C

7 6 7

5 5 2

6 4 1

3 4 3

The only candidate that can outperform T(4,1,2,3) is T(2,4,…) so we calculate it:

Actual T(2,4,1,3) = 29Actual T(2,4,3,1) = 34

1

2

3

4

A B C

7 6 7

5 5 2

6 4 1

3 4 3

Actual Time:

So the best time is T(4,1,2,3) and we don’t need to solve the problem for any other branch because we now their minimum time, already.

Bounds:

T = 26T = 29

T ≥27 T ≥25 T ≥23T ≥27

Bounds greater than 26!

• Using only the first level criteria we reduce the problem by 50% (omitting 2 main branches).

• Using the second level criteria we can reduce even more.

Summary

Empty space for notes