Re: More on Aggregation Predicates
- From: "Drew" <drewscogin@xxxxxxxxx>
- Date: 10 Oct 2006 07:58:42 -0700
This gives me [a] as the result, but what i am trying is to get the
list of nodes between two nodes say on giving x,y it shld give 'a' as
the result.As both x and y are connected through 'a' .
If i give x and z it should return [a,b] as the result.I tried like
findall(X, links(x,y), S). no result is shown.
Can anyone help me to get this , i googled up more but no result so
far.
I have two programs that may help.
This one finds more than one path between two nodes. "Arc" is the list
of facts that connect one node to another. To find a node, enter
path(a,b) or whatever path you are trying to find
/*****************************************
:- dynamic found/1.
arc(g,h).
arc(d,a).
arc(g,d).
arc(e,d).
arc(h,f).
arc(e,f).
arc(a,e).
arc(a,b).
arc(b,f).
arc(b,c).
arc(f,c).
legal(Z,[]).
legal(Z,[H|T]):- Z \= H, legal(Z,T).
path_worker(X,Y,Visited):- arc(X,Y),\+found(Y),assert(found(Y)).
path_worker(X,Y,Visited):-
arc(X,Z),legal(Z,Visited),path_worker(Z,Y,[Z|Visited]).
path(X,Y):- path_worker(X,Y,[X]).
/*****************************************
If this one doesn't work, look here for more examples:
http://sc0g.com/college/CS310
.
- References:
- More on Aggregation Predicates
- From: vishy
- More on Aggregation Predicates
- Prev by Date: Word Count Problem in Prolog
- Next by Date: Re: SWI-Prolog : "safe" atom_number?
- Previous by thread: More on Aggregation Predicates
- Next by thread: Word Count Problem in Prolog
- Index(es):