Re: about a prolog breadth-first exercises



On Jul 13, 5:34 am, Cesar Rabak <csra...@xxxxxxxxxxxx> wrote:
Btsw escreveu:> hello, this is my exercises about a prolog breadth-first, i fill the
places, but it doesn't work, anybody can help me?
thanks.

[Exercises]Fill out places blank:

[snipped]





[My Answers]

/*breadth first sarch*/
breadthfirst(Startnode,Solution_path) :-
bdsearch([Startnode],Solution_path).

bdsearch([Node|Path|_],[Node|Path]) :- goalnode(Node).
bdsearch([Node|Path],Solution_path) :-
expand(Node,New_paths), %expand the leftmost node
append(Path,New_paths,New_paths), %add the children node to list
bdsearch(New_paths,Solution_path). %call bdsearch recursively

%define predicate expand
expand([Node|Path],New_paths):- bagof([X,Node|Path],
(successor(Node,X),not(member(X,[Node|Path]))),New_paths),!.
expand(_,[]).

Did you try to write what expand had to perform in plain text language
and then implement the specification in Prolog?- Hide quoted text -

- Show quoted text -

hoho,i find the bug out, in my source it has one line "bdsearch([Node|
Path|_],[Node|Path]) :- goalnode(Node)." fix it to "bdsearch([[Node|
Path]|_],[Node|Path]) :- goalnode(Node). " it be done~! thanks a lot~!

.



Relevant Pages