Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This assignment asks you to apply the A search algorithm to the processing of propositional Prolog knowledge bases such as q: - a . q:

This assignment asks you to apply the A
search algorithm to the processing
of propositional Prolog knowledge bases such as
q:- a.
q:- b,c.
a:- d,e.
a:- c,e,f.
b:- c.
c:- e,f.
e.
f:- e.
which we can represent as the list
[[q,a],[q,b,c],[a,d,e],[a,c,e,f],[b,c],[c,e,f],[e],[f,e]]
and use as KB in the clauses
arc([H|T],Node,Cost,KB) :- member([H|B],KB), append(B,T,Node),
length(B,L), Cost is 1+ L/(L+1).
heuristic(Node,H) :- length(Node,H).
goal([]).
Your task is to define a predicate
astar(+Node,?Path,?Cost,+KB)
that implements A
, returning a path from Node to the goal node [] with
minimal cost, given KB. Test your code with queries such as
?- astar([q],Path,Cost,
[[q,a],[q,b,c],[a,d,e],[a,c,e,f],[b,c],[c,e,f],[e],[f,e]]).
Cost =11.916666666666668,
Path =[[q],[a],[c, e, f],[e, f, e, f],[f, e, f],[e, e, f],
[e, f],[f],[e],[]] ;
Cost =13.499999999999998,
Path =[[q],[b, c],[c, c],[e, f, c],[f, c],[e, c],[c],
[e, f],[f],[e],[]] ;
false
?- astar([q],Path,Cost,[[q,a],[q,b,c],[a],[b],[c]]).
Cost =2.5,
Path =[[q],[a],[]] ;
Cost =3.6666666666666665,
Path =[[q],[b, c],[c],[]] ;
false
Hint Modify the skeletal search algorithm
search([Node|_]) :- goal(Node).
search([Node|More]) :- findall(X,arc(Node,X),Children),
add2frontier(Children,More,New),
search(New).
so that the head of the list New obtained in add2frontier has f-value no
larger than any in News tail, where
f(node)= cost(node)+ h(node).
Let the frontier be a list of path-cost pairs (instead of just nodes), being
careful to update path costs, and to bring in the heuristic function in forming
the frontier New.
less-than([[Node1|_],Cost1],[[Node2|_],Cost2]) :-
heuristic(Node1,Hvalue1), heuristic(Node2,Hvalue2),
F1 is Cost1+Hvalue1, F2 is Cost2+Hvalue2,
F1=< F2.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2010 Barcelona Spain September 2010 Proceedings Part 2 Lnai 6322

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

364215882X, 978-3642158827

More Books

Students also viewed these Databases questions