Bfs prolog程序

时间:2016-05-06 19:08:29

标签: prolog breadth-first-search

这是一个BFS prolog程序,当我在sol中更改目标时,没有任何反应,显示与rest value相同的结果。是否正确?

   domains
       l=integer x=integer
   predicates
       nondeterm breadthfirst(l,l,l)
       nondeterm sol (x,l)
       nondeterm edge(x,l) 
   clauses
       edge(1,[2,3]).
       edge(2,[4,7]).
       edge(3,[5,6]).
       edge(4,[8,9]).
       edge(7,[]).
       edge(8,[]).
       edge(9,[]).
       edge(5,[]).
       edge(6,[]).

       breadthfirst([], List, List).
       breadthfirst([H|L1], List, [H|L3]) :- 
           breadthfirst(L1, List, L3).

       sol(X, [F|T]) :-
           edge(F, Y),
           breadthfirst(T, Y, Z),
           write(F, Z), nl,
           sol(X, Z).
   goal 
       sol(9, [1]).

0 个答案:

没有答案