def test_node_types(self): m = ConcreteModel() m.Y1 = BooleanVar() m.Y2 = BooleanVar() m.Y3 = BooleanVar() self.assertFalse(m.Y1.is_expression_type()) self.assertTrue(lnot(m.Y1).is_expression_type()) self.assertTrue(equivalent(m.Y1, m.Y2).is_expression_type()) self.assertTrue(atmost(1, [m.Y1, m.Y2, m.Y3]).is_expression_type())
def test_unary_not(self): m = ConcreteModel() m.Y = BooleanVar() op_static = lnot(m.Y) op_operator = ~m.Y for truth_combination in _generate_possible_truth_inputs(1): m.Y.set_value(truth_combination[0]) correct_value = not truth_combination[0] self.assertEqual(value(op_static), correct_value) self.assertEqual(value(op_operator), correct_value)
def test_binary_implies(self): m = ConcreteModel() m.Y1 = BooleanVar() m.Y2 = BooleanVar() op_static = implies(m.Y1, m.Y2) op_class = m.Y1.implies(m.Y2) # op_loperator = m.Y2 << m.Y1 # op_roperator = m.Y1 >> m.Y2 for truth_combination in _generate_possible_truth_inputs(2): m.Y1.value, m.Y2.value = truth_combination[0], truth_combination[1] correct_value = (not truth_combination[0]) or truth_combination[1] self.assertEqual(value(op_static), correct_value) self.assertEqual(value(op_class), correct_value) # self.assertEqual(value(op_loperator), correct_value) # self.assertEqual(value(op_roperator), correct_value) nnf = lnot(m.Y1).lor(m.Y2) self.assertEqual(value(op_static), value(nnf))