Skip to content

Commit

Permalink
Work on dwavesystems#200 and dwavesystems#203, could use a review and…
Browse files Browse the repository at this point in the history
… feedback
  • Loading branch information
James Cortese authored and Jason Necaise committed Dec 13, 2021
1 parent a670e0a commit 466fe68
Showing 1 changed file with 38 additions and 20 deletions.
58 changes: 38 additions & 20 deletions tests/test_tsp.py
Expand Up @@ -208,33 +208,51 @@ def test_k3_bidirectional(self):

self.assertEqual(ground_count, len(min_routes))

<<<<<<< HEAD
def test_graph_missing_edges(self):
G = nx.Graph()
G.add_weighted_edges_from([
(1, 0, 1),
(0, 3, 1),
(3, 2, 1),
(2, 1, 1),
G1 = nx.Graph()
G1.add_weighted_edges_from([
('a', 'b', 0.5),
('b', 'c', 1.0),
('a', 'c', 2.0),
])
Q1 = dnx.traveling_salesperson_qubo(G1, lagrange=10)

G2 = nx.Graph()
G2.add_weighted_edges_from([
('a', 'b', 0.5),
('a', 'c', 2.0),
])
Q = dnx.traveling_salesperson_qubo(G, missing_edge_weight=1)
# TODO: some assertions?
# make sure that missing_edge_weight gets applied correctly
Q2 = dnx.traveling_salesperson_qubo(G2, lagrange=10, missing_edge_weight=1.0)

self.assertDictEqual(Q1, Q2)

def test_digraph_missing_edges(self):
G = nx.DiGraph()
G.add_weighted_edges_from([
(1, 0, 1),
(0, 3, 1),
(3, 2, 1),
(2, 1, 1),
G1 = nx.DiGraph()
G1.add_weighted_edges_from([
('a', 'b', 0.5),
('b', 'a', 0.8),
('b', 'c', 1.0),
('c', 'b', 0.7),
('a', 'c', 2.0),
('c', 'a', 2.0),
])
Q = dnx.traveling_salesperson_qubo(G, missing_edge_weight=15)
# TODO: some assertions?
Q1 = dnx.traveling_salesperson_qubo(G1, lagrange=10)

G2 = nx.DiGraph()
G2.add_weighted_edges_from([
('a', 'b', 0.5),
('b', 'a', 0.8),
('c', 'b', 0.7),
('a', 'c', 2.0),
('c', 'a', 2.0),
])

# make sure that missing_edge_weight gets applied correctly
Q2 = dnx.traveling_salesperson_qubo(G2, lagrange=10, missing_edge_weight=1.0)

self.assertDictEqual(Q1, Q2)

=======
>>>>>>> added unit tests
def test_k4_equal_weights(self):
# k5 with all equal weights so all paths are equally good
G = nx.Graph()
Expand Down Expand Up @@ -344,4 +362,4 @@ def test_docstring_size(self):
bqm = dimod.BinaryQuadraticModel.from_qubo(Q)

self.assertEqual(len(bqm), n**2)
self.assertEqual(len(bqm.quadratic), 2*n*n*(n - 1))
self.assertEqual(len(bqm.quadratic), 2*n*n*(n - 1))

0 comments on commit 466fe68

Please sign in to comment.