source: liacs/cvp/prolog/assignment1.pro@ 4

Last change on this file since 4 was 2, checked in by Rick van der Zwet, 15 years ago

Initial import of data of old repository ('data') worth keeping (e.g. tracking
means of URL access statistics)

  • Property svn:executable set to *
File size: 1.2 KB
Line 
1#!/usr/bin/env swipl -s
2
3/*
4 * Rick van der Zwet
5 * 0433373
6 * Prolog programming assigment 1
7 * Licence: BSD
8 * $Id: assignment1.pro 299 2007-11-08 00:10:31Z rick $
9 */
10
11/* final call, [X,Y] member of Graph */
12trans_dag(X, Y, Graph) :-
13 member([X,Y], Graph).
14
15/* Find all nodes which are findable from X */
16trans_dag(X, Y, Graph) :-
17 member([X,Z], Graph),
18 trans_dag(Z, Y, Graph).
19
20/* final call, [X,Y] member of Graph, do note initial path is set []
21 * over here */
22trans(X, Y, Graph, _, []) :-
23 member([X,Y], Graph).
24
25/* Find all nodes which are findable from X, but where
26 * passed node is not member of Avoid, to avoid cycles
27 * Path is constructed just the other way around
28 */
29trans(X, Y, Graph, Avoid, Path) :-
30 not(member(X, Avoid)),
31 member([X,Z], Graph),
32 Path=[Z|PathTail],
33 AvoidAdded=[X|Avoid],
34 trans(Z, Y, Graph, AvoidAdded, PathTail).
35
36/* init trans to trans 'system' call, which just ignored the Path and
37 * makes the Avoid list starting []
38 */
39trans(X, Y, Graph) :-
40 trans(X, Y, Graph, [], _).
41
42
43/* init trans to path 'system' call
44 * makes the Avoid list starting []
45 */
46path(X, Y, Graph, Path) :-
47 trans(X, Y, Graph, [], Path).
Note: See TracBrowser for help on using the repository browser.