Пример #1
0
    def test_polyhedral_cons_ub(self):
        m = pe.ConcreteModel()
        m.x = pe.Var(range(2))
        m.P = ro.UncSet()
        m.w = ro.UncParam(range(2), nominal=(1, 2), uncset=m.P)
        m.P.cons = pe.ConstraintList()
        m.P.cons.add(pe.inequality(0.5, m.w[0], 1.5))
        m.P.cons.add(pe.inequality(1.5, m.w[1], 2.5))

        expr = pe.sum_product(m.w, m.x)
        m.cons = pe.Constraint(expr=expr <= 2)
        m.obj = pe.Objective(expr=m.x[0], sense=pe.maximize)
        t = ro.PolyhedralTransformation()
        t.apply_to(m)
        self.assertFalse(m.cons.active)
        self.assertTrue(hasattr(m, 'cons_counterpart_upper'))
Пример #2
0
    def test_polyhedral_obj_max(self):
        m = pe.ConcreteModel()
        m.x = pe.Var(range(2))
        m.P = ro.UncSet()
        m.w = ro.UncParam(range(2), nominal=(1, 2), uncset=m.P)
        m.P.cons = pe.ConstraintList()
        m.P.cons.add(pe.inequality(0.5, m.w[0], 1.5))
        m.P.cons.add(pe.inequality(1.5, m.w[1], 2.5))

        expr = pe.sum_product(m.w, m.x)
        m.obj = pe.Objective(expr=expr, sense=pe.maximize)
        m.cons = pe.Constraint(expr=pe.quicksum(m.x[i] for i in m.x) <= 4)
        t = ro.PolyhedralTransformation()
        t.apply_to(m)
        self.assertFalse(m.obj.active)
        self.assertTrue(hasattr(m, 'obj_counterpart'))
        self.assertTrue(hasattr(m, 'obj_new'))
        self.assertIs(m.obj_new.sense, pe.maximize)