def test_terms(self): cqm = CQM() a = cqm.add_variable('a', 'BINARY') b = cqm.add_variable('b', 'BINARY') c = cqm.add_variable('c', 'INTEGER') cqm.add_constraint([(a, b, 1), (b, 2.5,), (3,), (c, 1.5)], sense='<=')
def test_later_defn(self): i0 = Integer('i') i1 = Integer('i', upper_bound=1) cqm = CQM() cqm.add_variable('i', 'INTEGER') cqm.set_objective(i0) with self.assertRaises(ValueError): cqm.add_constraint(i1 <= 1) cqm.add_variable('i', 'INTEGER')
def test_terms_objective(self): cqm = CQM() a = cqm.add_variable('a', 'BINARY') b = cqm.add_variable('b', 'BINARY') c = cqm.add_variable('c', 'INTEGER') cqm.set_objective([(a, b, 1), (b, 2.5,), (3,), (c, 1.5)]) energy = cqm.objective.energy({'a': 1, 'b': 0, 'c': 10}) self.assertAlmostEqual(energy, 18) energy = cqm.objective.energy({'a': 1, 'b': 1, 'c': 3}) self.assertAlmostEqual(energy, 11)