def test_fp_MINLP3_simple(self): """Test the feasibility pump algorithm.""" with SolverFactory('mindtpy') as opt: model = SimpleMINLP3() print('\n Solving SimpleMINLP3 using feasibility pump') results = opt.solve(model, strategy='FP', mip_solver=required_solvers[1], nlp_solver=required_solvers[0], iteration_limit=30) self.assertTrue(is_feasible(model, self.get_config(opt)))
def test_ECP_MINLP3_simple(self): """Test the extended cutting plane decomposition algorithm.""" with SolverFactory('mindtpy') as opt: model = SimpleMINLP3() print('\n Solving MINLP3_simple problem with extended cutting plane') results = opt.solve(model, strategy='ECP', init_strategy='initial_binary', mip_solver=required_solvers[1], nlp_solver=required_solvers[0]) self.assertIs(results.solver.termination_condition, TerminationCondition.optimal) self.assertAlmostEqual(value(model.cost.expr), -5.512, places=2)
def test_FP_OA_MINLP3_simple(self): """Test the FP-OA algorithm.""" with SolverFactory('mindtpy') as opt: model = SimpleMINLP3() print('\n Solving SimpleMINLP3 using FP-OA') results = opt.solve(model, strategy='OA', init_strategy='FP', mip_solver=required_solvers[1], nlp_solver=required_solvers[0], iteration_limit=30) self.assertIs(results.solver.termination_condition, TerminationCondition.optimal) self.assertAlmostEqual(value(model.cost.expr), -5.512, places=2)
def test_OA_MINLP3_simple(self): """Test the outer approximation decomposition algorithm.""" with SolverFactory('mindtpy') as opt: model = SimpleMINLP3() print('\n Solving problem with Outer Approximation') results = opt.solve(model, strategy='OA', init_strategy='initial_binary', mip_solver=required_solvers[1], nlp_solver=required_solvers[0], obj_bound=10) self.assertIs(results.solver.termination_condition, TerminationCondition.optimal) self.assertAlmostEqual(value(model.cost.expr), -5.512, places=2)
def test_lazy_OA_MINLP3_simple(self): """Test the LP/NLP decomposition algorithm.""" with SolverFactory('mindtpy') as opt: model = SimpleMINLP3() print('\n Solving MINLP3_simple problem with LP/NLP') results = opt.solve(model, strategy='OA', init_strategy='initial_binary', mip_solver=required_solvers[1], nlp_solver=required_solvers[0], obj_bound=10, single_tree=True) # TODO: fix the bug of bound here # self.assertIs(results.solver.termination_condition, # TerminationCondition.optimal) self.assertAlmostEqual(value(model.cost.expr), -5.512, places=2)
def test_GOA_MINLP3_simple(self): """Test the global outer approximation decomposition algorithm.""" with SolverFactory('mindtpy') as opt: model = SimpleMINLP3() print('\n Solving MINLP3_simple problem with Outer Approximation') results = opt.solve(model, strategy='GOA', init_strategy='initial_binary', mip_solver=required_solvers[1], nlp_solver=required_solvers[0], obj_bound=10, add_nogood_cuts=True, use_mcpp=True, single_tree=True) self.assertIs(results.solver.termination_condition, TerminationCondition.feasible) self.assertAlmostEqual(value(model.cost.expr), -5.512, places=2)
from pyomo.contrib.mindtpy.tests.constraint_qualification_example import ConstraintQualificationExample from pyomo.environ import SolverFactory, value from pyomo.opt import TerminationCondition required_solvers = ('ipopt', 'glpk') # required_solvers = ('gams', 'gams') if all(SolverFactory(s).available() for s in required_solvers): subsolvers_available = True else: subsolvers_available = False model_list = [EightProcessFlowsheet(convex=True), ConstraintQualificationExample(), SimpleMINLP(), SimpleMINLP2(), SimpleMINLP3(), ProposalModel(), ] @unittest.skipIf(not subsolvers_available, 'Required subsolvers %s are not available' % (required_solvers,)) class TestMindtPy(unittest.TestCase): """Tests for the MindtPy solver plugin.""" def test_ECP(self): """Test the extended cutting plane decomposition algorithm.""" with SolverFactory('mindtpy') as opt: for model in model_list: results = opt.solve(model, strategy='ECP',