コード例 #1
0
def test_color_matrix_song2007():
    """
    Compared with manual coloring of dual graphs.

    Dual graphs were built manually and checked with the dual_graph function.
    Coloring for lb = 3 was compared to Song's paper.
    Coloring for lb != 3 was performed manually (easy for lb=1 and lb=4=lb_max).
    """

    G = graphs.build_song2007_graph()

    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
    assert c[4][lb - 1] == 4
    assert c[5][lb - 1] == 5

    lb = 2
    assert c[0][lb - 1] == 0
    assert c[1][lb - 1] == 0
    assert c[2][lb - 1] == 0
    assert c[3][lb - 1] == 1
    assert c[4][lb - 1] == 1
    assert c[5][lb - 1] == 2

    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] == 0
    assert c[4][lb - 1] == 1
    assert c[5][lb - 1] == 1

    lb = 4
    assert c[0][lb - 1] == 0
    assert c[1][lb - 1] == 0
    assert c[2][lb - 1] == 0
    assert c[3][lb - 1] == 0
    assert c[4][lb - 1] == 0
    assert c[5][lb - 1] == 1
コード例 #2
0
def test_dual_graph_song2007():
    G = graphs.build_song2007_graph()

    assert G.number_of_nodes() == 6
    assert G.number_of_edges() == 6

    paths = nx.shortest_path(G)

    dG = greedy.dual_graph(G, paths, 3)

    assert dG.number_of_nodes() == 6
    assert dG.number_of_edges() == 5

    assert dG.has_edge(0, 4)
    assert dG.has_edge(0, 5)
    assert dG.has_edge(1, 4)
    assert dG.has_edge(1, 5)
    assert dG.has_edge(2, 5)
コード例 #3
0
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
コード例 #4
0
    This function is inefficient and should not be used to compute the number of boxes for
    many different values of lb, since the shortest paths are computed every time.
    """

    paths = nx.shortest_path(graph)

    l, n = number_of_boxes_v2(graph, paths)

    return n[lb - 1]


if __name__ == "__main__":
    from tfdppin import graphs

    import matplotlib.pyplot as plt

    G = graphs.build_song2007_graph()

    assert num_boxes_from_graph(G, 3) == 2

    plt.figure(1)
    nx.draw(G, with_labels=True)
    plt.show(block=False)

    paths = nx.shortest_path(G)

    dG = dual_graph(G, paths, 3)
    plt.figure(2)
    nx.draw(dG, with_labels=True)
    plt.show()
コード例 #5
0
def test_number_of_boxes_song2007():

    G = graphs.build_song2007_graph()

    assert greedy.num_boxes_from_graph(G, 3) == 2
コード例 #6
0
def test_build_song2007_graph():

    G = graphs.build_song2007_graph()

    assert G.number_of_nodes() == 6
    assert G.number_of_edges() == 6