예제 #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
예제 #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
예제 #3
0
def draw_vertexcluster(graph=None):
    import comdect, cairo
    graph = get_graph()

    lcd = comdect.LabelCommunityDetection(min_nodes=20)
    coms = lcd.detect(graph)

    idset = set()
    for ids in coms:
        idset.update(ids)
    sg = graph.subgraph(iter(idset))
    sg.vs['weight'] = sg.pagerank(directed=False, weights='weight')
    comu_names = scp.comuid2name(graph, coms)
    comu_ids = scp.comuname2id(sg, comu_names)
    membership = [0 for i in range(0, sg.vcount())]
    for idx, idset in enumerate(comu_ids):
        for vid in idset:
            membership[vid] = idx

    cluster = VertexClustering(sg, membership)
    ncluster = len(cluster)

    ccp = ClusterColoringPalette(ncluster)
    #cls = ['black','gray','blue','green','white' ,'Maroon']
    for i, c in enumerate(comu_ids):
        vlist = [v for v in sg.vs.select(c)]
        for v in vlist:
            try:
                v['color'] = ccp[i]
            except:
                v['color'] = ccp[i]
        topn = heapq.nlargest(5, vlist, key=lambda v: v['weight'])
        for v in topn:
            v['label'] = v['name'].encode('utf8')
            v['label_size'] = 14
            v['label_color'] = ccp[ncluster - i - 1]
    fig = Plot(background='white')

    #fig._ctx.set_font_face(face)
    fig._ctx.select_font_face('WenQuanYi Zen Hei', cairo.FONT_SLANT_NORMAL,
                              cairo.FONT_WEIGHT_NORMAL)

    fig.add(cluster,
            bbox=(600, 600),
            mark_groups=True,
            vertex_size=5,
            vertex_label_dist=2,
            edge_width=0.3,
            opacity=0.8)
    #print "font family ",fig._ctx.get_font_face().get_family()
    fig.show()
    fig.save()
    #print "font family ",fig._ctx.get_font_face().get_family()
    return fig
예제 #4
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
예제 #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
예제 #6
0
def draw_vertexcluster(graph=None):
    import comdect, cairo
    graph = get_graph()
   
    lcd = comdect.LabelCommunityDetection(min_nodes=20)
    coms = lcd.detect(graph)
 
    idset = set()
    for ids in coms:
        idset.update(ids)
    sg = graph.subgraph(iter(idset))
    sg.vs['weight'] = sg.pagerank(directed=False, weights='weight')    
    comu_names = scp.comuid2name(graph, coms)
    comu_ids = scp.comuname2id(sg,comu_names)
    membership = [0 for i in range(0,sg.vcount())]
    for idx,idset in enumerate(comu_ids):
        for vid in idset:
            membership[vid] = idx
    
    cluster = VertexClustering(sg, membership)
    ncluster = len(cluster)
    
    ccp = ClusterColoringPalette(ncluster)
    #cls = ['black','gray','blue','green','white' ,'Maroon']
    for i,c in enumerate(comu_ids):
        vlist = [v for v in sg.vs.select(c)]
        for v in vlist:
            try:
                v['color'] = ccp[i]
            except:
                v['color'] = ccp[i]
        topn = heapq.nlargest(5, vlist, key=lambda v:v['weight'])
        for v in topn:
            v['label'] = v['name'].encode('utf8')
            v['label_size'] = 14
            v['label_color'] = ccp[ncluster-i-1]
    fig = Plot(background='white')

    #fig._ctx.set_font_face(face)
    fig._ctx.select_font_face('WenQuanYi Zen Hei', cairo.FONT_SLANT_NORMAL,cairo.FONT_WEIGHT_NORMAL)
    
    fig.add(cluster,bbox=(600,600), mark_groups=True,vertex_size=5, vertex_label_dist=2, edge_width=0.3, opacity=0.8)
    #print "font family ",fig._ctx.get_font_face().get_family()
    fig.show()
    fig.save()
    #print "font family ",fig._ctx.get_font_face().get_family()
    return fig