48
1 Branch and bound

7-Branch and Bound

Embed Size (px)

Citation preview

Page 1: 7-Branch and Bound

1

Branch and bound

Page 2: 7-Branch and Bound

2

Branch and Bound Method

• The design technique known as branch and bound is similar to backtracking in that it searches a tree model of the solution space and is applicable to a wide variety of discrete combinatorial problems.

• Backtracking algorithms try to find one or all configurations modeled as N-tuples, which satisfy certain properties.

• Branch and bound are more oriented towards optimization.

Page 3: 7-Branch and Bound

3

Here all the children of the E- node are generated before any other live node can become E- node.

Here two state space trees can be formed BFS (FIFO)and D search (LIFO).

Page 4: 7-Branch and Bound

4

1

2 34 5

X1=1X1=4

6 7 8

X2=2 X2=4

9 10 11

12 13

X3=3

16

1415

X4=4 BFS SEARCH for sum of subset problem

X3=4

X1=2

X2=3

Variable size tuple

Page 5: 7-Branch and Bound

5

Variable size tuple 1

2 1014 16

X1=1X1=4

3 7 9

X2=2 X2=4

11 13 15

4 6

X3=3

5

812

X4=4 DFS SEARCH for sum of subset problem

X3=4

X1=2

X2=3

Page 6: 7-Branch and Bound

6

Variable size tuple 1

2 34 5

X1=1X1=4

10 11 12

X2=2 X2=4

7 8 6

14 15

X3=3

16

139

X4=4 D- SEARCH for sum of subset problem

X3=4

X1=2

X2=3

Page 7: 7-Branch and Bound

7

Fixed size tuple

1

2 3

X1=0X1=1

4 5

6 7

8 910 11

12 13

14 1516 17

18 19

20 21

22 23

Nodes are generated in D - search manner for sum of subset problem

Page 8: 7-Branch and Bound

8

Traveling salesman problem

• The salesman problem is to find a least cost tour of N cities in his sales region.

• The tour is to visit each city exactly once.• Salesman has a cost matrix C where the

element cij equals the cost (usually in terms of time, money, or distance) of direct travel between city I and city j.

• Assume cii=infinity for all i. • Also cij= infinity if it is not possible to move

directly from city I to city j.

Page 9: 7-Branch and Bound

9

Branch and bound algorithms for traveling salesman problem can be formulated in a variety of ways.

Without loss of generality we can assume that every tour starts and ends at city one.

So the solution space S is given by

{ 1 , π , 1 | π is a permutation of (2,3,4… n)}

|S|= (n-1)!.

Page 10: 7-Branch and Bound

10

1

2 3 4

5 6

1112

7 8

13 14

9 10

15 16

A State space tree for traveling salesman problem with n= 4

I1=2I1=3

I1=4

I2=3I2=4

I3=4

I2=3

I3=2

Tour 1 2 3 4 1 1 2 4 3 1

Page 11: 7-Branch and Bound

11

all tours

------{3,5} {3,5}

-------{2,1} {2,1}

A branch and bound state space tree for traveling salesman problem

Page 12: 7-Branch and Bound

12

What is meant by bounding?

With each vertex in the tree we associate a lower bound on the cost of any tour in the set represented by the vertex.

The computation of these lower bounds is major labor saving device in any branch and bound algorithm.

There fore much thought should be given to obtain tight bounds.

Page 13: 7-Branch and Bound

13

Assume that we have constructed a specific complete tour with cost = m.

If the lower bound associated with the set of tours represented by a vertex v is M.

And

M>= m

Then no need to search further for descendants of v for the optimum tour.

Page 14: 7-Branch and Bound

14

Basic steps for the computation of lower bounds

The basic step in the computation of lower bound is known as reduction. It is based on following observations:

1- In the cost matrix C every full tour contains exactly one element from each row and each column.

Note: converse need not be true e.g {(1,5),(5,1),(2,3),( 3,4),(4,2)}.

Page 15: 7-Branch and Bound

15

{(1,5),(5,1),(2,3),( 3,4),(4,2)}.

Page 16: 7-Branch and Bound

16

• 1 5

• 2 3

» 4

Page 17: 7-Branch and Bound

17

Row Reduction

2- If a constant h is subtracted from every entry in any row or column of C , the cost of any tour under the new matrix C’ is exactly h less than the cost of the same tour under matrix C. This subtraction is called a row (column) reduction

Page 18: 7-Branch and Bound

18

3- By a reduction of the entire cost matrix C we mean the following: Sequentially go down the rows of C and subtract the value of each row’s smallest element hi from every element in the row. Then do the same for each column.

Let h = ∑ hi summation over all rows and columns

The resulting cost matrix will be called the reduction of C.

h is a lower bound on the cost of any tour.

Page 19: 7-Branch and Bound

19

Let A be the reduced cost matrix for a node R. Let S be a child of R such that edge (R,S) corresponds to including edge (i,j) in the tour.

1- change all entries in row i and column j of A to .(so that no edge from this row (column)leaving from I(coming to j), may be included in the tour in future).

2- set A(j,1) = ∞

This prevents A(j,1) since node 1 should be the last node of the tour.

Page 20: 7-Branch and Bound

20

4-Reduce all rows and columns in the resulting matrix except for rows and columns containing only ∞

.

Let the resulting matrix be B.

Let r be the total amount subtracted then lower bound on S is

lower bound for (R) + A(i,j) + r

Page 21: 7-Branch and Bound

21

example

∞ 20 30 10 11

15 ∞ 16 4 2

3 5 ∞ 2 4

19 6 18 ∞ 3

16 4 7 16 ∞

∞ 10 17 0 1

12 ∞ 11 2 0

0 3 ∞ 0 2

15 3 12 ∞ 0

11 0 0 12 ∞

Reduced cost matrix lower bound = 25(subtracting from rows 10,2,2,3,4) and 1,3 from column 1 and 3.

So all tours in the given graph have length at least 25.

Cost matrix Reduced Cost Matrix

Page 22: 7-Branch and Bound

22

∞ 20 30 10 11

15 ∞ 16 4 2

3 5 ∞ 2 4

19 6 18 ∞ 3

16 4 7 16 ∞

∞ 10 20 00 1

15 ∞ 16 4 2

3 5 ∞ 2 4

19 6 18 ∞ 3

16 4 7 16 ∞

2 3 1 4 5 2 h1 h2 h3 h4 h5

C1 C2 C3 C4 C5

Page 23: 7-Branch and Bound

23

52

1 25

2 3 4535 53 25 31

6 7 8

9 10

11

5036

I1=2

I1=3I1=4

I1=5

I2=2 i2= 3

28

52 28

28

I3=3I3=5

I4=3

Page 24: 7-Branch and Bound

24

∞ 10 17 0 1

12 ∞ 11 2 0

0 3 ∞ 0 2

15 3 12 ∞ 0

11 0 0 12 ∞

Reduced Cost Matrix

∞ ∞ ∞ ∞ ∞

∞ ∞ 11 2 0

0 ∞ ∞ 0 215 ∞ 12 ∞ 011 ∞ 0 12 ∞

Path (1,2) node 2(25 + 10=35)

Page 25: 7-Branch and Bound

25

∞ ∞ ∞ ∞ ∞

∞ ∞ 11 2 0

0 ∞ ∞ 0 215 ∞ 12 ∞ 011 ∞ 0 12 ∞

∞ ∞ ∞ ∞ ∞

1 ∞ ∞ 2 0

∞ 3 ∞ 0 2

4 3 ∞ ∞ 0

0 0 ∞ 12 ∞

∞ ∞ ∞ ∞ ∞

12 ∞ 9 0 ∞

0 3 ∞ 0 ∞12 0 9 ∞ ∞

∞ 0 0 12 ∞

Path (1,2) node 2(25 + 10=35) path(1,3) node 3 (25+17+11=53

=

path(1,5) node 5

∞ ∞ ∞ ∞ ∞12 ∞ 11 ∞ 0

0 3 ∞ ∞ 2

∞ 3 12 ∞ 011 0 0 ∞ ∞ Path 1,4

node 4

Page 26: 7-Branch and Bound

26

∞ ∞ ∞ ∞ ∞

12 ∞ 9 0 ∞

0 3 ∞ 0 ∞

12 0 9 ∞ ∞

∞ 0 0 12 ∞

∞ 10 17 0 1

12 ∞ 11 2 0

0 3 ∞ 0 2

15 3 12 ∞ 0

11 0 0 12 ∞

Reduced Cost Matrixpath(1,5) node 5

25 + +2 + 3=31

Page 27: 7-Branch and Bound

27

∞ 10 17 0 1

12 ∞ 11 2 0

0 3 ∞ 0 2

15 3 12 ∞ 0

11 0 0 12 ∞

Reduced Cost Matrix

∞ ∞ ∞ ∞ ∞

1 ∞ ∞ 2 0

∞ 3 ∞ 0 2

4 3 ∞ ∞ 0

0 0 ∞ 12 ∞

path(1,3) node 3 (25+17+11=53

Page 28: 7-Branch and Bound

28

∞ 10 17 0 1

12 ∞ 11 2 0

0 3 ∞ 0 2

15 3 12 ∞ 0

11 0 0 12 ∞

∞ ∞ ∞ ∞ ∞

12 ∞ 11 ∞ 0

0 3 ∞ ∞ 2

∞ 3 12 ∞ 0

11 0 0 ∞ ∞

Path 1,4 node 4Reduced Cost Matrix

Page 29: 7-Branch and Bound

29

∞ ∞ ∞ ∞ ∞

12 ∞ 11 ∞ 0

0 3 ∞ ∞ 2

∞ 3 12 ∞ 0

11 0 0 ∞ ∞

∞ ∞ ∞ ∞ ∞

∞ ∞ 11 ∞ 0

0 ∞ ∞ ∞ 2

∞ ∞ ∞ ∞ ∞

11 ∞ 0 ∞ ∞

Path 1-4-2 node 6

Bound 28

Path 1,4 node 4 bound 25

Page 30: 7-Branch and Bound

30

∞ ∞ ∞ ∞ ∞

∞ ∞ 11 ∞ 0

0 ∞ ∞ ∞ 2

∞ ∞ ∞ ∞ ∞

11 ∞ 0 ∞ ∞

∞ ∞ ∞ ∞ ∞

∞ ∞ ∞ ∞ ∞

∞ ∞ ∞ ∞ 0

∞ ∞ ∞ ∞ ∞

0 ∞ ∞ ∞ ∞

Path 1-4-2-3 node 9

Bound 52

Path 1-4-2 node 6

Bound 28

Page 31: 7-Branch and Bound

31

∞ ∞ ∞ ∞ ∞

∞ ∞ 11 ∞ 0

0 ∞ ∞ ∞ 2

∞ ∞ ∞ ∞ ∞11 ∞ 0 ∞ ∞

∞ ∞ ∞ ∞ ∞

1 ∞ ∞ ∞ 0

∞ 1 ∞ ∞ 0

∞ ∞ ∞ ∞ ∞

0 0 ∞ ∞ ∞

∞ ∞ ∞ ∞ ∞

∞ ∞ ∞ ∞ ∞

∞ ∞ ∞ ∞ 0

∞ ∞ ∞ ∞ ∞

0 ∞ ∞ ∞ ∞

Path 1-4-2 npde 6Path 1 4 3 : node 7

Path 1-4-2-3 node 9

∞ ∞ ∞ ∞ ∞

∞ ∞ ∞ ∞ ∞

0 ∞ ∞ ∞ ∞

∞ ∞ ∞ ∞ ∞

∞ ∞ 0 ∞ ∞

Path 1-4-2-5 node 10

Page 32: 7-Branch and Bound

32

Least cost (LC) Search

In both LIFO and FIFO branch and bound the selection rule for the next E- node is rather rigid and in a sense blind.The selection rule for the next E- node does not give any preference to a node that has a very good chance of getting the search to an answer node quickly.

The search for an answer node can often be speeded by using an “ intelligent ranking C*(.) for live nodes.The next E- node is selected on the basis of this ranking function.

Page 33: 7-Branch and Bound

33

Let g^ (x) be an estimate of the additional effort needed to reach an answer node from x.

H(x) is the cost of reaching x from the root.F(.) is any non decreasing function.Node x is assigned a rank using c^(.) such thatC^(x)= f(h(x)) + g^(x)Using f(.)=0 usually biases the search algorithm to

make deep probes into the search tree.Note: BFS and d-search are special cases of LC

search.If g^(x)= 0 and f(h(x)) = level of node x then a LC

search generates nodes by level.Which is BFS

Page 34: 7-Branch and Bound

34

Assignment Problem

Page 35: 7-Branch and Bound

35

There are n people who need to be assigned to execute n jobs, one person per job. (i.e. each person is assigned to exactly one job and each job is assigned to exactly one person).

C(i, j) is the cost if the i th person is assigned j th job

for each pair i, j =1,2…nThe problem is to find an assignment

with the smallest total cost.

Page 36: 7-Branch and Bound

36

• Hungarian method is much more efficient for this problem.

Page 37: 7-Branch and Bound

37

Lower bound

There are many ways to find a lower bound.

We can relax the condition on person,

i.e. one Person may be assigned more than one job

Or

We can relax he condition on jobs

More than one person may be assigned to a job

Page 38: 7-Branch and Bound

38

problem

Job1 Job2 Job3 Job4 persons

9 2 7 8 A

6 4 3 7 B

5 8 1 8 C

7 6 9 4 D

Page 39: 7-Branch and Bound

39

Person A to job 1Cut first row and first column

then try to assign the remaining persons to cheapest jobs lower bound 9+3+1+4=17

Job1 Job2 Job3 Job4 persons

9 2 7 8 A

6 4 3 7 B

5 8 1 8 C

7 6 9 4 D

Page 40: 7-Branch and Bound

40

Start

Lb=10

a 2

Lb=10

a1

Lb=17

a 3

Lb=20

a 4

Lb =18

b4

Lb=17

b 3

Lb=14

b1

Lb=13

c4

d 3

Lb=25

c3

d 4

Lb=13

For a 2 delete 2nd col ,1st row find min of each row and total of it

Page 41: 7-Branch and Bound

41

Lower bound when A-2 and B-1Lower bound 2+6+1+4=13

Job1 Job2 Job3 Job4 persons

9 2 7 8 A

6 4 3 7 B

5 8 1 8 C

7 6 9 4 D

Page 42: 7-Branch and Bound

42

Lower bound=2+3+1+4=10

Job1 Job2 Job3 Job4 persons

9 2 7 8 A

6 4 3 7 B

5 8 1 8 C

7 6 9 4 D

Page 43: 7-Branch and Bound

43

Knapsack Problem

Item

Wt Val Val/ wt

1 4 40 10

2 7 42 6

3 5 25 5

4 3 12 4

Knapsack ’s capacity is 10

Page 44: 7-Branch and Bound

44

• A simple way to compute upper bound is

= v + (W – w) (vi+1/wi+1)

Where v = total value of items already added in bag

w = wt of items already selected

i+1 is the best per unit payoff among the remaining items

Page 45: 7-Branch and Bound

45

W=0,v=0

Up=100

W=4,v=40

Up=76

W=0,v=0

Up=60

W /o 1With 1

W=4, v=40

Up=70W=11

Not feas

w/ o 2 With 2

W=4, v=40

Up=64

W=9, v=65

Up=69

W= 12

Not feas

W=9, v=65

Up=65

Sate space tree

w/ o 3 With 3

Item

Wt

Val

Val/ wt

1 4 40 10

2 7 42 6

3 5 25 5

4 3 12 4

Page 46: 7-Branch and Bound

46

Traveling salesman problem

a

e

c d

b

9

4

1

3

7

3 9

56

8

2

Page 47: 7-Branch and Bound

47

Lower Bound

for each city I find the sum si of the distances from city I to the two nearest cities; compute the sum s of these n numbers; divide the result by two and round up if all distances are integers.

Lb = [(1 +3)+ (3 +6) + (1 +2) + (3 +4) + (2+3)]/2 = 14

Page 48: 7-Branch and Bound

48

aLb=14

a, eLb=19

a, dLb=16

a, cX

a, bLb=14

a, b, eLb=19

a, b, dLb=16

a, b, cLb=16

a, b, d,e(c, a)

Lb= 16

a, b, d, c(e, a)Lb=24

a, b, c ,e(d, a)Lb=19

a, b, c, d(e,a)

Lb= 24

First tour Better tour Inferior tour Optimal tour

X

X X