/*--------------------------------------------------------------*/ 
/* Themis Panayiotopoulos, March 2018				*/ 
/* themis.panayiotopoulos3@gmail.com				*/
/* Artificial Intelligence and Virtual Reality Laboratory	*/
/* School of Information and Communication Technologies 	*/
/* Department of Informatics					*/
/* 8th Semester - Distributed Artificial Intelligence Course	*/
/* Pathfinder 1 : Directed Cyclic Graph				*/
/* as example query :						*/
/* ?- path(a,g,P).						*/
/*--------------------------------------------------------------*/

edge(a,b).
edge(b,c).
edge(b,d).
edge(b,e).
edge(c,f).
edge(d,g).
edge(e,g).
edge(f,g).
edge(f,a). % <- this produces a cycle


connected(X,Y) :- 
	edge(X,Y).
connected(X,Z) :- 
	edge(X,Y), 
	connected(Y,Z).

path(X,Y,[X,Y]) :- 
	edge(X,Y).
path(X,Z,[X|Path]) :- 
	edge(X,Y), 
	path(Y,Z,Path).

