0
dfs([Node | OPEN], _ , Goal) :-  
Node==Goal, !,          
write('yes! goal reached.... ' - Goal), nl.         

dfs([Node | OPEN],CLOSED, Goal) :- 
  findall(                        Next,                 
  (
    arc(Node, Next),        Next
    not(member(Next, OPEN)),            not(member(Next, CLOSED))
      ), 
      NewNode               
     ), 

      append(NewNode, OPEN, NewOPEN),   
    write('OPEN = frontier of search...'), write(NewOPEN),nl,
    write('CLOSED = nodes already visited...'), write([Node | CLOSED]),nl,nl,
  dfs(NewOPEN, [Node | CLOSED], Goal).  % recurse with new data

弧(a,b)。弧(a,c)。弧(b,d)。弧(b,e)。弧(c,f)。弧(f,g)。弧(e,z)。弧(d,e)。弧(z,g)。弧(z,d)。

4

1 回答 1

0

像这样的东西:

dfs(Node, Goal) :- !.         

dfs(Node, Goal) :- 
    arc(Node, Next),
    score(Node, Next, S),
    not (score(Node, Next, S1), S1 > S), write(Next),
    dfs(Next, Goal).

然后您需要为每条弧线定义一个分数,例如 score(a, b, 3)。

于 2013-01-09T16:09:52.967 回答