任何人都可以告诉我,在网络上我可以找到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)

我已经实现了论文中指定的两个版本。我了解到,未经优化的版本,如果递归求解,有助于理解算法。 这是版本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算法实现,请给它一个检查。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top