def test_build_path_graph(n=10): with pytest.raises(ValueError): G = graphs.build_path_graph(1) for i in range(2, n): G = graphs.build_path_graph(i) assert G.number_of_nodes() == i assert G.number_of_edges() == i - 1
def test_color_matrix_path_4(): G = graphs.build_path_graph(4) paths = nx.shortest_path(G) c = greedy.color_matrix(G, paths) lb = 1 assert c[0][lb - 1] == 0 assert c[1][lb - 1] == 1 assert c[2][lb - 1] == 2 assert c[3][lb - 1] == 3 lb = 2 assert c[0][lb - 1] == 0 assert c[1][lb - 1] == 0 assert c[2][lb - 1] == 1 assert c[3][lb - 1] == 1 lb = 3 assert c[0][lb - 1] == 0 assert c[1][lb - 1] == 0 assert c[2][lb - 1] == 0 assert c[3][lb - 1] == 1
def test_color_matrix_path_2(): G = graphs.build_path_graph(2) paths = nx.shortest_path(G) c = greedy.color_matrix(G, paths) assert c[0][0] == 0 assert c[1][0] == 1
def test_number_of_boxes_path(): for n in range(10, 30): G = graphs.build_path_graph(n) paths = nx.shortest_path(G) # Test lb = 1 assert greedy.num_boxes_from_graph(G, 1) == n # Test lb = 2 if n % 2 == 0: assert greedy.num_boxes_from_graph(G, 2) == n / 2 else: assert greedy.num_boxes_from_graph(G, 2) == (n - 1) / 2 + 1 # Test lb = n - 1 (n - 1 is the diameter of the network) assert greedy.num_boxes_from_graph(G, n - 1) == 2
def test_graph_diameter(): for i in range(2,10): G = graphs.build_path_graph(i) paths = nx.shortest_path(G) assert greedy.graph_diameter(paths) == i - 1 for i in range(2, 10): G = graphs.build_lattice_graph(i) paths = nx.shortest_path(G) assert greedy.graph_diameter(paths) == 2 * i - 2 G = graphs.build_song2007_graph() paths = nx.shortest_path(G) assert greedy.graph_diameter(paths) == 4
1), l_boxes, np.array(n_boxes) if __name__ == "__main__": from tfdppin import graphs import matplotlib.pyplot as plt import os pbc = False fuzzy = False f = plt.figure(figsize=(12, 5)) N = 200 G = graphs.build_path_graph(N, pbc=pbc) if fuzzy: p, lb, Nb = tfd_fuzzy(G) else: #p, lb, Nb = tfd_greedy_slow(G) p, lb, Nb = tfd_greedy(G) print("TDF Path:", p[0]) f.add_subplot(1, 2, 1) plt.title("Path (N = {})".format(N)) plt.xlabel("log($l_B$)") plt.ylabel("log($N_B$)") plt.loglog(lb, Nb, 'o') x = np.linspace(min(np.log(lb)), max(np.log(lb)), 100)