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



_______________________________________________
Users-prolog mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/users-prolog

Reply via email to