def __init__(self, moral): Graph.__init__(self, moral.nodes) heap = GraphUtilities.ClusterBinaryHeap() # Copy the graph so that we can destroy the copy as we insert it into heap. # Deep copy isn't working, need to trace down bug but for now use hack. for i, node in enumerate(moral.deep_copy_nodes()): heap.insert(node) inducedCliques = [] nodes = list(self.nodes) # Want nodes in their index order nodes.sort for (node, edges) in heap: realnode = nodes[node.index] for edge in edges: # We need to make sure we reference the nodes in the actual graph, # not the copied ones that were inserted into the heap. node1 = nodes[edge[0].index] node2 = nodes[edge[1].index] self.connect_nodes(node1, node2) clique = Clique(realnode.neighbors.union([realnode])) # We only add clique to inducedCliques if is not contained in a previously added clique GraphUtilities.addClique(inducedCliques, clique) self.cliques = inducedCliques