1

Markus Triska has reported an algorithm to determine strongly connected components (SCC). Is there a solution which determines the SCC without making use of attributed variable and that can work anytime. So that some vertices can have infinitely many edges?

I am asking because I am wondering whether B-Prologs anytime tabling which they call eager can be replicated. B-Prolog determines clusters which is their name for SCC. But it has also a tabling mode where it returns tabled results eagerly.

4

1 回答 1

-1

我猜这个算法符合要求,因为只要稍加修改,它就可以在根中获得无限度数。这是所有边都指向有限多个顶点时的 SCC 算法:

% plan(+Atom, -Assoc)
plan(P, R) :-
  sccforpred(P, [], [], R, _).

% sccforpred(+Atom, +List, +Assoc, -Assoc, -List)
sccforpred(P, S, H, H, [P]) :-
  member(P, S), !.
sccforpred(P, _, H, H, []) :-
  member(Q-L, H), (Q = P; member(P, L)), !.
sccforpred(P, S, I, O2, R2) :-
  findall(Q, edge(P, Q), L),
  sccforlist(L, [P|S], I, O, R),
  (member(U, R), member(U, S) ->
      O2 = O, R2 = [P|R];
      O2 = [P-R|O], R2 = []).

% sccforlist(+List, +List, +Assoc, -Assoc, -List)
sccforlist([], _, H, H, []).
sccforlist([P|Q], S, I, O, R) :-
  sccforpred(P, S, I, H, R1),
  sccforlist(Q, S, H, O, R2),
  findall(U, (member(U, R1); member(U, R2)), K),
  sort(K, R).

使用此示例图:

在此处输入图像描述

我得到这个结果:

Jekejeke Prolog 4, Runtime Library 1.4.1 (August 20, 2019)

?- plan(21,X).
X = [21-[], 22-[22, 23], 26-[24, 25, 26], 27-[]]
于 2019-10-26T22:36:35.407 回答