Exemplo n.º 1
0
 def test_time_limit(self):
     with SolverFactory('mindtpy') as opt:
         model = ConstraintQualificationExample()
         opt.solve(model, strategy='OA',
                   time_limit=1,
                   mip_solver=required_solvers[1],
                   nlp_solver=required_solvers[0]
                   )
Exemplo n.º 2
0
 def test_iteration_limit(self):
     with SolverFactory('mindtpy') as opt:
         model = ConstraintQualificationExample()
         print('\n test iteration_limit  to improve code coverage')
         opt.solve(model,
                   strategy='OA',
                   iteration_limit=1,
                   mip_solver=required_solvers[1],
                   nlp_solver=required_solvers[0])
Exemplo n.º 3
0
 def test_OA_ConstraintQualificationExample(self):
     with SolverFactory('mindtpy') as opt:
         model = ConstraintQualificationExample()
         print('\n Solving Constraint Qualification Example with Outer Approximation')
         results = opt.solve(model, strategy='OA',
                             mip_solver=required_solvers[1],
                             nlp_solver=required_solvers[0]
                             )
         self.assertIs(results.solver.termination_condition,
                       TerminationCondition.optimal)
         self.assertAlmostEqual(value(model.objective.expr), 3, places=2)
Exemplo n.º 4
0
 def test_lazy_OA_ConstraintQualificationExample(self):
     with SolverFactory('mindtpy') as opt:
         model = ConstraintQualificationExample()
         print('\n Solving ConstraintQualificationExample with LP/NLP')
         results = opt.solve(model,
                             strategy='OA',
                             mip_solver=required_solvers[1],
                             nlp_solver=required_solvers[0],
                             single_tree=True)
         self.assertIs(results.solver.termination_condition,
                       TerminationCondition.feasible)
         self.assertAlmostEqual(value(model.objective.expr), 3, places=2)
Exemplo n.º 5
0
 def test_ECP_ConstraintQualificationExample(self):
     with SolverFactory('mindtpy') as opt:
         model = ConstraintQualificationExample()
         print(
             '\n Solving Constraint Qualification Example with extended cutting plane')
         results = opt.solve(model, strategy='ECP',
                             mip_solver=required_solvers[1],
                             nlp_solver=required_solvers[0], bound_tolerance=1e-5
                             )
         self.assertIs(results.solver.termination_condition,
                       TerminationCondition.optimal)
         self.assertAlmostEqual(value(model.objective.expr), 3, places=2)
Exemplo n.º 6
0
    def test_fp_ConstraintQualificationExample(self):
        """Test the feasibility pump algorithm."""
        # TODO: bug fix
        with SolverFactory('mindtpy') as opt:
            model = ConstraintQualificationExample()
            print('\n Solving ProposalModel 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)))
Exemplo n.º 7
0
 def test_GOA_ConstraintQualificationExample_integer_cut_tabu_list(self):
     with SolverFactory('mindtpy') as opt:
         model = ConstraintQualificationExample()
         print(
             '\n Solving Constraint Qualification Example with global Outer Approximation(no-good cuts, tabu list)'
         )
         results = opt.solve(model,
                             strategy='GOA',
                             mip_solver=required_solvers[1],
                             nlp_solver=required_solvers[0],
                             use_tabu_list=True)
         self.assertIn(
             results.solver.termination_condition,
             [TerminationCondition.optimal, TerminationCondition.feasible])
         self.assertAlmostEqual(value(model.objective.expr), 3, places=2)
Exemplo n.º 8
0
required_nlp_solvers = 'ipopt'
required_mip_solvers = ['cplex_persistent', 'gurobi_persistent']
available_mip_solvers = [
    s for s in required_mip_solvers if SolverFactory(s).available(False)
]

if SolverFactory(required_nlp_solvers).available(
        False) and available_mip_solvers:
    subsolvers_available = True
else:
    subsolvers_available = False

model_list = [
    EightProcessFlowsheet(convex=True),
    ConstraintQualificationExample(),
    SimpleMINLP()
]


@unittest.skipIf(not subsolvers_available,
                 'Required subsolvers %s are not available' %
                 ([required_nlp_solvers] + required_mip_solvers))
@unittest.skipIf(not pyomo.core.base.symbolic.differentiate_available,
                 'Symbolic differentiation is not available')
class TestMindtPy(unittest.TestCase):
    """Tests for the MindtPy solver plugin."""
    @unittest.skipUnless('cplex_persistent' in available_mip_solvers,
                         'cplex_persistent solver is not available')
    def test_LPNLP_CPLEX(self):
        """Test the LP/NLP decomposition algorithm."""