Re: about a prolog breadth-first exercises
- From: Btsw <qixianming@xxxxxxxxx>
- Date: Sun, 15 Jul 2007 18:02:50 -0000
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~!
.
- Follow-Ups:
- Re: about a prolog breadth-first exercises
- From: Cesar Rabak
- Re: about a prolog breadth-first exercises
- References:
- about a prolog breadth-first exercises
- From: Btsw
- Re: about a prolog breadth-first exercises
- From: Cesar Rabak
- about a prolog breadth-first exercises
- Prev by Date: Re: about a prolog breadth-first exercises
- Next by Date: Re: about a prolog breadth-first exercises
- Previous by thread: Re: about a prolog breadth-first exercises
- Next by thread: Re: about a prolog breadth-first exercises
- Index(es):
Relevant Pages
|
|