我尝试在图中找到具有最高后代数的节点。我有以下代码:
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变量。 有什么想法解决这个问题吗?提前谢谢。