DAA Unit05 Part2
DAA Unit05 Part2
( unit-v Chapter -2 )
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.
∞ 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
∞ 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 ∞
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]
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]
∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞ ∞
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
^ 32 2 22
Process: The calculation of U and C is as 3 32
follows. 38
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
{
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.
b) n=5, ( p1,p2,p3,p4,p5 )=
( w1,w2,w3,w4,w5 )=
( 4,4,5,8,9 ) and m=15.