Beispiel #1
0
def get_single_seed_nature_community_once(nodes):
    global process_num
    if len(nodes) >= process_num:
        tem_list = get_betweenness_max_num(nodes, process_num)
    else:
        tem_list = get_betweenness_max_num(nodes, len(nodes))
    from SeedDrivenDete import get_all_cliques_by_nodes

    cliques = get_all_cliques_by_nodes(C, tem_list)
    pool_result = []
    if len(cliques) < process_num:
        process_num = len(cliques)
    pool = Pool(process_num)
    cli_len = len(cliques)
    group_list = split_list(cliques, process_num)

    for i in range(1, len(group_list), 2):
        group_list[i].reverse()

    for i in range(process_num):
        args = []
        for gr in group_list:
            if len(gr) > i:
                args.append(gr[i])
        args = (args,)
        # 		args=([cliques[j] for j in range(cli_len) if j%process_num==i],)
        print "args__________", args
        pool_result.append(pool.apply_async(process_f, args))

    pool.close()
    pool.join()

    communities = []
    for x in pool_result:
        communities = communities + x.get()
    print "finish single seed process___________________"

    return communities
def get_single_seed_nature_community_once(nodes):
    global process_num
    if len(nodes) >= process_num:
        tem_list = get_betweenness_max_num(nodes, process_num)
    else:
        tem_list = get_betweenness_max_num(nodes, len(nodes))
    from SeedDrivenDete import get_all_cliques_by_nodes
    cliques = get_all_cliques_by_nodes(C, tem_list)
    pool_result = []
    if len(cliques) < process_num:
        process_num = len(cliques)
    pool = Pool(process_num)
    cli_len = len(cliques)
    group_list = split_list(cliques, process_num)

    for i in range(1, len(group_list), 2):
        group_list[i].reverse()

    for i in range(process_num):
        args = []
        for gr in group_list:
            if len(gr) > i:
                args.append(gr[i])
        args = (args, )
        #		args=([cliques[j] for j in range(cli_len) if j%process_num==i],)
        print "args__________", args
        pool_result.append(pool.apply_async(process_f, args))

    pool.close()
    pool.join()

    communities = []
    for x in pool_result:
        communities = communities + x.get()
    print "finish single seed process___________________"

    return communities
Beispiel #3
0
def get_all_nature_community(cliques):
    pool_result = []
    global process_num
    if len(cliques) < process_num:
        process_num = len(cliques)

    pool = Pool(process_num)
    cli_len = len(cliques)

    group_list = split_list(cliques, process_num)

    for i in range(1, len(group_list), 2):
        group_list[i].reverse()

    for i in range(process_num):
        args = []
        for gr in group_list:
            if len(gr) > i:
                args.append(gr[i])
        args = (args,)
        # 		args=([cliques[j] for j in range(cli_len) if j%process_num==i],)
        print "args__________", args
        pool_result.append(pool.apply_async(process_f, args))

    pool.close()
    pool.join()

    communities = []
    for x in pool_result:
        communities = communities + x.get()
    print "finish process___________________"
    all_nodes = nodes_C
    comm_nodes = []
    for x in communities:
        comm_nodes = comm_nodes + x.nodes()
    left_list = [x for x in all_nodes if x not in comm_nodes]

    while len(left_list) > 0:
        single_seed_communities = get_single_seed_nature_community_once(left_list)
        communities = communities + single_seed_communities
        for comm in communities:
            for x in comm.nodes():
                if x in left_list:
                    left_list.remove(x)

    # 	while len(left_list)>0:
    # 		seed_node = get_degree_max(left_list)
    # 		print "seed_node",seed_node
    # 		seed_clique = get_cliques(C, seed_node)
    ##		print "seed_clique", seed_clique
    # 		single_node_Graph = nx.Graph(C.subgraph(seed_clique))
    ##		single_node_Graph.add_node(seed_node)
    # 		single_node_Graph = get_nature_community_short(single_node_Graph)
    #
    # 		sngn = single_node_Graph.nodes()
    # 		print "seed_community: ", sngn
    # 		communities.append(single_node_Graph)
    # 		for x in sngn:
    # 			if x in left_list:
    # 				left_list.remove(x)

    i = 0
    for x in communities:
        print "i = ", i, x.nodes()
        i = i + 1
    print "finish get all communities"
    communities = deal_communities(communities)
    print "complete deal_communities"
    return communities
def get_all_nature_community(cliques):
    pool_result = []
    global process_num
    if len(cliques) < process_num:
        process_num = len(cliques)

    pool = Pool(process_num)
    cli_len = len(cliques)

    group_list = split_list(cliques, process_num)

    for i in range(1, len(group_list), 2):
        group_list[i].reverse()

    for i in range(process_num):
        args = []
        for gr in group_list:
            if len(gr) > i:
                args.append(gr[i])
        args = (args, )
        #		args=([cliques[j] for j in range(cli_len) if j%process_num==i],)
        print "args__________", args
        pool_result.append(pool.apply_async(process_f, args))

    pool.close()
    pool.join()

    communities = []
    for x in pool_result:
        communities = communities + x.get()
    print "finish process___________________"
    all_nodes = nodes_C
    comm_nodes = []
    for x in communities:
        comm_nodes = comm_nodes + x.nodes()
    left_list = [x for x in all_nodes if x not in comm_nodes]

    while len(left_list) > 0:
        single_seed_communities = get_single_seed_nature_community_once(
            left_list)
        communities = communities + single_seed_communities
        for comm in communities:
            for x in comm.nodes():
                if x in left_list:
                    left_list.remove(x)


#	while len(left_list)>0:
#		seed_node = get_degree_max(left_list)
#		print "seed_node",seed_node
#		seed_clique = get_cliques(C, seed_node)
##		print "seed_clique", seed_clique
#		single_node_Graph = nx.Graph(C.subgraph(seed_clique))
##		single_node_Graph.add_node(seed_node)
#		single_node_Graph = get_nature_community_short(single_node_Graph)
#
#		sngn = single_node_Graph.nodes()
#		print "seed_community: ", sngn
#		communities.append(single_node_Graph)
#		for x in sngn:
#			if x in left_list:
#				left_list.remove(x)

    i = 0
    for x in communities:
        print "i = ", i, x.nodes()
        i = i + 1
    print "finish get all communities"
    communities = deal_communities(communities)
    print "complete deal_communities"
    return communities