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

arc(a、b)。arc(a、c)。arc(b、d)。arc(b、e)。arc(c、f)。arc(f、g)。arc(e、z)。arc(d、e)。arc(z、g)。arc(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 に答える