def test_expected_two_segment_cut(self): m = models.twoSegments_SawayaGrossmann() # have to make M big for the bigm relaxation to be the box 0 <= x <= 3, # 0 <= Y <= 1 (in the limit) TransformationFactory('gdp.cuttingplane').apply_to(m, bigM=1e6, verbose=True) self.check_expected_two_segment_cut(m)
def test_expected_two_segment_cut_fme(self): m = models.twoSegments_SawayaGrossmann() # have to make M big for the bigm relaxation to be the box 0 <= x <= 3, # 0 <= Y <= 1 (in the limit) TransformationFactory('gdp.cuttingplane').apply_to( m, bigM=1e6, create_cuts=create_cuts_fme, post_process_cut=None) self.check_expected_two_segment_cut(m)
def test_integer_arithmetic_cuts_valid_inf_norm(self): m = models.twoSegments_SawayaGrossmann() # have to make M big for the bigm relaxation to be the box 0 <= x <= 3, # 0 <= Y <= 1 (in the limit) TransformationFactory('gdp.cuttingplane').apply_to( m, bigM=1e6, create_cuts=create_cuts_fme, norm=float('inf'), post_process_cut=None, do_integer_arithmetic=True) cuts = m._pyomo_gdp_cuttingplane_transformation.cuts self.check_expected_two_segment_cut_exact(cuts)
def test_non_unique_cut_name_error(self): m = models.twoSegments_SawayaGrossmann() self.assertRaisesRegex( GDP_Error, "cuts_name was specified as 'disj1', but this is " "already a component on the instance! Please " "specify a unique name.", TransformationFactory('gdp.cuttingplane').apply_to, m, cuts_name="disj1")
def test_two_segment_cuts_valid(self): m = models.twoSegments_SawayaGrossmann() # add stupid variable to make sure that we don't require everything in # rBigM to be useful. m.will_be_stale = Var() # have to make M big for the bigm relaxation to be the box 0 <= x <= 3, # 0 <= Y <= 1 (in the limit) TransformationFactory('gdp.cuttingplane').apply_to(m, bigM=1e6) self.check_two_segment_cuts_valid(m)
def test_expected_two_segment_cut_inf_norm(self): m = models.twoSegments_SawayaGrossmann() # make sure this is fine if dual Suffix is already on model m.dual = Suffix(direction=Suffix.IMPORT) # have to make M big for the bigm relaxation to be the box 0 <= x <= 3, # 0 <= Y <= 1 (in the limit) TransformationFactory('gdp.cuttingplane').apply_to( m, bigM=1e6, norm=float('inf'), post_process_cut=None) self.check_expected_two_segment_cut(m)
def test_deactivated_objectives_ignored(self): m = models.twoSegments_SawayaGrossmann() # add an opposite direction objective, but deactivate it m.another_obj = Objective(expr=m.x - m.disj2.indicator_var, sense=maximize) m.another_obj.deactivate() # have to make M big for the bigm relaxation to be the box 0 <= x <= 3, # 0 <= Y <= 1 (in the limit) TransformationFactory('gdp.cuttingplane').apply_to(m, bigM=1e6, verbose=True) self.check_expected_two_segment_cut(m)
def test_cuts_named_correctly(self): m = models.twoSegments_SawayaGrossmann() # have to make M big for the bigm relaxation to be the box 0 <= x <= 3, # 0 <= Y <= 1 (in the limit) TransformationFactory('gdp.cuttingplane').apply_to( m, bigM=1e6, create_cuts=create_cuts_fme, cuts_name="perfect_cuts", post_process_cut=None, do_integer_arithmetic=True) cuts = m.component("perfect_cuts") self.assertIsInstance(cuts, Constraint) self.assertIsNone( m._pyomo_gdp_cuttingplane_transformation.component("cuts")) self.check_expected_two_segment_cut_exact(cuts)
def test_two_segment_cuts_valid_inf_norm(self): m = models.twoSegments_SawayaGrossmann() # make sure this is fine if there is a random component called dual: # Note that this not only tests that we handle the creating of the dual # Suffix correctly, but also that we handle a stupid variable in rBigM # that will come back stale and really shouldn't be in the separation # problem. m.dual = Var() # have to make M big for the bigm relaxation to be the box 0 <= x <= 3, # 0 <= Y <= 1 (in the limit) # This one has to post process, but it is correct with the default # settings. TransformationFactory('gdp.cuttingplane').apply_to( m, bigM=1e6, norm=float('inf')) self.check_two_segment_cuts_valid(m)