任何人都可以告诉我,在网络上我可以找到Bron-Kerbosch算法的解释,为clique找到或解释它是如何工作的?
我知道它发表在“算法457:找到无向图的所有派系”一书中,但我找不到能描述算法的自由源。
我不需要算法的源代码,我需要解释它是如何工作的。
任何人都可以告诉我,在网络上我可以找到Bron-Kerbosch算法的解释,为clique找到或解释它是如何工作的?
我知道它发表在“算法457:找到无向图的所有派系”一书中,但我找不到能描述算法的自由源。
我不需要算法的源代码,我需要解释它是如何工作的。
尝试找一个拥有ACM学生帐户的人,他可以给你一份论文副本,在这里: http://portal.acm.org/citation.cfm?doid=362342.362367
我刚刚下载了它,它只有两页长,在Algol 60中有一个实现!
我在这里找到了算法的解释: http://www.dfki.de/~neumann/ie-seminar/presentations/finding_cliques.pdf 这是一个很好的解释......但我需要一个C#中的库或实现 - .-'
算法正确 这里 我使用Java链接列表重写它作为集合R,P,X并且它可以工作 喜欢魅力(好的是在根据算法进行设置操作时使用函数“retainAll”)。
由于重写算法时的优化问题,我建议您稍微考虑一下实现
我还试图围绕Bron-Kerbosch算法,所以我在python中编写了自己的实现。它包括一个测试用例和一些注释。希望这可以帮助。
class Node(object):
def __init__(self, name):
self.name = name
self.neighbors = []
def __repr__(self):
return self.name
A = Node('A')
B = Node('B')
C = Node('C')
D = Node('D')
E = Node('E')
A.neighbors = [B, C]
B.neighbors = [A, C]
C.neighbors = [A, B, D]
D.neighbors = [C, E]
E.neighbors = [D]
all_nodes = [A, B, C, D, E]
def find_cliques(potential_clique=[], remaining_nodes=[], skip_nodes=[], depth=0):
# To understand the flow better, uncomment this:
# print (' ' * depth), 'potential_clique:', potential_clique, 'remaining_nodes:', remaining_nodes, 'skip_nodes:', skip_nodes
if len(remaining_nodes) == 0 and len(skip_nodes) == 0:
print 'This is a clique:', potential_clique
return
for node in remaining_nodes:
# Try adding the node to the current potential_clique to see if we can make it work.
new_potential_clique = potential_clique + [node]
new_remaining_nodes = [n for n in remaining_nodes if n in node.neighbors]
new_skip_list = [n for n in skip_nodes if n in node.neighbors]
find_cliques(new_potential_clique, new_remaining_nodes, new_skip_list, depth + 1)
# We're done considering this node. If there was a way to form a clique with it, we
# already discovered its maximal clique in the recursive call above. So, go ahead
# and remove it from the list of remaining nodes and add it to the skip list.
remaining_nodes.remove(node)
skip_nodes.append(node)
find_cliques(remaining_nodes=all_nodes)
为了它的价值,我发现了一个Java实现: http://joelib.cvs.sourceforge.net/joelib/joelib2/src/joelib2/algo/clique/BronKerbosch.java?view=markup
HTH。
我已经实现了论文中指定的两个版本。我了解到,未经优化的版本,如果递归求解,有助于理解算法。 这是版本1的python实现(未优化):
def bron(compsub, _not, candidates, graph, cliques):
if len(candidates) == 0 and len(_not) == 0:
cliques.append(tuple(compsub))
return
if len(candidates) == 0: return
sel = candidates[0]
candidates.remove(sel)
newCandidates = removeDisconnected(candidates, sel, graph)
newNot = removeDisconnected(_not, sel, graph)
compsub.append(sel)
bron(compsub, newNot, newCandidates, graph, cliques)
compsub.remove(sel)
_not.append(sel)
bron(compsub, _not, candidates, graph, cliques)
然后你调用这个函数:
graph = # 2x2 boolean matrix
cliques = []
bron([], [], graph, cliques)
变量 cliques
将包含发现的派系。
一旦理解了这一点,就可以轻松实现优化的一个。
Boost :: Graph具有出色的Bron-Kerbosh算法实现,请给它一个检查。