예제 #1
0
 def test_binary_and(self):
     m = ConcreteModel()
     m.Y1 = BooleanVar()
     m.Y2 = BooleanVar()
     op_static = land(m.Y1, m.Y2)
     op_class = m.Y1.land(m.Y2)
     # op_operator = 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 = all(truth_combination)
         self.assertEqual(value(op_static), correct_value)
         self.assertEqual(value(op_class), correct_value)
예제 #2
0
 def test_nary_and(self):
     nargs = 3
     m = ConcreteModel()
     m.s = RangeSet(nargs)
     m.Y = BooleanVar(m.s)
     op_static = land(*(m.Y[i] for i in m.s))
     op_class = BooleanConstant(True)
     # op_operator = True
     for y in m.Y.values():
         op_class = op_class.land(y)
         # op_operator &= y
     for truth_combination in _generate_possible_truth_inputs(nargs):
         m.Y.set_values(dict(enumerate(truth_combination, 1)))
         correct_value = all(truth_combination)
         self.assertEqual(value(op_static), correct_value)
         self.assertEqual(value(op_class), correct_value)
예제 #3
0
    def test_to_string(self):
        m = ConcreteModel()
        m.Y1 = BooleanVar()
        m.Y2 = BooleanVar()
        m.Y3 = BooleanVar()

        self.assertEqual(str(land(m.Y1, m.Y2, m.Y3)), "Y1 ∧ Y2 ∧ Y3")
        self.assertEqual(str(lor(m.Y1, m.Y2, m.Y3)), "Y1 ∨ Y2 ∨ Y3")
        self.assertEqual(str(equivalent(m.Y1, m.Y2)), "Y1 iff Y2")
        self.assertEqual(str(implies(m.Y1, m.Y2)), "Y1 --> Y2")
        self.assertEqual(str(xor(m.Y1, m.Y2)), "Y1 ⊻ Y2")
        self.assertEqual(str(atleast(1, m.Y1, m.Y2)), "atleast(1: [Y1, Y2])")
        self.assertEqual(str(atmost(1, m.Y1, m.Y2)), "atmost(1: [Y1, Y2])")
        self.assertEqual(str(exactly(1, m.Y1, m.Y2)), "exactly(1: [Y1, Y2])")

        # Precedence check
        self.assertEqual(str(m.Y1.implies(m.Y2).lor(m.Y3)), "(Y1 --> Y2) ∨ Y3")