0
start(b1).
end(b6).

edge(b1,b2).
edge(b1,b6).
edge(b2,b3).
edge(b2,b4).
edge(b3,b5).
edge(b4,b5).
edge(b5,b1).

constraint(b5,2).

Task: The predicate path (X, Y, V, P) is now used to determine paths that go from a node X to Y. Cycles should not be avoided entirely - instead, loop loops should be used constraint (K, N) each node K only appear at most N times in the path, if this is restricted accordingly. The determined paths should be complete and in the correct order. To simplify matters, it can be assumed that X is always a start node and Y is an end node. Example query / output:

?- path(b1,b6,[],P).
P = [b1, b6] ;
P = [b1, b2, b3, b5, b1, b6] ;
P = [b1, b2, b3, b5, b1, b2, b3, b5, b1|...] ;
P = [b1, b2, b3, b5, b1, b2, b4, b5, b1|...] ;
P = [b1, b2, b4, b5, b1, b6]
....

My hopeless attempt :

path(X,Y,[H|T],P) :-
   edge(X,Z), count(Z,[H|T],M), constraint(M,2), path(Z,Y,[X|T],P).

I believe that I am on the right way, but I have no base case.

Hope someone knows the way to go?

false
  • 10,264
  • 13
  • 101
  • 209
katarina
  • 33
  • 3
  • Where does this loop constraint come from? – false Mar 10 '20 at 09:43
  • Should you decide to opt for an acyclic path, use: [this](https://stackoverflow.com/q/30328433/772868). You miight take this as a starting point and insert cycles thereafter – false Mar 10 '20 at 09:48

0 Answers0