Tuesday, July 3, 2007

BREADTH FIRST SEARCH with dynamic entries

domains
node = symbol
path=symbol*

database
edge(node,node)
final(node)

predicates
solve(node,path)
depth(path,node,path)
member(node,path)
go

clauses
member(X,[X|_]).
member(X,[_|T]):-
member(X,T).
solve(Node,Solution):-
depth([],Node,Solution).
depth(Path,Node,[Node|Path]):-
final(Node).
depth(Path,Node,Solution):-
edge(Node,Node1),
not(member(Node1,Path)),
depth([Node|Path],Node1,Solution).


go:-
write("enter node1"),nl,
readln(N1),nl,
write("enter node2"),nl,
readln(N2),nl,
assert(edge(N1,N2)),
write("enter y to continue or press n"),nl,
readchar(S),S='y',
go.

go:-
write("enter final node "),nl,
readln(F),nl,
assert(final(F)),nl,
write("Enter node from which to traverse"),nl,
readln(T),nl,
solve(T,Path),
write(Path),nl.


goal
go.

1 comment:

Unknown said...

hay buddy its really nice thnks