Esempio n. 1
0
    def test_already_arborescence(self):
        """Tests that a directed acyclic graph that is already an
        arborescence produces an isomorphic arborescence as output.

        """
        A = nx.balanced_tree(2, 2, create_using=nx.DiGraph())
        B = nx.dag_to_branching(A)
        assert_true(nx.is_isomorphic(A, B))
Esempio n. 2
0
def circuit_to_formula(circuit):
    # Convert the circuit to an equivalent formula.
    formula = dag_to_branching(circuit)
    # Transfer the operator or variable labels for each node from the
    # circuit to the formula.
    for v in formula:
        source = formula.node[v]['source']
        formula.node[v]['label'] = circuit.node[source]['label']
    return formula
Esempio n. 3
0
    def test_already_branching(self):
        """Tests that a directed acyclic graph that is already a
        branching produces an isomorphic branching as output.

        """
        T1 = nx.balanced_tree(2, 2, create_using=nx.DiGraph())
        T2 = nx.balanced_tree(2, 2, create_using=nx.DiGraph())
        G = nx.disjoint_union(T1, T2)
        B = nx.dag_to_branching(G)
        assert_true(nx.is_isomorphic(G, B))
Esempio n. 4
0
    def test_single_root(self):
        """Tests that a directed acyclic graph with a single degree
        zero node produces an arborescence.

        """
        G = nx.DiGraph([(0, 1), (0, 2), (1, 3), (2, 3)])
        B = nx.dag_to_branching(G)
        expected = nx.DiGraph([(0, 1), (1, 3), (0, 2), (2, 4)])
        assert_true(nx.is_arborescence(B))
        assert_true(nx.is_isomorphic(B, expected))
Esempio n. 5
0
    def test_multiple_roots(self):
        """Tests that a directed acyclic graph with multiple degree zero
        nodes creates an arborescence with multiple (weakly) connected
        components.

        """
        G = nx.DiGraph([(0, 1), (0, 2), (1, 3), (2, 3), (5, 2)])
        B = nx.dag_to_branching(G)
        expected = nx.DiGraph([(0, 1), (1, 3), (0, 2), (2, 4), (5, 6), (6, 7)])
        assert_true(nx.is_branching(B))
        assert_false(nx.is_arborescence(B))
        assert_true(nx.is_isomorphic(B, expected))
Esempio n. 6
0
 def test_multidigraph(self):
     nx.dag_to_branching(nx.MultiDiGraph())
Esempio n. 7
0
 def test_undirected(self):
     nx.dag_to_branching(nx.Graph())
Esempio n. 8
0
 def test_not_acyclic(self):
     """Tests that a non-acyclic graph causes an exception."""
     G = nx.DiGraph(pairwise('abc', cyclic=True))
     nx.dag_to_branching(G)
Esempio n. 9
0
 def test_multigraph(self):
     with pytest.raises(nx.NetworkXNotImplemented):
         nx.dag_to_branching(nx.MultiGraph())
Esempio n. 10
0
 def test_undirected(self):
     with pytest.raises(nx.NetworkXNotImplemented):
         nx.dag_to_branching(nx.Graph())
Esempio n. 11
0
 def test_not_acyclic(self):
     """Tests that a non-acyclic graph causes an exception."""
     with pytest.raises(nx.HasACycle):
         G = nx.DiGraph(pairwise("abc", cyclic=True))
         nx.dag_to_branching(G)
Esempio n. 12
0
 def test_multidigraph(self):
     nx.dag_to_branching(nx.MultiDiGraph())
Esempio n. 13
0
 def test_undirected(self):
     nx.dag_to_branching(nx.Graph())
Esempio n. 14
0
 def test_not_acyclic(self):
     """Tests that a non-acyclic graph causes an exception."""
     G = nx.DiGraph(pairwise('abc', cyclic=True))
     nx.dag_to_branching(G)