-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfig21_9.pl
41 lines (30 loc) · 830 Bytes
/
fig21_9.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
% Figure 21.9 Learning about a path in a graph.
% Learning about path: path(StartNode,GoalNode,Path)
% A directed graph
link(a,b).
link(a,c).
link(b,c).
link(b,d).
link(d,e).
backliteral( link(X,Y), [ X:item], [ Y:item]).
backliteral( path(X,Y,L), [ X:item], [ Y:item, L:list]).
term( list, [X|L], [ X:item, L:list]).
term( list, [], []).
prolog_predicate( link(X,Y)).
start_clause( [ path(X,Y,L)] / [X:item,Y:item,L:list] ).
% Examples
ex( path( a, a, [a])).
ex( path( b, b, [b])).
ex( path( e, e, [e])).
ex( path( f, f, [f])).
ex( path( a, c, [a,c])).
ex( path( b, e, [b,d,e])).
ex( path( a, e, [a,b,d,e])).
nex( path( a, a, [])).
nex( path( a, a, [b])).
nex( path( a, a, [b,b])).
nex( path( e, d, [e,d])).
nex( path( a, d, [a,b,c])).
nex( path( a, c, [a])).
nex( path( a, c, [a,c,a,c])).
nex( path( a, d, [a,d])).