def test_k_relax2(): n = 3 k = 2 G = nx.path_graph(n) H = nx.path_graph(n) sa.k_dim_linear_relax(G, H, k) (answer, isomorphism) = sa.k_dim_linear_relax(G, H, k) np.testing.assert_almost_equal(isomorphism.sum(0), np.ones(n)) np.testing.assert_almost_equal(isomorphism.sum(1), np.ones(n))
def test_if_answer_is_correct2(): """ test if different number of nodes is immediately realized""" G = nx.path_graph(4) H = nx.path_graph(5) k = 1 (answer, X) = sa.k_dim_linear_relax(G, H, k) assert not (answer)
def test_if_answer_is_correct(): n = 5 G = nx.path_graph(n) H = nx.path_graph(n) k = 1 (answer, X) = sa.k_dim_linear_relax(G, H, k) assert answer
def test_fancy_graph(): G = file2graph("graphs/CaiOrigTwistedV10.txt") F = file2graph("graphs/CaiOrigV10.txt") k = 2 (answer, isomorphism) = sa.k_dim_linear_relax(G, F, k) assert answer in (0, 3) if answer is not 0: np.testing.assert_almost_equal(isomorphism.sum(0), 1, decimal=4) np.testing.assert_almost_equal(isomorphism.sum(1), 1, decimal=4)
def test_simple1(): G = file2graph("graphs/simple1.txt") F = file2graph("graphs/simple2.txt") k = 1 (answer, isomorphism) = sa.k_dim_linear_relax(G, F, k, solver='linear') assert answer in (0, 3) if answer is not 0: np.testing.assert_almost_equal(isomorphism.sum(0), 1) np.testing.assert_almost_equal(isomorphism.sum(1), 1)
def test_if_solution_is_bijection(): """after converting the solution back to a square matrix all row sums and all colums sums should be 1""" n = 4 k = 1 G = nx.path_graph(n) H = nx.path_graph(n) (answer, X) = sa.k_dim_linear_relax(G, H, k) np.testing.assert_almost_equal(X.sum(0), np.ones(n)) np.testing.assert_almost_equal(X.sum(1), np.ones(n))
def example(): G = file2graph("graphs/CaiOrigTwistedV10.txt") H = file2graph("graphs/CaiOrigV10.txt") nx.draw(G) print('close figure to continue') plt.show() nx.draw(H) print('close figure to continue') plt.show() for k in range(1, 4): print("\033[1;33;40m \n running Sherali-Adams with k =", k, "\033[0m ") solver = "linear" if k < 3 else "minimize" (answer, isomorphism) = k_dim_linear_relax(G, H, k, solver) print("\033[01;32m \n", flag_interpreter(answer), "\033[00m ") print("\033[1;33;40m \n", np.round(isomorphism, decimals=5), "\033[0m ")