赞
踩
比如对于一个图g,它已经包含了{1,2}并且,我们知道它是按照1,2的顺序放入的,即最后放入的那个点是2,搜索原图所有的顶点,找到一个点x使得:2与x相连,x与g原先有的顶点相连(x与1相连)。那么对于图g的下一个图h就有{1,2,x}放入队列。继续寻找下一个顶点y。依次类推,直到队列为空。
BronKerbosch1(R, P, X):
if P and X are both empty:
report R as a maximal clique
for each vertex v in P:
BronKerbosch1(R ⋃ {v}, P ⋂ N(v), X ⋂ N(v))
P := P \ {v}
X := X ⋃ {v}
Procedure MaxCliqueDyn(R, C, level)
S[level] := S[level] + S[level−1] − Sold[level];
Sold[level] := S[level−1];
while R ≠ Ø do
choose a vertex p with maximum C(p) (last vertex) from R;
R := R\{p};
if |Q| + C[index of p in R] > |Qmax| then
Q := Q ⋃ {p};
if R ⋂ Γ(p) ≠ Ø then
if S[level]/ALL STEPS < Tlimit then
calculate the degrees of vertices in G(R ⋂ Γ(p));
sort vertices in R ⋂ Γ(p) in a descending order
with respect to their degrees;
end if
ColorSort(R ⋂ Γ(p), C')
S[level] := S[level] + 1;
ALL STEPS := ALL STEPS + 1;
MaxCliqueDyn(R ⋂ Γ(p), C', level + 1);
else if |Q| > |Qmax| then Qmax := Q;
Q := Q\{p};
else return
end while
代码大致流程 和BronKerbosch有相似之处,时间复杂度也是指数级别的
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。