about a prolog breadth-first exercises
- From: Btsw <qixianming@xxxxxxxxx>
- Date: Thu, 12 Jul 2007 09:35:18 -0000
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:
/*define successors first*/
successor(s,a).
successor(s,b).
successor(a,s).
successor(a,b).
successor(a,c).
successor(b,s).
successor(b,a).
successor(b,g).
successor(c,a).
successor(c,g).
successor(g,b).
successor(g,c).
/*define goal state*/
goalnode(g).
/*breadth first sarch*/
breadthfirst(Startnode,Solution_path) :-
bdsearch([Startnode],Solution_path).
bdsearch([Node|Path|_],[Node|Path]) :- goalnode(Node).
bdsearch([Node|Path],Solution_path) :-
expand(________,________), %expand the leftmost node
append(________,________,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(____,___),not(member(___,[Node|Path]))),New_paths),!.
expand(_,[]).
[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(_,[]).
.
- Follow-Ups:
- Re: about a prolog breadth-first exercises
- From: Cesar Rabak
- Re: about a prolog breadth-first exercises
- Prev by Date: Re: listing(+Pred, -Atom)
- Next by Date: Re: Floyd warshall
- Previous by thread: CFP 8th International Conference on Intelligent Data Engineering and Automated Learning (IDEAL'07)
- Next by thread: Re: about a prolog breadth-first exercises
- Index(es):