G = nx.relabel.convert_node_labels_to_integers(G)

    if not os.path.exists('results'):
        os.mkdir('results')

    show(G)

    filename = os.path.join('results', 'n' + str(len(G)) + 'd' +
                            str(max(G.degree().values())) + 'or' + str(min(G.degree().values())) + '_revised_edgelist.txt')
    nx.write_edgelist(G, filename)

    for node in G.nodes():
        if G.degree()[node] == q - 1:
            for node2 in G.nodes():
                if G.degree()[node2] == q - 1:
                    if nx_to_ig(G).shortest_paths()[node][node2] == 3:
                        G.add_edge(node, node2)
                        break

    show(G)

    H = nx.read_edgelist(os.path.join('results', 'n' + str(len(G)) + 'd' +
                                      str(max(G.degree().values())) + '_edgelist.txt'))
    original_aspl = nx_to_ig(H).average_path_length()
    predicted_original_aspl = predicted_aspl_after_adding_edges(float(q))
    print "original aspl:", original_aspl
    print "predicted original aspl:", predicted_original_aspl
    assert original_aspl == predicted_original_aspl
    print "revised aspl:", aspl
    assert aspl < predicted_aspl_after_adding_edges(float(q))
    parser.add_argument('p', type=int)
    parser.add_argument('k', type=int)
    parser.add_argument('--verbose', action='store_true')
    args = parser.parse_args()

    G = nd2(args.p, args.k)
    q = args.p ** args.k

    G = nx.relabel.convert_node_labels_to_integers(G)

    '''
    if not os.path.exists('results'):
        os.mkdir('results')
    '''

    ig_G = nx_to_ig(G)
    N1, ds1, D1, aspl1 = len(G), set(
        G.degree().values()), ig_G.diameter(), ig_G.average_path_length()
    print N1, ds1, D1, aspl1

    '''
    filename = os.path.join('results', 'n' + str(len(G)) + 'd' +
                            str(max(G.degree().values())) + 'or' + str(min(G.degree().values())) + '_edgelist.txt')
    nx.write_edgelist(G, filename)

    if args.verbose:
        G = nx.relabel.convert_node_labels_to_integers(nx.read_edgelist(filename))
        ig_G = nx_to_ig(G)
        N2, ds2, D2, aspl2 = len(G), set(
            G.degree().values()), ig_G.diameter(), ig_G.average_path_length()
        assert (N1, ds1, D1, aspl1) == (N2, ds2, D2, aspl2)
Beispiel #3
0
    parser = argparse.ArgumentParser()
    parser.add_argument('p', type=int)
    parser.add_argument('k', type=int)
    parser.add_argument('--verbose', action='store_true')
    args = parser.parse_args()

    G = nd2(args.p, args.k)
    q = args.p**args.k

    G = nx.relabel.convert_node_labels_to_integers(G)
    '''
    if not os.path.exists('results'):
        os.mkdir('results')
    '''

    ig_G = nx_to_ig(G)
    N1, ds1, D1, aspl1 = len(G), set(
        G.degree().values()), ig_G.diameter(), ig_G.average_path_length()
    print N1, ds1, D1, aspl1
    '''
    filename = os.path.join('results', 'n' + str(len(G)) + 'd' +
                            str(max(G.degree().values())) + 'or' + str(min(G.degree().values())) + '_edgelist.txt')
    nx.write_edgelist(G, filename)

    if args.verbose:
        G = nx.relabel.convert_node_labels_to_integers(nx.read_edgelist(filename))
        ig_G = nx_to_ig(G)
        N2, ds2, D2, aspl2 = len(G), set(
            G.degree().values()), ig_G.diameter(), ig_G.average_path_length()
        assert (N1, ds1, D1, aspl1) == (N2, ds2, D2, aspl2)
        print N2, ds2, D2, aspl2
Beispiel #4
0
    if not os.path.exists('results'):
        os.mkdir('results')

    show(G)

    filename = os.path.join(
        'results', 'n' + str(len(G)) + 'd' + str(max(G.degree().values())) +
        'or' + str(min(G.degree().values())) + '_revised_edgelist.txt')
    nx.write_edgelist(G, filename)

    for node in G.nodes():
        if G.degree()[node] == q - 1:
            for node2 in G.nodes():
                if G.degree()[node2] == q - 1:
                    if nx_to_ig(G).shortest_paths()[node][node2] == 3:
                        G.add_edge(node, node2)
                        break

    show(G)

    H = nx.read_edgelist(
        os.path.join(
            'results', 'n' + str(len(G)) + 'd' +
            str(max(G.degree().values())) + '_edgelist.txt'))
    original_aspl = nx_to_ig(H).average_path_length()
    predicted_original_aspl = predicted_aspl_after_adding_edges(float(q))
    print "original aspl:", original_aspl
    print "predicted original aspl:", predicted_original_aspl
    assert original_aspl == predicted_original_aspl
    print "revised aspl:", aspl
Beispiel #5
0

def predicted_aspl_after_adding_edges(q):
    return 2 * (q**3 + q**2 - q - 2) / (q**3 + q**2)


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('p', type=int)
    parser.add_argument('k', type=int)
    args = parser.parse_args()

    q = args.p**args.k

    G = nx.read_edgelist('results/n' + str(q**2) + 'd' + str(q) + 'or' +
                         str(q - 1) + '_edgelist.txt')
    H = nx.read_edgelist('results/n' + str(q**2) + 'd' + str(q) +
                         '_edgelist.txt')

    predicted_aspl_before = predicted_aspl_before_adding_edges(q)
    predicted_aspl_after = predicted_aspl_after_adding_edges(q)
    aspl_before_adding_edges = nx_to_ig(G).average_path_length()
    aspl_after_adding_edges = nx_to_ig(H).average_path_length()

    assert predicted_aspl_before == aspl_before_adding_edges
    assert predicted_aspl_after == aspl_after_adding_edges
    print("predicted_aspl_before_adding_edges:", predicted_aspl_before)
    print("predicted_aspl_after_adding_edges:", predicted_aspl_after)
    print("aspl_before_adding_edges:", aspl_before_adding_edges)
    print("aspl_after_adding_edges:", aspl_after_adding_edges)
Beispiel #6
0
    return 2 * (q**2 + q - 1) / (q**2 + q)


def predicted_aspl_after_adding_edges(q):
    return 2 * (q**3 + q**2 - q - 2) / (q**3 + q**2)

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('p', type=int)
    parser.add_argument('k', type=int)
    args = parser.parse_args()

    q = args.p ** args.k

    G = nx.read_edgelist('results/n' + str(q**2) + 'd' + str(q) +
                         'or' + str(q - 1) + '_edgelist.txt')
    H = nx.read_edgelist('results/n' + str(q**2) + 'd' + str(q) +
                         '_edgelist.txt')

    predicted_aspl_before = predicted_aspl_before_adding_edges(q)
    predicted_aspl_after = predicted_aspl_after_adding_edges(q)
    aspl_before_adding_edges = nx_to_ig(G).average_path_length()
    aspl_after_adding_edges = nx_to_ig(H).average_path_length()

    assert predicted_aspl_before == aspl_before_adding_edges
    assert predicted_aspl_after == aspl_after_adding_edges
    print("predicted_aspl_before_adding_edges:", predicted_aspl_before)
    print("predicted_aspl_after_adding_edges:", predicted_aspl_after)
    print("aspl_before_adding_edges:", aspl_before_adding_edges)
    print("aspl_after_adding_edges:", aspl_after_adding_edges)
Beispiel #7
0
import networkx as nx
from common import nx_to_ig

G = nx.read_edgelist("results/n16384d128or127_edgelist.txt")

q = 2**7

ig_G = nx_to_ig(G)
print(ig_G.average_path_length())
predicted_aspl_before_adding_edges = 2 * (q**2 + q - 1) / (q**2 + q)
print(predicted_aspl_before_adding_edges)

'''
for node1 in G.nodes():
    for node2 in G.nodes():
        if G.degree()[node1] == 127 and G.degree()[node2] == 127:
            G.add_edge(node1, node2)
'''

nodes = []
degs = G.degree()
for node in G.nodes():
    if degs[node] == 127:
        nodes.append(node)
assert len(nodes) % 2 == 0
for i in range(len(nodes) // 2):
    G.add_edge(nodes[2 * i], nodes[2 * i + 1])

print(set(G.degree().values()))

ig_G = nx_to_ig(G)