0% found this document useful (0 votes)
8 views32 pages

DAA Unit05 Part2

Uploaded by

rrotteakshay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views32 pages

DAA Unit05 Part2

Uploaded by

rrotteakshay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 32

Branch and Bound

( unit-v Chapter -2 )

 Backtracking is effective for subset or permutation


problems.

 Backtracking is not good for optimization problems.

 This drawback is rectified by using Branch And Bound


technique.
 Branch And Bound is applicable for only optimization
problems and will apply when greedy and dynamic
programming fails.

 Branch and Bound also uses bounding function similar to


backtracking.
Branch and Bound
General Method:
 Here we create a state space tree and all the children of
the E-node( the live node whose children are currently being
generated) will get generated before any other live node
becomes the E-node.
For exploring the new nodes we can use either BFS or DFS
approach
The Branch and Bound technique which uses BFS (Queue)
is called as FIFO Branch and Bound.
The Branch and Bound technique which uses DFS (Stack)
is called as LIFO Branch and Bound.
Bounding functions are used to avoid the generation of the
sub tree which do not lead us to answer node.
Terminology of tree organization

State Space :-
All paths from the root to othernodes
define the state space of the problem.

Solution Space :-
All paths from the root to solution states
define the solution space of the
problem.
Ex :- 1
X1=1
X1=4
X1=2 X1=3

2 34 50
18

x 2= 2 3 1 3 1 2 4 1 2 3
4 4

3 8 13 19 24 29 35 40 45 51 56 61
x3=
3 4 2 4 2 3 3 4 1 4 1 3 2 4 1 4 1 2 2 3 1 3 1 2

4 6 9 11 14 16 20 22 25 27 30 32 36 38 41 43 46 48 52 54 57 59 62 64
x4=
4 3 4 2 3 2 4 3 4 1 3 1 4 2 4 1 2 1 3 2 3 1 2 1

5 7 10 12 15 17 21 23 26 28 31 33 37 39 42 44 47 9 53 55 58 60 63 65

Tree organization of the 4-queens solution space. Nodes are numbered as in depth
first search.
Problem state :-
Each node in the tree is a problem
state.
Ex:-1 2 18
and so on
Solution States :-
These are those problem
states S for which the path from the root
to S define a tuple in the solution space.

Ex:-
5 7 10 12 15 17 21 and so on
– A node which has been generated and all of whose
children have not yet been generated is called a live
node.

– The live node whose children are currently being


generated is called E-node ( Expanding node ).

– A dead node is a generated node which can not to be


expanded further or all of whose children have been
generated.
Branch And Bound
Nodes will be expanded in three ways.
• Search the tree using a breadth-first search
(FIFO branch and bound).

• Search the tree as in a BFS, but replace the FIFO queue


with a stack (LIFO branch and bound).

• Replace the FIFO queue with a priority queue


(Least-Cost (or max priority) branch and bound).
• Least-cost branch and bound directs the search
to the parts which most likely to contain the answer.
Traveling Salesperson Problem
Let G=(V,E) be a directed graph defining
an instance of the travelling salesperson
problem.
Let cij be the cost of the edge (i,j) and
cij=∞ if (i,j)€│E(g) and let │V│=n.
Assume that the tour starts and ends at 1.
To use least cost branch and bound to
search the travelling salesperson state
space tree,we must definr a cost function
c(x) and two other functions
c^(x) <=c(x)<=u^(x).
Reduced Cost Matrix
• A Row or Column is said to be reduced if it
contains at least one zero and all remaining
entries are non-negative .
• A matrix is reduced iff every row and column is
reduced.
- if a constant t is chosen to be minimum entry in
row i (column j) will introduce a zero into a row i
(column j).
- The total amount subtracted from the columns
and rows is lower bound on the length of a
minimum cost tour and can be used as the c^(x)
value for the root of state space tree.
With every node in the state space tree,
we associate a reduced cost matrix.
Let A be the reduced cost matrix for
node R. Let S be the child of r such that
the edge (R,S) corresponds to including
edge (i,j) in the tour.if S is not a leaf
node then the reduced cost matrix for
node S can be obtained as follows.
1. Change all entries in row i column j of
A to ∞.
2. Set A(i,j) to ∞.
3. Apply row reduction and column
reduction except for rows and
columns containing ∞.
4. The total cost for node S can be
calculated as,
c^(S) =c^(R)+A(i,j)+r.
where r is the total amount
substracted in step3.
Travelling Sales persons Problem:

∞ 20 30 10
11
G= 15 ∞ 16 4 2
3 5 ∞ 2 4
19 6 18 ∞ 3
16 4 7 16 ∞

Row minimization:
• find the min value in each row and subtract from the entire row values :

Min values
∞ 20 30 10 11 10 ∞ 10 20 0 1
15 ∞ 16 4 2 2 13 ∞ 14 2 0
3 5 ∞ 2 4 2
3
 1 3 ∞ 0 2
19 6 18 ∞ 3 16 3 15 ∞ 0
16 4 7 16 ∞ 4 12 0 3 12
21 ∞
Column minimization:

∞ 10 20 0 1
13 ∞ 14 2 0
1 3 ∞ 0 2
16 3 15 ∞ 0
12 0 3 12 ∞
1 0 3 0 0 =4

After Full Reduction :

∞ 20 30 10 ∞ 10 17 0 1
11 12 ∞ 11 2 0
15 ∞ 16 4 2  0 3 ∞ 0 2
3 5 ∞ 2 4 15 3 12 ∞ 0
Full reduction 11 0 0 12 ∞
19 6 18 ∞ 3
16 4 7 16 ∞

Total minimization is 21+4 = 25


Steps in dynamic reduction technique:

Draw the state space tree at the root with the optimum cost.
Calculate the cost matrix for i -> j path by making ith row and jth column
entries as ∞ . And also make M[j][i] as ∞
Calculate the Cost which includes (i->j) path is sum of optimum cost,
reduced cost , M[i][j].

a) Path from 1 to 2: so make 1st row and 2nd column as ∞, and set M[2][1]
as ∞
25
∞ 10 17 0 1 ∞ ∞ ∞ ∞ ∞
12 ∞ 11 2 0 ∞ ∞ 11 2 0 1
0 3 ∞ 0 2  0 ∞ ∞ 0 2
35
15 3 12 ∞ 0 15 ∞ 12 ∞ 0
11 0 0 12 ∞ 11 ∞ 0 12 ∞ 2

Cost = 25 + 0 + 10 = 35
Optimum reduced old value of
cost cost M[1][2]
b) Path from 1 to 3: so make 1st row and 3rd column as ∞, and set M[3][1] as ∞

25

∞ 10 17 0 1 ∞ ∞ ∞ ∞ ∞ 1
12 ∞ 11 2 0 12 ∞ ∞ 2 0
0 3 ∞ 0 2  ∞ 3
15 3
∞ 0
∞ ∞
2
0
35 53
15 3 12 ∞ 0 2 3
11 0 0 12 ∞ 11 0 ∞ 12 ∞
11

Cost = 25 + 11 + 17 = 53
Optimum reduced old value of
cost cost M[1][3]
c) Path from 1 to 4: so make 1st row and 4th column as ∞, and set M[4][1] as ∞

25

∞ 10 17 0 1 ∞ ∞ ∞ ∞ ∞ 1
12 ∞ 11 2 0 12 ∞ 11 ∞ 0
0 3 ∞ 0 2  0

3 ∞
3 12


2
0
35 53 25
15 3 12 ∞ 0
11 0 0 12 ∞ 11 0 0 ∞ ∞ 2 3 4

Cost = 25 + 0 + 0 = 25
Optimum reduced old value of
cost cost M[1][4]
d) Path from 1 to 5: so make 1st row and 5th column as ∞, and set M[5][1] as ∞

25

∞ 10 17 0 1 ∞ ∞ ∞ ∞ ∞ 1
12 ∞ 11 2 0 12 ∞ 11 2 ∞ 2
0 3 ∞ 0 2  0 3
15 3

12
0



35 53 25 31
15 3 12 ∞ 0 3
11 0 0 12 ∞ ∞ 0 0 12 ∞ 2 3 4 5
5

Cost = 25 + 5 + 1 = 31
Optimum reduced old value of
cost cost M[1][4]

As the optimum cost we got at node no 4, so the next E-node will be


node no 4. now we explore the node 4 by taking the reduced matrix
that we got in the process of (1->4)
e) Path from 1 to 4 to 2: so make 1st and 4th row as ∞ and 4th and 2nd column as ∞,
and set M[2][1] as ∞
25

1
∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞
12 ∞ 11 ∞ 0 ∞ ∞ 11 ∞ 0 35 53
0 3 ∞ ∞ 2  0 ∞ ∞ ∞ 2
2
25 31
∞ 3 12 ∞ 0 ∞ ∞ ∞ ∞ ∞ 3 4 5
11 0 0 ∞ ∞ 11 ∞ 0 ∞ ∞
28

2
Cost = 25 + 0 + 3 = 28
Optimum reduced old value of
cost cost M[4][2]
f) Path from 1 to 4 to 3: so make 1st and 4th row as ∞ and 4th and 3rd column as ∞,
and set M[3][1] as ∞
25

1
∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞
12 ∞ 11 ∞ 0 12 ∞ ∞ ∞ 0 35 53
0 3 ∞ ∞ 2  ∞ 3 ∞ ∞ 2 2
2
25 31
∞ 3 12 ∞ 0 ∞ ∞ ∞ ∞ ∞ 3 4 5
11 0 0 ∞ ∞ 11 0 ∞ ∞ ∞
28 50
11 13
2 3
Cost = 25 + 13 + 12 = 50
Optimum reduced old value of
cost cost M[4][3]
g) Path from 1 to 4 to 5: so make 1st and 4th row as ∞ and 4th and 5th column as ∞,
and set M[5][1] as ∞
25

1
∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞
12 ∞ 11 ∞ 0 12 ∞ 11 ∞ ∞ 11 35 53
0 3 ∞ ∞ 2  0 3 ∞ ∞ ∞
2
25 31
∞ 3 12 ∞ 0 ∞ ∞ ∞ ∞ ∞ 3 4 5
11 0 0 ∞ ∞ ∞ 0 0 ∞ ∞
28 50
11 36
2 3 5
Cost = 25 + 11 + 0 = 36
Optimum reduced old value of
cost cost M[4][5]

As the optimum cost we got is at node no 2, so the next E-node will


be node no 2. now we explore the node 2 by taking the reduced
matrix that we got in the process of (1->4->2)
h) Path from 1 to 4 to 2 to 3: so make 1st , 4th , 2nd rows as ∞ and 4th , 2nd ,3rd column
as ∞, and set M[3][1] as ∞
25

∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞
1
∞ ∞ 11 ∞ 0 ∞ ∞ ∞ ∞ ∞
35
0

∞ ∞
∞ ∞


2

 ∞







2

2 53 25 31
2 3 4 5
11 ∞ 0 ∞ ∞ 11 ∞ ∞ ∞ ∞ 11

13 28 50 36
2 3 5
Cost = 28 + 13 + 11 = 52 52
Optimum reduced old value of
cost cost M[2][3] 3
i) Path from 1 to 4 to 2 to 5: so make 1st , 4th , 2nd rows as ∞ and 4th ,2nd , 5th column as
∞, and set M[5][1] as ∞
25

∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞
1
∞ ∞ 11 ∞ 0 ∞ ∞ ∞ ∞ ∞
35
0

∞ ∞
∞ ∞


2

 0









53 25 31
2 3 4 5
11 ∞ 0 ∞ ∞ ∞ ∞ 0 ∞ ∞

28 50 36
2 3 5
Cost = 28 + 0 + 0 = 28 52 28
Optimum reduced old value of
cost cost M[2][5] 3 5

As the optimum cost we got is at node no 5, so the next E-node will


be node no 5. we need to explore the node. But node 5 will get only
option of going to node 3. so here no need to do any calculations.
Hence the optimal path is 1->4 -> 2 -> 5 -> 3 -> 1
0/1 knapsack problem

Nodes will be expanded in three ways.


• Search the tree using a breadth-first search
(FIFO branch and bound).

• Search the tree as in a BFS, but replace the FIFO queue


with a stack (LIFO branch and bound).

• Replace the FIFO queue with a priority queue


(Least-Cost (or max priority) branch and bound).
0/1 knapsack problem ^

LC Branch and Bound Solution: Cost Function= c


Upper number = u
EX:- n=4, ( p1,p2,p3,p4 )= (10,10,12,18 ) 32
( w1,w2,w3,w4 ) = ( 2, 4, 6, 9 ), m=15 1 38

^ 32 2 22
Process: The calculation of U and C is as 3 32
follows. 38

U(1) - Scan through the objects from left to 32


right and put into the knapsack until 38 4 5 22
the first object that does not fit is 36
encontered.
32 6 38
^ 38 7 38
C(1) – Similar to U(1) except that it also
considers a fraction of the first object that
does not fit the knapsack.
38 8 9 20
38 20
Answer node
Continue this process until an answer node is
found.
FIFO Branch and Bound EX:- n=4, ( p1,p2,p3,p4 )= (10,10,12,18 )
( w1,w2,w3,w4 ) = ( 2,4,6,9 ), m=15
^
32
38
1
Cost Function = c
32 22 Upper Bound = u
2
38 3 32

32
22
38 4 5 36 6 22 7 30
32 30

32
8 38
38 9 38

50 32
50 10 11 12 38 13 20
32 38 20
Answer
node
EX:- n=4, ( p1,p2,p3,p4 )= (45,30,45,10 )
( w1,w2,w3,w4 ) = ( 3,5,9,5 ), m=16
C=75 w=8
u=115
1
X1 =1
X1 =0
75 w=8 75 w=14
115 2 3 79

X2 =1 X2 =0

75 w=8
90 w=12
115 4 5 98
X3 =1
X3 =0 X3 =1 X3 =0

120 w=17 75 w=8 90 w=12 45 w=3


115 85
8 9 55
98
6 7

100 w=17 90 w=12


8 100 9 90
Answer node
Algorithm UBound(cp,cw,k,m)
// cp is current total profit, cw is the current weight total, k is the index of the
last removed item, m is the knapsack size.

{
b=cp;
fori=k+1 to n do
{
if(c+w[i]<=m) then
{

c=c+w[i];
b=b-p[i];
}
}
return b;
}
Home Work :-
1. Draw the portion of the state space tree generated by
LCBB and FIFIBB for the following knapsack problem.

a) n=5, ( p1,p2,p3,p4,p5 ) = ( 10,15,6,8,4 ),


( w1,w2,w3,w4,w5 )= ( 4,6,3,4,2 ) and
m=12

b) n=5, ( p1,p2,p3,p4,p5 )=
( w1,w2,w3,w4,w5 )=
( 4,4,5,8,9 ) and m=15.

You might also like