Re: about a prolog breadth-first exercises



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?
.



Relevant Pages

  • Re: about a prolog breadth-first exercises
    ... Btsw escreveu: ... expand(Node,New_paths), %expand the leftmost node ... append, %add the children node to list ...
    (comp.lang.prolog)
  • Re: about a prolog breadth-first exercises
    ... expand, %expand the leftmost node ... append, %add the children node to list ... Did you try to write what expand had to perform in plain text language ... " it success! ...
    (comp.lang.prolog)
  • Re: about a prolog breadth-first exercises
    ... expand, %expand the leftmost node ... append, %add the children node to list ... Did you try to write what expand had to perform in plain text language ... hoho,i find the bug out, in my source it has one line "bdsearch([Node| ...
    (comp.lang.prolog)