def cache_graph():
    g = analysis_nx.load_graph('data/wiki-Vote/wiki-Vote.txt')
    lscc = analysis_nx.calculate_largest_strongly_connected_comp(g)
    lwcc = analysis_nx.calculate_largest_weakly_connected_comp(g)
    nx.write_gpickle(g, 'graphs/wiki-g.gpickle')
    nx.write_gpickle(lscc, 'graphs/wiki-lscc.gpickle')
    nx.write_gpickle(lwcc, 'graphs/wiki-lwcc.gpickle')
예제 #2
0
import analysis_nx
import time
start = time.time()

path_to_file = './data/wiki-Vote/wiki-Vote.txt'
g = analysis_nx.load_graph(path_to_file, True)
print('load graph: \t', int(divmod(time.time() - start, 60)[0]), 'min:', int(divmod(time.time() - start, 60)[1]),'s')

print('=====LSCC=====')
start_lscc = time.time()
LSCC = analysis_nx.calculate_largest_strongly_connected_comp(g)
print('calculate LSCC: \t', int(divmod(time.time() - start_lscc, 60)[0]), 'min:', int(divmod(time.time() - start, 60)[1]),'s')

print('LSCC edges: \t', LSCC.number_of_edges())
print('LSCC nodes: \t', LSCC.number_of_nodes())

LSCC_dist = analysis_nx.compute_shortest_path_distances_parallel_mp(LSCC)
print('caluclate distances LSCC: \t', int(divmod(time.time() - start_lscc, 60)[0]), 'min:', int(divmod(time.time() - start, 60)[1]),'s')

s_median, s_mean, s_diam, s_eff_diam = analysis_nx.compute_stats(LSCC_dist)
print('median distance: \t', s_median)
print('mean distance: \t', s_mean)
print('diameter: \t', s_diam)
print('effective diameter: \t', s_eff_diam)

print('LSCC done: \t', int(divmod(time.time() - start_lscc, 60)[0]), 'min:', int(divmod(time.time() - start, 60)[1]),'s')

print('=====LWCC=====')
start_lwcc = time.time()

LWCC = analysis_nx.calculate_largest_weakly_connected_comp(g)
def neighborhood_func(b, k, h, i):
    s = 0
    for l in range(k):
        s += leftmost_zero(b[l, h, i])
    return 2 ** (s / k) / 0.77351


def leftmost_zero(array):
    return np.where(array == 0)[0][0]


def interpolate(h, h_max, n_func):
    diameter_eff = h - 1
    diameter_eff += (0.9 * n_func[h_max] - n_func[h - 1]) / (n_func[h] - n_func[h - 1])
    return diameter_eff


if __name__ == "__main__":
    #g = read_cached('wiki-g')
    #lscc = read_cached('wiki-lscc')
    #lwcc = read_cached('wiki-lwcc')
    g = analysis_nx.load_graph('data/wiki-Vote/wiki-Vote.txt')
    lscc = analysis_nx.calculate_largest_strongly_connected_comp(g)
    lwcc = analysis_nx.calculate_largest_weakly_connected_comp(g)

    n_samples = int(0.01 * lscc.number_of_nodes())
    #bfs_graph = method_2(lscc, n_samples)

    method_3(lscc, 32)