Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best First Search

Status
Not open for further replies.

thestonefox

Technical User
Mar 14, 2003
2
GB
Can anybody help me on how to implement a best first search method in keylink prolog.

Ive found countless examples of how to actually code the best first search but nothing on how to actually put it to any use.

The problem i have is as follows:-

Take a word (e.g. code) and via best first search change each letter of the given word into the second given word (e.g. mark)

so you would enter something like:-

words(code,mark).

and the output would be:-

code,mode,made,mare,mark

How would i implement any best first search method to do something like this?

any help would be greatly appreciated.

Also any good advice on how to draw Finite State Transition Networks would be of much appreciation too.

Kindest Regards
 
well actually i dont know anything about first search but i tried to make a program that does what u want.

I use SWI-Prolog so i am not sure if it works for u. It needs 3 built-in predicates:
sub_atom, atom_concat and atom_length


first_search(Word1,Word2,Result) :- fs(Word1,Word2,1,Result).

fs(Word1,_,_,Word1).
fs(Word1,Word2,Akk,Result) :-
atom_length(Word2,L),
Akk =< L,
sub_atom(Word1,Akk,_,0,SubWord1),
sub_atom(Word2,0,Akk,_,SubWord2),
atom_concat(SubWord2,SubWord1,NewWord),
NewAkk is Akk+1,
fs(NewWords,Word2,NewAkk,Result).



for the instanciation first_search(code,mark,X). the programm would proceed as follows:

X=code; (press ; for alternates),
X=mode;
X=made;
X=mare;
X=mark;
no

if u want to have a list of all teh solutions u can use findall

findall(X,first_search(code,mark,X),Result).

this would give Result=[code,mode,made,mare,mark]


this little programm only works for 2 words of the same length. but it wouldnt be hard to change it so it can deal with words of different length. i just didnt know how u want to use it and if it is what u were asking for
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top