Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Standard view
Full view
of .
Look up keyword
Like this
0 of .
Results for:
No results containing your search query
P. 1
Lab 4 Best First Heuristic Search

Lab 4 Best First Heuristic Search

Ratings: (0)|Views: 252 |Likes:
Published by chakravarthyashok

More info:

Published by: chakravarthyashok on Apr 21, 2010
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less





EA C461 (ArtificialIntelligence)
Lab 4:
Best-First HeuristicSearch
Prepared By:
Dr. Mukesh Kumar Rohilrohil@bits-pilani.ac.inThis Lab is based on the book by Ivan Bratko, Prolog Programming for Artificial Intelligence, ThirdEdition, 2001, Pearson Education Ltd., Second Impression 2007 (in India).Given the heuristic function f(n) = g(n) + h(n), where g(n) is an estimate of the cost of an optimal pathfrom starting node, s, to current node, n, and h(n) is an estimate of the cost of an optimal path fromnode n to the goal node t.When node n is encountered by the search process we have following situation: a path from s to nmust have already been found and its cost can be computed as the sum of the arc-costs on the path. Itmay not be optimal cost but its cost can serve as an estimate g(n) of the minimal cost from s to n.Theother term, h(n), is more problematic because the ‘world’ between n and t has not been explored by thesearch until this point. Therefore, h(n) is typically is real heuristic guess, based on the algorithm’sgeneral knowledge about the particular problem.Starting with the start node, the search keeps generating new successor nodes, always expanding in themost promising direction according to the f-values. During this process, a search tree is generatedwhose root is the start node of the search. The best-first search program will thus kep expanding thissearch tree until a solution is found. This tree will be represented in the program by terms of twoforms:1.l(N, F/G) represents a single node tree (a leaf); N is a node in the state space, G is g(N) (cost of the path found from the start node to N); F is f(N) = G + h(N).2.t(N, F/G, Subs) represents a tree with non-empty subtree; N is the root of the tree, Subs is a listof its subtrees; G is g(N); F is updated f-value of N – that is, the f-value of the most promisingsuccessor of N; the list Subs is ordered according to increasing f-values of the sub-trees. The updating of the f-values is necessary to enable the program to recognize the most promisingsubtree at each level of the search tree. This modification of f-estimates lead, in fact, to a function f from nodes to tree. For a single node tree (a leaf), n, we have the original definition of f(n) i.e. f(n) =g(n) + h(n). For a tree, T, hose root is n, and n’s subtrees are S
, S
, etc., f(T) = min
).A best-first program along these lines is shown in Table 1. Some more explanation of this programfollows.The key procedure is expand, which has six arguments:expand(P, Tree, Bound, Tree1, Solved, Solution).It expands a current (sub)tree as long as the f-value of this tree remains less or equal to Bound. Thearguments of expand are given in Table 2.P, Tree and Bound are ‘input’ parameters to expand. Expand produces three kinds of results which isindicated by the value of the argument Solved as follows:
(1). Solved = yes.Solution = a solution path found by expanding Tree within Bound.Tree1 = uninstantiated.(2). Solved = no.Solution = Tree expanded so that its f-value exceeds Bound.Tree1 = uninstantiated.(3). Solved = never.Solution and Tree1 = uninstantiated.A Prolog program (based on the best first search) to solve 8-puzzle problem is given in Table 3.However, some predicates need more clauses to be added.
Do the following:
1.Apply the Best-first search (Table 2) tosolve the routing problem (as given inFig. 1) to find the shortest path fromnode s to node t.2.Find the time taken by the method tofind the shortest path for problem 1above. [Hint: Read and Use time/2 predicate given in the LPA Win-Prolog help]3.Comparing the program in Table 1and Table 3, make a table of predicatesof Table 1 and Table 3 by statingwhich predicate(s) in Table 3 does theanalogous or similar work of which predicate(s) in Table 1.4.The Table 3 (Best-first search appliedto 8-puzzle problem) does not have some clauses of some predicate. Completethose and run the program for five initial conditions to reach to the goal state.The goal state is given in Fig. 2.5.Name your files as L4_AI_YourID_pN and zip them as L4_AI_YourID.zip andtransmit to instructor’s email id. Replace the text YourID by your BITSIDNumber and N in pN by problem number 1, 2, 3, or 4 as the case may be.
Figure 1: A routing network [The numbers alongarcs are g(n) and numbers in square are h(n)]
Figure 2
% A best-first search program.% bestfirst( Start, Solution): Solution is a path from Start to a goalbestfirst( Start, Solution) :-  expand( [], l( Start, 0/0), 9999,  _ , yes, Solution). % Assume 9999 is greater than any f-value% expand( Path, Tree, Bound, Tree1, Solved, Solution):% Path is path between start node of search and subtree Tree,% Tree1 is Tree expanded within Bound,% if goal found then Solution is solution path and Solved = yes% Case 1: goal leaf-node, construct a solution pathexpand( P, l( N,  _ ),  _ ,  _ , yes, [N|P]) :-  goal(N). % Case 2: leaf-node, f-value less than Bound% Generate successors and expand them within Bound.expand( P, l(N,F/G), Bound, Tree1, Solved, Sol) :-  F =< Bound,  ( bagof ( M/C, ( s(N,M,C), not member (M,P) ), Succ),  !,% Node N has successors succlist( G, Succ, Ts),% Make subtrees Ts  bestf ( Ts, F1),% f-value of best successor   expand( P, t(N,F1/G,Ts), Bound, Tree1, Solved, Sol)  ; Solved = never % N has no successors - dead end  ) . % Case 3: non-leaf, f-value less than Bound% Expand the most promising subtree; depending on% results, procedure continue will decide how to proceedexpand( P, t(N,F/G,[T|Ts]), Bound, Tree1, Solved, Sol) :-F =< Bound,bestf( Ts, BF), min( Bound, BF, Bound1), % Bound1 = min(Bound,BF)

Activity (3)

You've already reviewed this. Edit your review.
1 thousand reads
1 hundred reads
Raneen Dawood liked this

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->