Anda di halaman 1dari 4

Assignment -1

Name

LALIT

RollNo. B10061 Branch EE

The whole problem is divided into following parts :1. 2. 3. 4. 5. Initial state Operators Defining legal moves H Value Comparison(Heuristic function) MoveGen function 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 BBBWWWE BBBWWEW Tile hoped (Q) 0 Out of place (R) 6 6 T=P+S 6+1 7

This is the best node with lowest heuristic S is 1 for this BBBWEWW 1 6 part of the tree A TILE CAN HOP BBBEWWW 2 6 ATMOST TWO TILES Best node in BBBWWEW 0 6 level two P is 2 BBBEWWW 1 6 BBEBWWW 2 5 Best node in BBBWEWW 6 level two P is 3 BBBEWWW 1 5 BBEBWWW 1 5 BEBBWWW 2 5 The search goes in this way and the search tree is as follows :-

8 9

8 9 9 9 9 9 10

Initial State P=1 P=2 P=3 P=4 P=5 P=6 P=7 (nodes with lowset h value only) P=8 P=8 P=10 P=11 P=12 P=13 P=14 P=15 P=16 P=17 P=18 P=19 P=20 P=21 P=22 P=23 P=24 GOAL ATTAINED
EBWBBWW BBBEWWW BBBWEWW BBBWWEW (Q=0;R=6,T=7)

BBBWWWE

BBBWEWW (Q=1;R=6;T=8)

BBBEWWW (T=9)

BBBEWWW

BBEWWBW

BBEWBWW

BEBWBWW

EBBWBWW

BBWEBWW

BBBWEWW

BEWBBWW

BBEWBWW

BBWBEWW

BWEBBWW

BBWEBWW

BWWBBEW

BWWBEBW

BWWWEBBW

EWWBBBW

WWEBBBW

WWBEBBW

WWBBEBW

WWBBBEW

WWBBBWE

WWBBEWB

WWBBWEB

WWBEWBB

WWBWEBB

WWEWBBB

WWWEBBB

WWWBEBB

WWWBBEB

WWWBBBE

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)