assignment-1 ( b10061 )
TRANSCRIPT
Assignment -1 Name LALIT
RollNo. B10061
Branch EE
The whole problem is divided into following parts :-
1. Initial state
2. Operators Defining legal moves
3. H – Value Comparison(Heuristic function)
4. MoveGen function
5. Goal test
Initial State
B B B W W W E
Description:-
There are three black tiles(B), three white tiles(W) and an empty cell(E). The Puzzle has the
following moves(Legal Moves):
H1 and H2 are the operators for defining the legal moves.
H1 A tile may move into an adjacent empty cell with unit cost
H2A tile may hop over at most two other tiles into an empty cell with a cost equal to
the number of tiles hopped over
Goal:-
The goal of the puzzle is to have all of the white tiles to the left of all of the black tiles (without
regard to the position of empty cell) i.e.
W W W B B B E
Solution :-
P is one (1) for every level of the tree
Operators defining Legal moves.
The heuristic function is given by :-
Q no. of tiles hopped over
R no. of tiles out of place
S = Q+R
T = P+S
No. of moves/Nodes available will be decided according to the value of T we are getting; the
lesser the value or lower the cost, the more good will be the node to choose for Goal
Attainment.
Initial state Tile hoped (Q) Out of place (R) T=P+S
BBBWWWE - 6 6+1
This is the best node with lowest heuristic
BBBWWEW 0 6 7
S is 1 for this part of the tree
BBBWEWW 1 6 8
A TILE CAN HOP ATMOST TWO TILES
BBBEWWW 2 6 9
Best node in level two P is 2
BBBWWEW 0 6 8
BBBEWWW 1 6 9
BBEBWWW 2 5 9
Best node in level two P is 3
BBBWEWW - 6 9
BBBEWWW 1 5 9
BBEBWWW 1 5 9
BEBBWWW 2 5 10
The search goes in this way and the search tree is as follows :-
P=24 GOAL ATTAINED
P=23
P=22
P=21
P=20
P=19
P=18
P=17
P=16
P=15
P=14
P=13
P=12
P=11
P=10
P=8
P=8
P=7 (nodes with lowset h value only)
P=6
P=5
P=4
P=3
P=2
P=1
Initial State BBBWWWE
BBBWWEW
(Q=0;R=6,T=7)
BBBWEWW
BBBEWWW BBEWBWW
EBBWBWW BBWEBWW
BEWBBWW
EBWBBWW BWEBBWW
BWWBBEW
BWWBEBW
BWWWEBBW
EWWBBBW
WWEBBBW
WWBEBBW
WWBBEBW
WWBBBEW
WWBBBWE
WWBBEWB
WWBBWEB
WWBEWBB
WWBWEBB
WWEWBBB
WWWEBBB
WWWBEBB
WWWBBEB
WWWBBBE
BBWEBWW
BBEWBWW BBWBEWW
BBBWEWW
BEBWBWW
BBBEWWW BBEWWBW
BBBWEWW
(Q=1;R=6;T=8)
BBBEWWW
(T=9)
MoveGen() function: -
It has to search for lowest ‘T’ and follow it in that node(with minimum T) and search further for the
lowest one till the goal is attained.
Pseudocode for it
Node1 is the parent node or the initial state of our problem
Function Expand(node,problem), Returns (set of nodes )
In expand, we are opening a node and comparing it with the solution of problem and then calculating
the value of ‘T’ or the path cost.
For each calculate ‘T’ and in MinFn Expand(node,problem) // Expand the node with minimum ‘T’
Here, MinFn is used to to expand the node with minimum T
And in this way search goes on with minimum ‘T’ and comparing it with solution required.
T the value of ‘T’ can be calculated by;
T=P+S
Q no. of tiles hopped over
R no. of tiles out of place
S = Q+R
Goal-Test: -
It is simply a compare and return type function
If (nodex==solution)
thenReturn(nodex)
Else
MoveGen(nodex, problem)