Пример #1
0
 def test_ub_only(self):
     bqm = BinaryQuadraticModel({
         0: 0.0,
         1: 0.0,
         2: 0.0,
         3: 0.0,
         4: 0.0
     }, {
         (0, 1): -2.0,
         (0, 2): -5.0,
         (0, 3): -2.0,
         (0, 4): -2.0,
         (1, 2): -2.0,
         (1, 3): -2.0,
         (1, 4): 4.0,
         (2, 3): -3.0,
         (2, 4): -5.0,
         (3, 4): -4.0
     }, 0, dimod.SPIN)
     sampler = ClipComposite(ExactSolver())
     solver = ExactSolver()
     response = sampler.sample(bqm, upper_bound=1)
     response_exact = solver.sample(bqm)
     self.assertEqual(response.first.sample, response_exact.first.sample)
     self.assertAlmostEqual(response.first.energy,
                            response_exact.first.energy)
Пример #2
0
 def test_with_labels(self):
     bqm = BinaryQuadraticModel(
         {
             'a': 0.0,
             'b': 0.0,
             'c': 0.0,
             'd': 0.0,
             'e': 0.0
         }, {
             ('a', 'b'): -2.0,
             ('a', 'c'): -5.0,
             ('a', 'd'): -2.0,
             ('a', 'e'): -2.0,
             ('b', 'c'): -2.0,
             ('b', 'd'): -2.0,
             ('b', 'e'): 4.0,
             ('c', 'd'): -3.0,
             ('c', 'e'): -5.0,
             ('d', 'e'): -4.0
         }, 0, dimod.SPIN)
     sampler = ClipComposite(ExactSolver())
     solver = ExactSolver()
     response = sampler.sample(bqm, lower_bound=-1, upper_bound=1)
     response_exact = solver.sample(bqm)
     self.assertEqual(response.first.sample, response_exact.first.sample)
     self.assertAlmostEqual(response.first.energy,
                            response_exact.first.energy)
Пример #3
0
 def test_empty_bqm(self):
     bqm = BinaryQuadraticModel({}, {}, 0.0, dimod.SPIN)
     sampler = ClipComposite(ExactSolver())
     sampler.sample(bqm, lower_bound=-1, upper_bound=1)