Exemplo n.º 1
0
    def test_cuts_are_correct_facets_fme(self):
        m = models.makeTwoTermDisj_boxes()
        TransformationFactory('gdp.cuttingplane').apply_to(
            m,
            create_cuts=create_cuts_fme,
            post_process_cut=None,
            zero_tolerance=0)
        # This would also be a valid cut, it just doesn't happen to be what we
        # choose.
        # facet_extreme_pts = [
        #     (1,0,3,1),
        #     (1,0,3,2),
        #     (0,1,1,3),
        #     (0,1,1,4)
        # ]
        facet_extreme_pts = [(0, 1, 1, 3), (0, 1, 2, 3), (1, 0, 3, 1),
                             (1, 0, 4, 1)]

        cuts = m._pyomo_gdp_cuttingplane_transformation.cuts
        # Here, we get just one facet
        self.assertEqual(len(cuts), 1)
        cut = cuts[0]
        cut_expr = cut.body
        lower = cut.lower
        upper = cut.upper
        for pt in facet_extreme_pts:
            m.d[0].indicator_var.fix(pt[0])
            m.d[1].indicator_var.fix(pt[1])
            m.x.fix(pt[2])
            m.y.fix(pt[3])
            if lower is not None:
                self.assertEqual(value(lower), value(cut_expr))
            if upper is not None:
                self.assertEqual(value(upper), value(cut_expr))
Exemplo n.º 2
0
    def test_cuts_valid_on_hull_vertices_inf_norm(self):
        m = models.makeTwoTermDisj_boxes()
        # we actually don't have to adjust the back-off problem tolerance for
        # this norm.
        TransformationFactory('gdp.cuttingplane').apply_to(
            m, norm=float('inf'), verbose=True)

        self.check_cuts_valid_on_hull_vertices(m, TOL=1e-8)
Exemplo n.º 3
0
 def test_active_objective_err(self):
     m = models.makeTwoTermDisj_boxes()
     m.obj.deactivate()
     self.assertRaisesRegex(
         GDP_Error,
         "Cannot apply cutting planes transformation without an active "
         "objective in the model*",
         TransformationFactory('gdp.cuttingplane').apply_to, m)
Exemplo n.º 4
0
    def test_transformation_block(self):
        m = models.makeTwoTermDisj_boxes()
        TransformationFactory('gdp.cuttingplane').apply_to(m)

        # we created the block
        transBlock = m._pyomo_gdp_cuttingplane_transformation
        self.assertIsInstance(transBlock, Block)
        # the cuts are on it
        cuts = transBlock.cuts
        self.assertIsInstance(cuts, Constraint)
Exemplo n.º 5
0
 def test_create_using(self):
     m = models.makeTwoTermDisj_boxes()
     diff_apply_to_and_create_using(self, m, 'gdp.cuttingplane')
Exemplo n.º 6
0
 def test_cuts_are_correct_facets_inf_norm(self):
     m = models.makeTwoTermDisj_boxes()
     TransformationFactory('gdp.cuttingplane').apply_to(m, norm=float('inf'))
     self.check_cuts_are_correct_facets(m)
Exemplo n.º 7
0
 def test_cuts_are_correct_facets_with_tolerance(self):
     m = models.makeTwoTermDisj_boxes()
     TransformationFactory('gdp.cuttingplane').apply_to(m)
     self.check_cuts_are_correct_facets(m)
Exemplo n.º 8
0
    def test_cuts_valid_on_hull_vertices_with_tolerance(self):
        m = models.makeTwoTermDisj_boxes()
        TransformationFactory('gdp.cuttingplane').apply_to(
            m, back_off_problem_tolerance=2e-8, verbose=True)

        self.check_cuts_valid_on_hull_vertices(m, TOL=1e-8)
Exemplo n.º 9
0
    def test_cuts_valid_on_hull_vertices_fme(self):
        m = models.makeTwoTermDisj_boxes()
        TransformationFactory('gdp.cuttingplane').apply_to(
            m, create_cuts=create_cuts_fme, post_process_cut=None)

        self.check_cuts_valid_on_hull_vertices(m, TOL=0)
Exemplo n.º 10
0
 def test_cuts_valid_for_optimal_inf_norm(self):
     m = models.makeTwoTermDisj_boxes()
     TransformationFactory('gdp.cuttingplane').apply_to( m,
                                                         norm=float('inf'))
     # same tolerance as the l-2 norm version:
     self.check_cuts_valid_for_optimal(m, TOL=1e-8)
Exemplo n.º 11
0
    def test_cuts_valid_for_optimal_with_tolerance(self):
        m = models.makeTwoTermDisj_boxes()
        TransformationFactory('gdp.cuttingplane').apply_to(
            m, back_off_problem_tolerance=1e-7)

        self.check_cuts_valid_for_optimal(m, TOL=1e-8)