Skip to content

Commit

Permalink
Add more random graph test cases
Browse files Browse the repository at this point in the history
This commit adds more random graph test cases that catch some failures.
These tests still fail and will need to be fixed before we can move
forward on this.
  • Loading branch information
mtreinish committed Jan 29, 2021
1 parent 37b518d commit 0c6ea26
Showing 1 changed file with 57 additions and 11 deletions.
68 changes: 57 additions & 11 deletions tests/test_max_weight_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,22 @@ def test_nested_blossom_augmented(self):
expected)

def test_gnp_random_against_networkx(self):
rx_graph = retworkx.undirected_gnp_random_graph(10, .75, seed=42)
nx_graph = networkx.Graph(list(rx_graph.edge_list()))
nx_matches = networkx.max_weight_matching(nx_graph)
rx_match_dict = retworkx.max_weight_matching(rx_graph)
# Convert retworkx dict output to networkx set of tuples
rx_matches = {
(u, v) for (u, v) in set(map(frozenset, rx_match_dict.items()))}
self.assertEqual(nx_matches, rx_matches)
for i in range(1024):
rx_graph = retworkx.undirected_gnp_random_graph(10, .75,
seed=42 + i)
nx_graph = networkx.Graph(list(rx_graph.edge_list()))
nx_matches = networkx.max_weight_matching(nx_graph)
rx_match_dict = retworkx.max_weight_matching(rx_graph)
# Convert retworkx dict output to networkx set of tuples
for (u, v) in set(map(frozenset, rx_match_dict.items())):
if (u, v) not in nx_matches:
if (v, u) not in nx_matches:
self.fail("seed %s failed. Element %s and it's "
" reverse %s not found "
"in networkx output.\nretworkx output: %s"
"\nnetworkx output: %s\nedge list: %s" % (
42 + i, (u, v), (v, u), rx_match_dict,
nx_matches, list(rx_graph.edge_list())))

def test_gnp_random_against_networkx_max_cardinality(self):
rx_graph = retworkx.undirected_gnp_random_graph(10, .78, seed=428)
Expand All @@ -349,6 +357,44 @@ def test_gnp_random_against_networkx_max_cardinality(self):
rx_match_dict = retworkx.max_weight_matching(
rx_graph, max_cardinality=True)
# Convert retworkx dict output to networkx set of tuples
rx_matches = {
(u, v) for (u, v) in set(map(frozenset, rx_match_dict.items()))}
self.assertEqual(nx_matches, rx_matches)
for (u, v) in set(map(frozenset, rx_match_dict.items())):
if (u, v) not in nx_matches:
if (v, u) not in nx_matches:
self.fail("seed %s failed. Element %s and it's "
" reverse %s not found "
"in networkx output.\nretworkx output: %s"
"\nnetworkx output: %s\nedge list: %s" % (
428, (u, v), (v, u), rx_match_dict,
nx_matches, list(rx_graph.edge_list())))

def test_gnm_random_against_networkx(self):
rx_graph = retworkx.undirected_gnm_random_graph(10, 13, seed=42)
nx_graph = networkx.Graph(list(rx_graph.edge_list()))
nx_matches = networkx.max_weight_matching(nx_graph)
rx_match_dict = retworkx.max_weight_matching(rx_graph)
for (u, v) in set(map(frozenset, rx_match_dict.items())):
if (u, v) not in nx_matches:
if (v, u) not in nx_matches:
self.fail("seed %s failed. Element %s and it's "
" reverse %s not found "
"in networkx output.\nretworkx output: %s"
"\nnetworkx output: %s\nedge list: %s" % (
42, (u, v), (v, u), rx_match_dict,
nx_matches, list(rx_graph.edge_list())))

def test_gnm_random_against_networkx_max_cardinality(self):
rx_graph = retworkx.undirected_gnm_random_graph(10, 12, seed=428)
nx_graph = networkx.Graph(list(rx_graph.edge_list()))
nx_matches = networkx.max_weight_matching(
nx_graph, maxcardinality=True)
rx_match_dict = retworkx.max_weight_matching(
rx_graph, max_cardinality=True)
for (u, v) in set(map(frozenset, rx_match_dict.items())):
if (u, v) not in nx_matches:
if (v, u) not in nx_matches:
self.fail("seed %s failed. Element %s and it's "
" reverse %s not found "
"in networkx output.\nretworkx output: %s"
"\nnetworkx output: %s\nedge list: %s" % (
42, (u, v), (v, u), rx_match_dict,
nx_matches, list(rx_graph.edge_list())))

0 comments on commit 0c6ea26

Please sign in to comment.