users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Need advice for path research


From: Gurvan Le Guernic
Subject: Need advice for path research
Date: Tue, 6 Jun 2006 18:48:53 +0200 (CEST)
User-agent: SquirrelMail/1.4.6

   Hi,

I have a graph described using predicates similar to: rel(node1,node2).

For example, the graph a-b-c is described as follow:
rel(a,b).
rel(b,c).

 I want to code a predicate given all path without cycles from a given
node to another one.
 A simple implementation (not taking care of cycles) would be:
path(From, To, [From, To]) :- rel(From, To).
path(From, To, [From | Tail]) :-
   rel(From, Intermediate),
   path(Intermediate, To, Tail).

 How would you prevent an element to appear twice in the path?
 I tried to play with \= and \== but I don't really know how to use them
before having the final path. If I wait to check that elements do not
appear twice in possible paths, gprolog goes out of memory.

   Thanks for your help,
   Gurvan Le Guernic





reply via email to

[Prev in Thread] Current Thread [Next in Thread]