def subPartitionNx(self, graph):
		max_cover_clique_ls = cliques.find_cliques(graph)
		max_clique_index = numpy.argmax(map(len,max_cover_clique_ls))
		max_clique = max_cover_clique_ls[max_clique_index]
		self.clique_ls.append(max_clique)
		graph.delete_nodes_from(max_clique)
		if graph.number_of_nodes()==0:	#graph.size() is different, = number_of_edges()
			return
		else:
			self.subPartitionNx(graph)
예제 #2
0
 def subPartitionNx(self, graph):
     max_cover_clique_ls = cliques.find_cliques(graph)
     max_clique_index = numpy.argmax(map(len, max_cover_clique_ls))
     max_clique = max_cover_clique_ls[max_clique_index]
     self.clique_ls.append(max_clique)
     graph.delete_nodes_from(max_clique)
     if graph.number_of_nodes() == 0:  # graph.size() is different, = number_of_edges()
         return
     else:
         self.subPartitionNx(graph)
예제 #3
0
    def _processAgpat(self,sub,G):
        """
        Workhorse function for packing agpats.
        """
        # original 'agpat' edges
        oldEdges = [edge
                    for node in sub
                    for edge in G.out_edges(node) if edge[2]=='agpat']

        # find all possible agpat child pairs
        I = NX.Graph()
        # all nodes have to be present (some can be lone ones)
        for x in oldEdges:
            I.add_node(x[1])
        for (c,d) in Packer._makePairs([x[1] for x in oldEdges]):
            I.add_edge(c,d)

        # find all cliques
        # (sorted by size)
        cliques = C.find_cliques(I)
        newLen = reduce(lambda x,y:x+len(y), cliques, 0)
        
        # proceed if new grouping use less edges that the original
        # (rearrange edges)
        unchanged = True
        if newLen<len(oldEdges):
            # pick an edge for each child in each clique..
            edge_map = {}
            for clique in cliques:
                for node in clique:
                    if not edge_map.has_key(node):
                        edge_map[node] = []
                    current = [e for e in oldEdges if e[1]==node][0]
                    edge_map[node].append(current)
                    oldEdges.remove(current)
            # and remove unneeded edges
            for (a,b,c) in oldEdges:
                self.mapping.append( ('edge-delete',
                                      (a.node,b.node,c),
                                      '_packAgpat') )
                G.delete_edge(a,b,c)
            
            # pack each group..
            while cliques:
                children = cliques.pop(0)
                parent = sub.pop(0)
                # connect children to the parent
                for node in children:
                    (p1,p2,e) = edge_map[node].pop(0)
                    self.mapping.append( ('edge-move',
                                          (p1.node,p2.node,e),
                                          (parent.node,node.node,e),
                                          '_packAgpat') )
                    G.delete_edge(p1,p2,e)
                    G.add_edge(parent,node,e)
            # and remove unneeded parents
            for node in sub:
                self.mapping.append( ('node-delete',node.node,
                                      '_packAgpat') )
                G.delete_node(node)
            unchanged = False
        
        return(unchanged)
예제 #4
0
			pdb.set_trace()
		self.init()
		node_ls = self.order_nodes(graph)
		self.sub_max_clique(graph, node_ls, 0)

if __name__ == '__main__':
	import networkx as nx
	G=nx.Graph()
	G.add_edge(1,2)
	G.add_edge(2,3)
	G.add_edge(2,4)
	G.add_edge(2,5)
	G.add_edge(2,6)
	G.add_edge(4,6)
	#G.add_edge(7,8)
	#G.add_edge(3,4)
	#G.add_edge(3,6)
	clique_instance = clique(debug=1)
	clique_instance.max_clique(G)
	print 'max_clique_size:', clique_instance.max_clique_size
	print 'max_clique_ls:', clique_instance.max_clique_ls
	print 'nodes:', G.nodes()
	print 'degree:', G.degree()
	nx.draw(G)
	import pylab
	print 'the graph looks like this:'
	pylab.show()
	
	from networkx import cliques
	G_max_clique = cliques.find_cliques(G)
	print 'cliques found  by networkx:', G_max_clique
예제 #5
0
        self.init()
        node_ls = self.order_nodes(graph)
        self.sub_max_clique(graph, node_ls, 0)


if __name__ == '__main__':
    import networkx as nx
    G = nx.Graph()
    G.add_edge(1, 2)
    G.add_edge(2, 3)
    G.add_edge(2, 4)
    G.add_edge(2, 5)
    G.add_edge(2, 6)
    G.add_edge(4, 6)
    #G.add_edge(7,8)
    #G.add_edge(3,4)
    #G.add_edge(3,6)
    clique_instance = clique(debug=1)
    clique_instance.max_clique(G)
    print 'max_clique_size:', clique_instance.max_clique_size
    print 'max_clique_ls:', clique_instance.max_clique_ls
    print 'nodes:', G.nodes()
    print 'degree:', G.degree()
    nx.draw(G)
    import pylab
    print 'the graph looks like this:'
    pylab.show()

    from networkx import cliques
    G_max_clique = cliques.find_cliques(G)
    print 'cliques found  by networkx:', G_max_clique