예제 #1
0
    def compare_rx_nx_sets(self, rx_graph, rx_matches, nx_matches, seed,
                           nx_graph):
        def get_rx_weight(edge):
            weight = rx_graph.get_edge_data(*edge)
            if weight is None:
                return 1
            return weight

        def get_nx_weight(edge):
            weight = nx_graph.get_edge_data(*edge)
            if not weight:
                return 1
            return weight['weight']

        not_match = False
        for (u, v) in rx_matches:
            if (u, v) not in nx_matches:
                if (v, u) not in nx_matches:
                    print("seed %s failed. Element %s and it's "
                          "reverse %s not found in networkx output.\nretworkx"
                          " output: %s\nnetworkx output: %s\nedge list: %s\n"
                          "falling back to checking for a valid solution" %
                          (seed, (u, v), (v, u), rx_matches, nx_matches,
                           list(rx_graph.weighted_edge_list())))
                    not_match = True
                    break
        if not_match:
            self.assertTrue(retworkx.is_matching(rx_graph, rx_matches),
                            "%s is not a valid matching" % rx_matches)
            self.assertTrue(retworkx.is_maximal_matching(rx_graph, rx_matches),
                            "%s is not a maximal matching" % rx_matches)
            self.assertEqual(sum(map(get_rx_weight, rx_matches)),
                             sum(map(get_nx_weight, nx_matches)))
예제 #2
0
 def test_is_matching_invalid_edge(self):
     graph = retworkx.generators.path_graph(4)
     matching = {(0, 3), (1, 2)}
     self.assertFalse(retworkx.is_matching(graph, matching))
예제 #3
0
 def test_is_matching_single_edge(self):
     graph = retworkx.generators.path_graph(4)
     matching = {(1, 2)}
     self.assertTrue(retworkx.is_matching(graph, matching))
예제 #4
0
 def test_is_matching_valid(self):
     graph = retworkx.generators.path_graph(4)
     matching = {(0, 1), (2, 3)}
     self.assertTrue(retworkx.is_matching(graph, matching))
예제 #5
0
 def test_is_matching_empty(self):
     graph = retworkx.generators.path_graph(4)
     matching = set()
     self.assertTrue(retworkx.is_matching(graph, matching))