コード例 #1
0
    def test_ellipsoidal_cons_lb_root(self):
        m = pe.ConcreteModel()
        m.x = pe.Var(range(2))
        m.U = ro.UncSet()
        m.w = ro.UncParam(range(2), nominal=(1, 2), uncset=m.U)
        expr = ((m.w[0] - 1)**2 + 0.1 * (m.w[0] - 1) * (m.w[1] - 2) +
                (m.w[1] - 2)**2 <= 0.1)
        m.U.cons = pe.Constraint(expr=expr)

        expr = pe.sum_product(m.w, m.x)
        m.cons = pe.Constraint(expr=2 <= expr)
        m.obj = pe.Objective(expr=m.x[0], sense=pe.minimize)
        t = ro.EllipsoidalTransformation()
        t.apply_to(m, root=True)
        self.assertFalse(m.cons.active)
        self.assertTrue(hasattr(m, 'cons_counterpart'))
        self.assertTrue(hasattr(m.cons_counterpart, 'lower'))
        self.assertTrue(hasattr(m.cons_counterpart.lower, 'rob'))
コード例 #2
0
    def test_ellipsoidal_obj_max_root(self):
        m = pe.ConcreteModel()
        m.x = pe.Var(range(2))
        m.U = ro.UncSet()
        m.w = ro.UncParam(range(2), nominal=(1, 2), uncset=m.U)
        expr = ((m.w[0] - 1)**2 + 0.1 * (m.w[0] - 1) * (m.w[1] - 2) +
                (m.w[1] - 2)**2 <= 0.1)
        m.U.cons = pe.Constraint(expr=expr)

        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.EllipsoidalTransformation()
        t.apply_to(m, root=True)
        self.assertFalse(m.obj.active)
        self.assertTrue(hasattr(m, 'obj_counterpart'))
        self.assertFalse(hasattr(m.obj_counterpart, 'det'))
        self.assertTrue(hasattr(m.obj_counterpart, 'rob'))
        self.assertIs(m.obj_counterpart.rob.sense, pe.maximize)