Exemple #1
0
def get_vertexcover_scp(graph=None, k=3, min_nodes=20):
    if graph == None:
        graph = get_graph()
    comus = scp.communities_scp(graph, k, min_nodes)

    idset = set()
    for ids in comus:
        idset.update(ids)
    sg = graph.subgraph(idset)
    sg.vs['weight'] = sg.pagerank()

    comu_names = scp.comuid2name(graph, comus)
    comu_ids = scp.comuname2id(sg, comu_names)
    cover = VertexCover(sg, comu_ids)

    ccp = ClusterColoringPalette(len(cover))
    #cls = ['black','gray','blue','green','white' ,'Maroon']
    for i, cluster in enumerate(cover):
        vlist = [v for v in sg.vs.select(cluster)]
        vlist.sort(key=lambda v: v['weight'], reverse=True)
        for v in vlist:
            try:
                v['color'] = ccp[i]
            except:
                v['color'] = ccp[i]
        for v in vlist[0:4]:
            v['label'] = v['name'].encode('utf8')
            #v['lable_cex'] = 1.5
            v['label_color'] = 'black'

    return cover
Exemple #2
0
def get_vertexcover_scp(graph=None, k=3, min_nodes=20):
    if graph == None:
        graph = get_graph()
    comus = scp.communities_scp(graph,k,min_nodes)
    
    idset = set()
    for ids in comus:
        idset.update(ids)
    sg = graph.subgraph(idset)
    sg.vs['weight'] = sg.pagerank()
    
    comu_names = scp.comuid2name(graph, comus)
    comu_ids = scp.comuname2id(sg,comu_names)
    cover = VertexCover(sg,comu_ids)

    ccp = ClusterColoringPalette(len(cover))
    #cls = ['black','gray','blue','green','white' ,'Maroon']
    for i,cluster in enumerate(cover):
         vlist = [v for v in sg.vs.select(cluster)]
         vlist.sort(key=lambda v:v['weight'], reverse=True)
         for v in vlist:
             try:
                 v['color'] = ccp[i]
             except:
                 v['color'] = ccp[i]
         for v in vlist[0:4]:
             v['label'] = v['name'].encode('utf8')
             #v['lable_cex'] = 1.5
             v['label_color'] = 'black'

    return cover
Exemple #3
0
def write_communities_scp(graph, filename):
    comus = scp.communities_scp(graph, 3, 10)
    comu_names = scp.comuid2name(graph, comus)
    f = open(filename)
    for com in comu_names:
        s = ' '.join(com) + '\r\n'
        f.write(s.encode('gb18030'))
    f.close()
Exemple #4
0
def write_communities_scp(graph, filename):
    comus = scp.communities_scp(graph,3,10)
    comu_names = scp.comuid2name(graph, comus)
    f = open(filename)
    for com in comu_names:
        s = ' '.join(com) + '\r\n'
        f.write(s.encode('gb18030'))
    f.close()
Exemple #5
0
def get_vertexcover_scp(graph):
    comus = scp.communities_scp(graph, 3, 10)
    comu_names = scp.comuid2name(graph, comus)
    nameset = set()
    for names in comu_names:
        nameset.update(names)
    sg = graph.subgraph(nameset)
    comu_ids = scp.comuname2id(sg, comu_names)
    cover = VertexCover(sg, comu_ids)

    return cover
Exemple #6
0
def get_vertexcover_scp(graph):
    comus = scp.communities_scp(graph,3,10)
    comu_names = scp.comuid2name(graph, comus)
    nameset = set()
    for names in comu_names:
        nameset.update(names)
    sg = graph.subgraph(nameset)
    comu_ids = scp.comuname2id(sg,comu_names)
    cover = VertexCover(sg,comu_ids)

    return cover
Exemple #7
0
 def detect(self, graph):
     import scp
     return scp.communities_scp(graph, self.k, self.min_nodes)