Discussions related to Visual Prolog
aya eltokhy
Posts: 1
Joined: 28 Feb 2014 17:28

depth first search problem

Unread post by aya eltokhy »

I wrote the following Prolog code for depth first search:

Code: Select all

domains           sl=symbol* predicates         nondeterm parent(symbol,symbol)         nondeterm getChildren(symbol,sl,sl)         nondeterm member(symbol,sl)         nondeterm add(sl,sl,sl,sl)         nondeterm dfs(sl,sl,symbol) clauses         parent(a,b).         parent(a,c).         parent(a,d).         parent(b,e).         parent(b,f).         parent(c,f).         parent(c,g).         parent(e,h).         parent(e,i).         parent(f,j).                         dfs(OPEN,CLOSE,END):-                         OPEN=[],!,fail                         ;                         OPEN=[X|_],X=END,!,true                         ;                         getChildren(X,[],ChL),CLOSE2=[X|CLOSE],add(ChL,OPEN,CLOSE2,OPENF),                         dfs(OPENF,CLOSE2,END).                 getChildren(X1,ChL,ChLF):-                 parent(X1,Ch),not(member(Ch,ChL)),!,ChL2=[Ch|ChL],                 getChildren(X1,ChL2,ChLF)                 ;                 ChLF=ChL.                                         member(X,[X|_]).         member(X,[_|T]):-                 member(X,T).                                         add([],OPEN,_,OPENF):-OPENF=OPEN,!.         add(ChL,OPEN,CLOSE,OPENF):-                 ChL=[H|T],not(member(H,OPEN)),not(member(H,CLOSE)),!,                 OPEN2=[H|OPEN],add(T,OPEN2,CLOSE,OPENF)                 ;                 ChL=[_|T],add(T,OPEN,CLOSE,OPENF).           goal         %getChildren(a,[],CHLF).         dfs([a],[],b).


However, I get the following error:

the variable is not bounded in this clause X
User avatar
George
Active Member
Posts: 47
Joined: 19 Sep 2011 8:54

Unread post by George »

#1 : it is not the latest prolog version
#2 : try to avoid if -else statement for old prolog version..
#3 : instead, use backtracking - this will avoid this kind of issue..
#4 : for any personal support, send a email to : Georgeananth.prolog@gmail
Kind Regards,
George Ananth. S | Prolog Developer
georgeananth.prolog@gmail.com
+91 9791499282
Post Reply