补图 - Prolog

3

我有一个问题。我有一个连续的无向图。因此,我需要在Prolog中编写一段代码来给出补充图。

例如图示:

edge(1,2).
edge(2,3).
edge(3,4).
edge(4,5).
edge(5,1).

rot(X,Y):- edge(X,Y).
rot(X,Y):- edge(Y,X).

请帮忙 :) 谢谢。

1个回答

0
这应该适用于发出地面查询以及枚举所有可能的边缘。
complement(X, Y):-
  ((var(X);var(Y)) -> setof(V, Z^rot(V,Z), Vertices);true), % If either vertex is not ground, compute the set of vertices
  (ground(X) -> (once(rot(X, _)), VerticesX=[X]) ; VerticesX=Vertices), % Determine list of candidate X
  (ground(Y) -> (once(rot(Y, _)), VerticesY=[Y]) ; VerticesY=Vertices), % and candidate Y
  member(X, VerticesX),
  member(Y, VerticesY),
  X \= Y,        % Generate and test all
  \+(rot(X,Y)).  % possible candidates

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接