在Graph Prolog中查找具有最大后代的节点

时间:2018-06-12 05:48:24

标签: graph prolog descendant

我尝试在图中找到具有最高后代数的节点。我有以下代码:

descendant(X,Y) :- parent(X,Y).
descendant(X,Y) :- parent(X,Z), descendant(Z,Y).
descendants(X, L) :- findall(A, descendant(X,A), L).


max_descendant(X, L, Len, Max) :-
    N is 0,!,
    node(X), descendants(X, L),
    length(L, Len), Len > N, Max = [X].

我仍然混淆了如何设置Max变量。 有什么想法解决这个问题吗?提前谢谢。

0 个答案:

没有答案