コード例 #1
0
ファイル: test_threshold.py プロジェクト: zahra-mor/networkx
    def test_shortest_path(self):
        deg = [3, 2, 2, 1]
        G = nx.generators.havel_hakimi_graph(deg)
        cs1 = nxt.creation_sequence(deg, with_labels=True)
        for n, m in [(3, 0), (0, 3), (0, 2), (0, 1), (1, 3), (3, 1), (1, 2),
                     (2, 3)]:
            assert nxt.shortest_path(cs1, n, m) == nx.shortest_path(G, n, m)

        spl = nxt.shortest_path_length(cs1, 3)
        spl2 = nxt.shortest_path_length([t for v, t in cs1], 2)
        assert spl == spl2

        spld = {}
        for j, pl in enumerate(spl):
            n = cs1[j][0]
            spld[n] = pl
        assert spld == nx.single_source_shortest_path_length(G, 3)

        assert nxt.shortest_path(["d", "d", "d", "i", "d", "d"], 1,
                                 2) == [1, 2]
        assert nxt.shortest_path([3, 1, 2], 1, 2) == [1, 2]
        assert pytest.raises(TypeError, nxt.shortest_path, [3.0, 1.0, 2.0], 1,
                             2)
        assert pytest.raises(ValueError, nxt.shortest_path, [3, 1, 2], "a", 2)
        assert pytest.raises(ValueError, nxt.shortest_path, [3, 1, 2], 1, "b")
        assert nxt.shortest_path([3, 1, 2], 1, 1) == [1]
コード例 #2
0
ファイル: test_threshold.py プロジェクト: ProgVal/networkx
    def test_shortest_path(self):
        deg = [3, 2, 2, 1]
        G = nx.generators.havel_hakimi_graph(deg)
        cs1 = nxt.creation_sequence(deg, with_labels=True)
        for n, m in [(3, 0), (0, 3), (0, 2), (0, 1), (1, 3),
                     (3, 1), (1, 2), (2, 3)]:
            assert_equal(nxt.shortest_path(cs1, n, m),
                         nx.shortest_path(G, n, m))

        spl = nxt.shortest_path_length(cs1, 3)
        spl2 = nxt.shortest_path_length([t for v, t in cs1], 2)
        assert_equal(spl, spl2)

        spld = {}
        for j, pl in enumerate(spl):
            n = cs1[j][0]
            spld[n] = pl
        assert_equal(spld, nx.single_source_shortest_path_length(G, 3))

        assert_equal(nxt.shortest_path(['d', 'd', 'd', 'i', 'd', 'd'], 1, 2), [1, 2])
        assert_equal(nxt.shortest_path([3, 1, 2], 1, 2), [1, 2])
        assert_raises(TypeError, nxt.shortest_path, [3., 1., 2.], 1, 2)
        assert_raises(ValueError, nxt.shortest_path, [3, 1, 2], 'a', 2)
        assert_raises(ValueError, nxt.shortest_path, [3, 1, 2], 1, 'b')
        assert_equal(nxt.shortest_path([3, 1, 2], 1, 1), [1])
コード例 #3
0
ファイル: test_threshold.py プロジェクト: Harshi3030/algos
    def test_shortest_path(self):
        deg = [3, 2, 2, 1]
        G = nx.generators.havel_hakimi_graph(deg)
        cs1 = nxt.creation_sequence(deg, with_labels=True)
        for n, m in [(3, 0), (0, 3), (0, 2), (0, 1), (1, 3),
                     (3, 1), (1, 2), (2, 3)]:
            assert_equal(nxt.shortest_path(cs1, n, m),
                         nx.shortest_path(G, n, m))

        spl = nxt.shortest_path_length(cs1, 3)
        spl2 = nxt.shortest_path_length([t for v, t in cs1], 2)
        assert_equal(spl, spl2)

        spld = {}
        for j, pl in enumerate(spl):
            n = cs1[j][0]
            spld[n] = pl
        assert_equal(spld, nx.single_source_shortest_path_length(G, 3))

        assert_equal(nxt.shortest_path(['d', 'd', 'd', 'i', 'd', 'd'], 1, 2), [1, 2])
        assert_equal(nxt.shortest_path([3, 1, 2], 1, 2), [1, 2])
        assert_raises(TypeError, nxt.shortest_path, [3., 1., 2.], 1, 2)
        assert_raises(ValueError, nxt.shortest_path, [3, 1, 2], 'a', 2)
        assert_raises(ValueError, nxt.shortest_path, [3, 1, 2], 1, 'b')
        assert_equal(nxt.shortest_path([3, 1, 2], 1, 1), [1])
コード例 #4
0
ファイル: test_threshold.py プロジェクト: blublud/networkx
    def test_creation_sequences(self):
        deg=[3,2,2,1]
        G=nx.generators.havel_hakimi_graph(deg)
        cs0=nxt.creation_sequence(deg)
        H0=nxt.threshold_graph(cs0)
        assert_equal(''.join(cs0), 'ddid')

        cs1=nxt.creation_sequence(deg, with_labels=True)
        H1=nxt.threshold_graph(cs1)
        assert_equal(cs1, [(1, 'd'), (2, 'd'), (3, 'i'), (0, 'd')])

        cs2=nxt.creation_sequence(deg, compact=True)
        H2=nxt.threshold_graph(cs2)
        assert_equal(cs2, [2, 1, 1])
        assert_equal(''.join(nxt.uncompact(cs2)), 'ddid')
        assert_true(graph_could_be_isomorphic(H0,G))
        assert_true(graph_could_be_isomorphic(H0,H1))
        assert_true(graph_could_be_isomorphic(H0,H2))
コード例 #5
0
    def test_creation_sequences(self):
        deg = [3, 2, 2, 1]
        G = nx.generators.havel_hakimi_graph(deg)
        cs0 = nxt.creation_sequence(deg)
        H0 = nxt.threshold_graph(cs0)
        assert_equal(''.join(cs0), 'ddid')

        cs1 = nxt.creation_sequence(deg, with_labels=True)
        H1 = nxt.threshold_graph(cs1)
        assert_equal(cs1, [(1, 'd'), (2, 'd'), (3, 'i'), (0, 'd')])

        cs2 = nxt.creation_sequence(deg, compact=True)
        H2 = nxt.threshold_graph(cs2)
        assert_equal(cs2, [2, 1, 1])
        assert_equal(''.join(nxt.uncompact(cs2)), 'ddid')
        assert_true(graph_could_be_isomorphic(H0, G))
        assert_true(graph_could_be_isomorphic(H0, H1))
        assert_true(graph_could_be_isomorphic(H0, H2))
コード例 #6
0
ファイル: test_threshold.py プロジェクト: zahra-mor/networkx
    def test_creation_sequences(self):
        deg = [3, 2, 2, 1]
        G = nx.generators.havel_hakimi_graph(deg)

        with pytest.raises(ValueError):
            nxt.creation_sequence(deg, with_labels=True, compact=True)

        cs0 = nxt.creation_sequence(deg)
        H0 = nxt.threshold_graph(cs0)
        assert "".join(cs0) == "ddid"

        cs1 = nxt.creation_sequence(deg, with_labels=True)
        H1 = nxt.threshold_graph(cs1)
        assert cs1 == [(1, "d"), (2, "d"), (3, "i"), (0, "d")]

        cs2 = nxt.creation_sequence(deg, compact=True)
        H2 = nxt.threshold_graph(cs2)
        assert cs2 == [2, 1, 1]
        assert "".join(nxt.uncompact(cs2)) == "ddid"
        assert graph_could_be_isomorphic(H0, G)
        assert graph_could_be_isomorphic(H0, H1)
        assert graph_could_be_isomorphic(H0, H2)
コード例 #7
0
ファイル: test_threshold.py プロジェクト: blublud/networkx
    def test_shortest_path(self):
        deg=[3,2,2,1]
        G=nx.generators.havel_hakimi_graph(deg)
        cs1=nxt.creation_sequence(deg, with_labels=True)
        for n, m in [(3, 0), (0, 3), (0, 2), (0, 1), (1, 3),
                     (3, 1), (1, 2), (2, 3)]:
            assert_equal(nxt.shortest_path(cs1,n,m),
                         nx.shortest_path(G, n, m))

        spl=nxt.shortest_path_length(cs1,3)
        spl2=nxt.shortest_path_length([ t for v,t in cs1],2)
        assert_equal(spl, spl2)

        spld={}
        for j,pl in enumerate(spl):
            n=cs1[j][0]
            spld[n]=pl
        assert_equal(spld, nx.single_source_shortest_path_length(G, 3))
コード例 #8
0
ファイル: test_threshold.py プロジェクト: blublud/networkx
    def test_finding_routines(self):
        G=nx.Graph({1:[2],2:[3],3:[4],4:[5],5:[6]})
        G.add_edge(2,4)
        G.add_edge(2,5)
        G.add_edge(2,7)
        G.add_edge(3,6)
        G.add_edge(4,6)

        # Alternating 4 cycle
        assert_equal(nxt.find_alternating_4_cycle(G), [1, 2, 3, 6])

        # Threshold graph
        TG=nxt.find_threshold_graph(G)
        assert_true(nxt.is_threshold_graph(TG))
        assert_equal(sorted(TG.nodes()), [1, 2, 3, 4, 5, 7])

        cs=nxt.creation_sequence(dict(TG.degree()), with_labels=True)
        assert_equal(nxt.find_creation_sequence(G), cs)
コード例 #9
0
ファイル: test_threshold.py プロジェクト: zahra-mor/networkx
    def test_finding_routines(self):
        G = nx.Graph({1: [2], 2: [3], 3: [4], 4: [5], 5: [6]})
        G.add_edge(2, 4)
        G.add_edge(2, 5)
        G.add_edge(2, 7)
        G.add_edge(3, 6)
        G.add_edge(4, 6)

        # Alternating 4 cycle
        assert nxt.find_alternating_4_cycle(G) == [1, 2, 3, 6]

        # Threshold graph
        TG = nxt.find_threshold_graph(G)
        assert nxt.is_threshold_graph(TG)
        assert sorted(TG.nodes()) == [1, 2, 3, 4, 5, 7]

        cs = nxt.creation_sequence(dict(TG.degree()), with_labels=True)
        assert nxt.find_creation_sequence(G) == cs
コード例 #10
0
    def test_shortest_path(self):
        deg = [3, 2, 2, 1]
        G = nx.generators.havel_hakimi_graph(deg)
        cs1 = nxt.creation_sequence(deg, with_labels=True)
        for n, m in [(3, 0), (0, 3), (0, 2), (0, 1), (1, 3), (3, 1), (1, 2),
                     (2, 3)]:
            assert_equal(nxt.shortest_path(cs1, n, m),
                         nx.shortest_path(G, n, m))

        spl = nxt.shortest_path_length(cs1, 3)
        spl2 = nxt.shortest_path_length([t for v, t in cs1], 2)
        assert_equal(spl, spl2)

        spld = {}
        for j, pl in enumerate(spl):
            n = cs1[j][0]
            spld[n] = pl
        assert_equal(spld, dict(nx.single_source_shortest_path_length(G, 3)))