I have a knowledge base of this type:
connect(a, b).
connect(a, d).
connect(a, e).
connect(b, a).
connect(b, c).
...
My objective is, given an origin and a destiny, to go through all the existing nodes once, before reaching the final node.
So far this is what I have got:
path(O, D, L):-
path(O, D, [O], L).
path(D, D, _, [D]).
path(O, D, A, [O|T]):-
connect(O, I),
\+ member(I, A),
path(I, D, [I|A], T).
In order to deal with the double connections e.g. connect(a, b). connect(b, a).
I use a list that saves every node I go through and before going into the recursion call I make sure that the node I am going to does not belong in that list.
Now I need to make sure that I go through all the existing nodes before reaching the final one. I have absolutely no idea how to even approach this. How can I ever be sure that I visited all the other nodes before reaching the last one?