Exemplo n.º 1
0
 def test_detect_effectively_discrete_vars(self):
     m = ConcreteModel()
     m.x = Var()
     m.y = Var(domain=Binary)
     m.z = Var(domain=Integers)
     m.constr = Constraint(expr=m.x == m.y + m.z)
     m.ignore_inequality = Constraint(expr=m.x <= m.y + m.z)
     m.ignore_nonlinear = Constraint(expr=m.x**2 == m.y + m.z)
     m.a = Var()
     m.b = Var(domain=Binary)
     m.c = Var(domain=Integers)
     m.disj = Disjunct()
     m.disj.constr = Constraint(expr=m.a == m.b + m.c)
     effectively_discrete = detect_effectively_discrete_vars(m, 1E-6)
     self.assertEqual(len(effectively_discrete), 1)
     self.assertEqual(effectively_discrete[m.x], [m.constr])
     effectively_discrete = detect_effectively_discrete_vars(m.disj, 1E-6)
     self.assertEqual(len(effectively_discrete), 1)
     self.assertEqual(effectively_discrete[m.a], [m.disj.constr])
Exemplo n.º 2
0
 def test_detect_effectively_discrete_vars(self):
     m = ConcreteModel()
     m.x = Var()
     m.y = Var(domain=Binary)
     m.z = Var(domain=Integers)
     m.constr = Constraint(expr=m.x == m.y + m.z)
     m.ignore_inequality = Constraint(expr=m.x <= m.y + m.z)
     m.ignore_nonlinear = Constraint(expr=m.x ** 2 == m.y + m.z)
     m.a = Var()
     m.b = Var(domain=Binary)
     m.c = Var(domain=Integers)
     m.disj = Disjunct()
     m.disj.constr = Constraint(expr=m.a == m.b + m.c)
     effectively_discrete = detect_effectively_discrete_vars(m, 1E-6)
     self.assertEqual(len(effectively_discrete), 1)
     self.assertEqual(effectively_discrete[m.x], [m.constr])
     effectively_discrete = detect_effectively_discrete_vars(m.disj, 1E-6)
     self.assertEqual(len(effectively_discrete), 1)
     self.assertEqual(effectively_discrete[m.a], [m.disj.constr])
Exemplo n.º 3
0
 def test_determine_valid_values(self):
     m = ConcreteModel()
     m.x = Var()
     m.y = Var(RangeSet(4), domain=Binary)
     m.z = Var(domain=Integers, bounds=(-1, 2))
     m.constr = Constraint(expr=m.x == m.y[1] + 2 * m.y[2] + m.y[3] +
                           2 * m.y[4] + m.z)
     m.logical = ConstraintList()
     m.logical.add(expr=m.y[1] + m.y[2] == 1)
     m.logical.add(expr=m.y[3] + m.y[4] == 1)
     m.logical.add(expr=m.y[2] + m.y[4] <= 1)
     var_to_values_map = determine_valid_values(
         m, detect_effectively_discrete_vars(m, 1E-6),
         Bunch(equality_tolerance=1E-6, pruning_solver='glpk'))
     valid_values = set([1, 2, 3, 4, 5])
     self.assertEqual(set(var_to_values_map[m.x]), valid_values)
Exemplo n.º 4
0
 def test_determine_valid_values(self):
     m = ConcreteModel()
     m.x = Var()
     m.y = Var(RangeSet(4), domain=Binary)
     m.z = Var(domain=Integers, bounds=(-1, 2))
     m.constr = Constraint(
         expr=m.x == m.y[1] + 2 * m.y[2] + m.y[3] + 2 * m.y[4] + m.z)
     m.logical = ConstraintList()
     m.logical.add(expr=m.y[1] + m.y[2] == 1)
     m.logical.add(expr=m.y[3] + m.y[4] == 1)
     m.logical.add(expr=m.y[2] + m.y[4] <= 1)
     var_to_values_map = determine_valid_values(
         m, detect_effectively_discrete_vars(m, 1E-6), Bunch(
             equality_tolerance=1E-6,
             pruning_solver='glpk'))
     valid_values = set([1, 2, 3, 4, 5])
     self.assertEqual(set(var_to_values_map[m.x]), valid_values)