Exemple #1
0
def test_deterministic_corruption():
    G = dg.RH(20, 0.5)
    G2 = le.apply_random_corruptions(G,
                                     expected_corruption_steps=15,
                                     rng=np.random.RandomState(7))
    G3 = le.apply_random_corruptions(G,
                                     expected_corruption_steps=15,
                                     rng=np.random.RandomState(7))
    assert nx.is_isomorphic(G2, G3)
Exemple #2
0
def test_is_laman():
    G = dg.RH(20, 0.5)
    tic = time.time()
    print("Running Laman checker")
    assert le.is_laman(G)
    elapsed = time.time() - tic
    print("Check took %.5f seconds \n" % elapsed)
    G.add_edge(100, 5)
    assert (le.is_laman(G) == False)
Exemple #3
0
def test_repeat_action():
    G = dg.RH(20, 0.5)
    G2 = deepcopy(G)
    actions = []
    for _ in range(24):
        G, act = le.insert_random_node(G, return_action=True)
        actions.append(act)
    for _ in range(12):
        G, act = le.delete_random_node(G, return_action=True)
        actions.append(act)
    for act in actions:
        G2 = le.compute_action(G2, act)
    assert nx.is_isomorphic(G, G2)
Exemple #4
0
def test_inverses():
    tic = time.time()
    G = dg.RH(30, 0.5)
    print('Graph generation took %.5f seconds' % (time.time() - tic))
    for _ in range(24):
        G_target = deepcopy(G)
        G, inv = le.insert_random_node(G, return_inverse=True)
        G_inv = le.compute_action(G, inv)
        assert nx.is_isomorphic(G_inv, G_target)
    for _ in range(12):
        G_target = deepcopy(G)
        G, inv = le.delete_random_node(G, return_inverse=True)
        G_inv = le.compute_action(G, inv)
        assert nx.is_isomorphic(G_inv, G_target)
Exemple #5
0
def dod_vs_size_exp():
    sizes = range(3, 100, 2)
    num_trials = 10
    for p in [0, 0.5, 1.0]:
        dods = []
        for size in sizes:
            dod_sum = 0
            for trial in range(num_trials):
                G = data_gen.RH(size, p)
                dod_sum += get_DoD(G)
            dods.append(dod_sum / num_trials)
            print(size)
        plt.plot(sizes, dods, linestyle='--', marker='^', label='p = %.1f' % p)
    plt.legend(loc='upper right')
    plt.xlabel('Size of graph')
    plt.ylabel('Degree of decomposability')
    plt.show(block=False)
    plt.pause(0.001)
    plt.savefig('dod_vs_size.png')
Exemple #6
0
def test_renumber():
    G = dg.RH(30, 0.5)
    for _ in range(10):
        G = le.delete_random_node(G)
    for idx, node in enumerate(list(G.nodes)):
        assert idx == node
Exemple #7
0
def test_laman_after_corruption():
    G = dg.RH(20, 0.5)
    G2 = le.apply_random_corruptions(G, expected_corruption_steps=15)
    assert le.is_laman(G2)
Exemple #8
0
def test_deterministic_generation():
    G1 = dg.RH(20, 0.5, rng=np.random.RandomState(42))
    G2 = dg.RH(20, 0.5, rng=np.random.RandomState(42))
    assert nx.is_isomorphic(G1, G2)