Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :- dynamic(node/1).
- :- dynamic(edge/2).
- :- initialization(goal).
- process(node(X)) :- assertz(node(X)). %îê
- process(edge(X, Y)) :- assertz(edge(X, Y)). %îê
- process(_) :- write('Syntax Error!'), fail, !. %îê
- goal :- open('graph2.txt', read, F), load_graph(F), close(F), !, main.
- load_graph(F) :- at_end_of_stream(F) -> true; read(F, X), process(X), load_graph(F).
- writeBagOf :- bagof(Path, get_ham_path(Path), Ls), write(Ls).
- lenBagOf :- bagof(Path, get_ham_path(Path), Ls), length(Ls, T), write(T).
- main :- get_ham_path(Path), write(Path).
- get_ham_path(Path) :- path(A,_,Path), node(A), is_hamilt(Path).
- subpath(A, [A | P], [A | P]).
- subpath(A, [Y | P1], P) :- adjacent(X, Y), \+ member(X, P1), subpath(A, [X, Y | P1], P).
- path(A, Z, Path) :- subpath(A, [Z], Path).
- adjacent(X, Y) :- (edge(X, Y);edge(Y, X)).
- is_hamilt(P) :- \+ (node(A), \+ member(A,P)).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement