Example #1
0
    def test_disaggregation_constraints(self):
        m = models.makeTwoTermIndexedDisjunction()
        TransformationFactory('gdp.chull').apply_to(m)

        disaggregationCons = m._gdp_chull_relaxation_disjunction_disaggregation
        relaxedDisjuncts = m._pyomo_gdp_chull_relaxation.relaxedDisjuncts
        self.assertIsInstance(disaggregationCons, Constraint)
        self.assertEqual(len(disaggregationCons), 3)

        disaggregatedVars = {
            (1, 0): [
                relaxedDisjuncts[0].component('x[1]'),
                relaxedDisjuncts[1].component('x[1]')
            ],
            (2, 0): [
                relaxedDisjuncts[2].component('x[2]'),
                relaxedDisjuncts[3].component('x[2]')
            ],
            (3, 0): [
                relaxedDisjuncts[4].component('x[3]'),
                relaxedDisjuncts[5].component('x[3]')
            ],
        }

        for i, disVars in iteritems(disaggregatedVars):
            cons = disaggregationCons[i]
            self.assertEqual(cons.lower, 0)
            self.assertEqual(cons.upper, 0)
            repn = generate_standard_repn(cons.body)
            self.assertTrue(repn.is_linear())
            self.assertEqual(repn.constant, 0)
            self.assertEqual(len(repn.linear_vars), 3)
            check_linear_coef(self, repn, m.x[i[0]], 1)
            check_linear_coef(self, repn, disVars[0], -1)
            check_linear_coef(self, repn, disVars[1], -1)
Example #2
0
    def test_disaggregation_constraints(self):
        m = models.makeTwoTermIndexedDisjunction()
        TransformationFactory('gdp.chull').apply_to(m)

        disaggregationCons = m._gdp_chull_relaxation_disjunction_disaggregation
        relaxedDisjuncts = m._pyomo_gdp_chull_relaxation.relaxedDisjuncts
        self.assertIsInstance(disaggregationCons, Constraint)
        self.assertEqual(len(disaggregationCons), 3)

        disaggregatedVars = {
            (1, 0): [relaxedDisjuncts[0].component('x[1]'),
                          relaxedDisjuncts[1].component('x[1]')],
            (2, 0): [relaxedDisjuncts[2].component('x[2]'),
                          relaxedDisjuncts[3].component('x[2]')],
            (3, 0): [relaxedDisjuncts[4].component('x[3]'),
                          relaxedDisjuncts[5].component('x[3]')],
        }

        for i, disVars in iteritems(disaggregatedVars):
            cons = disaggregationCons[i]
            self.assertEqual(cons.lower, 0)
            self.assertEqual(cons.upper, 0)
            repn = generate_standard_repn(cons.body)
            self.assertTrue(repn.is_linear())
            self.assertEqual(repn.constant, 0)
            self.assertEqual(len(repn.linear_vars), 3)
            check_linear_coef(self, repn, m.x[i[0]], 1)
            check_linear_coef(self, repn, disVars[0], -1)
            check_linear_coef(self, repn, disVars[1], -1)
Example #3
0
    def test_disaggregation_constraints(self):
        m = models.makeTwoTermIndexedDisjunction()
        TransformationFactory('gdp.chull').apply_to(m)

        disaggregationCons = m._gdp_chull_relaxation_disjunction_disaggregation
        relaxedDisjuncts = m._pyomo_gdp_chull_relaxation.relaxedDisjuncts
        self.assertIsInstance(disaggregationCons, Constraint)
        self.assertEqual(len(disaggregationCons), 3)

        disaggregatedVars = {
            (1, 0): [
                relaxedDisjuncts[0].component('x[1]'),
                relaxedDisjuncts[1].component('x[1]')
            ],
            (2, 0): [
                relaxedDisjuncts[2].component('x[2]'),
                relaxedDisjuncts[3].component('x[2]')
            ],
            (3, 0): [
                relaxedDisjuncts[4].component('x[3]'),
                relaxedDisjuncts[5].component('x[3]')
            ],
        }

        for i, disVars in iteritems(disaggregatedVars):
            cons = disaggregationCons[i]
            self.assertEqual(cons.lower, 0)
            self.assertEqual(cons.upper, 0)
            self.assertEqual(len(cons.body._args), 3)
            self.assertEqual(len(cons.body._coef), 3)
            self.assertEqual(cons.body._coef[0], 1)
            self.assertEqual(cons.body._coef[1], -1)
            self.assertEqual(cons.body._coef[2], -1)
            self.assertIs(cons.body._args[0], m.x[i[0]])
            self.assertIs(cons.body._args[1], disVars[0])
            self.assertIs(cons.body._args[2], disVars[1])