【发布时间】:2014-11-21 16:17:15
【问题描述】:
我希望你能帮我解决这个问题。
我正在尝试学习 Prolog 中的深度优先搜索算法,我遇到了以下代码
go(Start, Goal) :-
empty_stack(Empty_been_list),
stack(Start, Empty_been_list, Been_list),
path(Start, Goal, Been_list).
% path implements a depth first search in PROLOG
% Current state = goal, print out been list
path(Goal, Goal, Been_list) :-
reverse_print_stack(Been_list).
path(State, Goal, Been_list) :-
mov(State, Next),
% not(unsafe(Next)),
not(member_stack(Next, Been_list)),
stack(Next, Been_list, New_been_list),
path(Next, Goal, New_been_list), !.
reverse_print_stack(S) :-
empty_stack(S).
reverse_print_stack(S) :-
stack(E, Rest, S),
reverse_print_stack(Rest),
write(E), nl.
我有点明白发生了什么,但我终其一生都无法找到或发明一些我可以使用的事实。
请帮忙。即使它是一组非常简单的事实,我只需要从某个地方开始
提前谢谢你
【问题讨论】:
-
Here 是此问题的通用解决方案。你直接说
closure0(mov,Start,Finis) -
请像其他谓词一样缩进
go -
我可能以错误的方式提出问题,因为我不理解错误的答案
-
@SeanGray:提供整个程序 - 包括
mov/2的一些事实。没有它,您的代码仍然是假设的。 -
这就是我要问的问题:D,我想知道我可以使用哪些事实。
标签: algorithm prolog depth-first-search transitive-closure