#!/usr/bin/env swipl -s /* * Rick van der Zwet * 0433373 * Prolog programming assigment 1 * Licence: BSD * $Id: assignment1.pro 299 2007-11-08 00:10:31Z rick $ */ /* final call, [X,Y] member of Graph */ trans_dag(X, Y, Graph) :- member([X,Y], Graph). /* Find all nodes which are findable from X */ trans_dag(X, Y, Graph) :- member([X,Z], Graph), trans_dag(Z, Y, Graph). /* final call, [X,Y] member of Graph, do note initial path is set [] * over here */ trans(X, Y, Graph, _, []) :- member([X,Y], Graph). /* Find all nodes which are findable from X, but where * passed node is not member of Avoid, to avoid cycles * Path is constructed just the other way around */ trans(X, Y, Graph, Avoid, Path) :- not(member(X, Avoid)), member([X,Z], Graph), Path=[Z|PathTail], AvoidAdded=[X|Avoid], trans(Z, Y, Graph, AvoidAdded, PathTail). /* init trans to trans 'system' call, which just ignored the Path and * makes the Avoid list starting [] */ trans(X, Y, Graph) :- trans(X, Y, Graph, [], _). /* init trans to path 'system' call * makes the Avoid list starting [] */ path(X, Y, Graph, Path) :- trans(X, Y, Graph, [], Path).