Ejemplo n.º 1
0
    def test_graph(self):
        edges = [
            # back edges
            (0, 2),
            (0, 3),
            (1, 4),
            (4, 9),
            (5, 7),
            # tree edges
            (0, 1),
            (1, 2),
            (2, 3),
            (2, 4),
            (4, 5),
            (4, 8),
            (5, 6),
            (6, 7),
            (8, 9),
        ]

        graph = retworkx.PyGraph()
        graph.extend_from_edge_list(edges)
        chains = retworkx.chain_decomposition(graph, source=0)
        expected = [
            [(0, 3), (3, 2), (2, 1), (1, 0)],
            [(0, 2)],
            [(1, 4), (4, 2)],
            [(4, 9), (9, 8), (8, 4)],
            [(5, 7), (7, 6), (6, 5)],
        ]
        self.assertEqual(expected, chains)
Ejemplo n.º 2
0
 def test_disconnected_graph_root_node(self):
     graph = retworkx.union(self.graph, self.graph)
     chains = retworkx.chain_decomposition(graph, source=0)
     expected = [
         [(0, 1), (1, 2), (2, 0)],
         [(3, 4), (4, 5), (5, 3)],
     ]
     self.assertEqual(expected, chains)
Ejemplo n.º 3
0
 def test_disconnected_graph(self):
     graph = retworkx.union(self.graph, self.graph)
     chains = retworkx.chain_decomposition(graph)
     expected = [
         [(0, 1), (1, 2), (2, 0)],
         [(3, 4), (4, 5), (5, 3)],
         [(6, 7), (7, 8), (8, 6)],
         [(9, 10), (10, 11), (11, 9)],
     ]
     self.assertEqual(expected, chains)
Ejemplo n.º 4
0
 def setUp(self):
     self.graph = retworkx.generators.cycle_graph(3)
     self.chains = retworkx.chain_decomposition(self.graph)
Ejemplo n.º 5
0
 def test_barbell_graph(self):
     chains = retworkx.chain_decomposition(self.graph, source=0)
     expected = [[(0, 1), (1, 2), (2, 0)], [(3, 4), (4, 5), (5, 3)]]
     self.assertEqual(expected, chains)