Friday, July 6, 2007

BNM

domains
node = symbol
path = symbol*
database
edge(node,node)
final(node)
predicates
solve(node,path)
depth(path,node,path)
go
member(node,path)
clauses
go:-
write("enter first node"),nl,
readln(N1),
write("enter second node"),nl,
readln(N2),
assert(edge(N1,N2)),nl,
write("do you wish to continue? 'y'/'n' "),nl,
readchar(D),
D='y',
go.
go:-
write("enter start node"),nl,
readln(P1),
write("enter final node"),nl,
readln(P2),
assert(final(P2)),nl,
solve(P2,Solution),nl,
write(Solution).
member(X,[X_]) .
member(X,[_T]) :-
member(X,T).
solve(Node,Solution) :-
depth([],Node,Solution).
depth(Path,Node,[NodePath]) :- final(Node).
depth(Path,Node,Solution) :- edge(Node,Node1),
not(member(Node1,Path)),
depth([NodePath],Node1,Solution).
goal go.

No comments: