Exemplo n.º 1
0
 def test_FP_8PP(self):
     """Test the feasibility pump algorithm."""
     with SolverFactory('mindtpy') as opt:
         model = EightProcessFlowsheet(convex=True)
         print('\n Solving 8PP problem using feasibility pump')
         results = opt.solve(model,
                             strategy='FP',
                             mip_solver=required_solvers[1],
                             nlp_solver=required_solvers[0],
                             bound_tolerance=1E-5)
         log_infeasible_constraints(model)
         self.assertTrue(is_feasible(model, self.get_config(opt)))
Exemplo n.º 2
0
 def test_rNLP_add_slack(self):
     """Test the outer approximation decomposition algorithm."""
     with SolverFactory('mindtpy') as opt:
         model = EightProcessFlowsheet()
         print('\n Solving problem with Outer Approximation')
         opt.solve(model,
                   strategy='OA',
                   init_strategy='rNLP',
                   mip_solver=required_solvers[1],
                   nlp_solver=required_solvers[0],
                   bound_tolerance=1E-5,
                   add_slack=True)
         self.assertAlmostEqual(value(model.cost.expr), 68, places=1)
Exemplo n.º 3
0
    def test_OA_8PP_sympy(self):
        """Test the outer approximation decomposition algorithm."""
        with SolverFactory('mindtpy') as opt:
            model = EightProcessFlowsheet(convex=False)
            print('\n Solving 8PP problem with Outer Approximation(max_binary)')
            results = opt.solve(model, strategy='OA',
                                mip_solver=required_solvers[1],
                                nlp_solver=required_solvers[0],
                                differentiate_mode='sympy')

            self.assertIs(results.solver.termination_condition,
                          TerminationCondition.optimal)
            self.assertAlmostEqual(value(model.cost.expr), 68, places=1)
Exemplo n.º 4
0
    def test_ECP_8PP_sympy(self):
        """Test the extended cutting plane decomposition algorithm."""
        with SolverFactory('mindtpy') as opt:
            model = EightProcessFlowsheet(convex=True)
            print('\n Solving 8PP problem with extended cutting plane(max_binary)')
            results = opt.solve(model, strategy='ECP',
                                mip_solver=required_solvers[1],
                                nlp_solver=required_solvers[0], obj_bound=5500,
                                differentiate_mode='sympy')

            self.assertIs(results.solver.termination_condition,
                          TerminationCondition.optimal)
            self.assertAlmostEqual(value(model.cost.expr), 68, places=1)
Exemplo n.º 5
0
 def test_rNLP_add_slack(self):
     """Test the extended cutting plane decomposition algorithm."""
     with SolverFactory('mindtpy') as opt:
         model = EightProcessFlowsheet(convex=True)
         print(
             '\n Test rNLP initialize strategy and add_slack to improve code coverage')
         opt.solve(model, strategy='ECP',
                   init_strategy='rNLP',
                   mip_solver=required_solvers[1],
                   nlp_solver=required_solvers[0],
                   bound_tolerance=1E-5,
                   add_slack=True)
         self.assertAlmostEqual(value(model.cost.expr), 68, places=1)
Exemplo n.º 6
0
 def test_FP_OA_8PP(self):
     """Test the FP-OA algorithm."""
     with SolverFactory('mindtpy') as opt:
         model = EightProcessFlowsheet(convex=True)
         print('\n Solving 8PP problem using FP-OA')
         results = opt.solve(model,
                             strategy='OA',
                             init_strategy='FP',
                             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.cost.expr), 68, places=1)
Exemplo n.º 7
0
    def test_OA_8PP_init_max_binary(self):
        """Test the outer approximation decomposition algorithm."""
        with SolverFactory('mindtpy') as opt:
            model = EightProcessFlowsheet()
            print('\n Solving problem with Outer Approximation')
            opt.solve(model,
                      strategy='OA',
                      init_strategy='max_binary',
                      mip_solver=required_solvers[1],
                      nlp_solver=required_solvers[0])

            # self.assertIs(results.solver.termination_condition,
            #               TerminationCondition.optimal)
            self.assertTrue(fabs(value(model.cost.expr) - 68) <= 1E-2)
Exemplo n.º 8
0
    def test_lazy_OA_8PP_init_max_binary(self):
        """Test the LP/NLP decomposition algorithm."""
        with SolverFactory('mindtpy') as opt:
            model = EightProcessFlowsheet()
            print('\n Solving 8PP_init_max_binary problem with LP/NLP')
            results = opt.solve(model,
                                strategy='OA',
                                init_strategy='max_binary',
                                mip_solver=required_solvers[1],
                                nlp_solver=required_solvers[0],
                                single_tree=True)

            self.assertIs(results.solver.termination_condition,
                          TerminationCondition.optimal)
            self.assertAlmostEqual(value(model.cost.expr), 68, places=1)
Exemplo n.º 9
0
    def test_OA_8PP(self):
        """Test the outer approximation decomposition algorithm."""
        with SolverFactory('mindtpy') as opt:
            model = EightProcessFlowsheet()
            print('\n Solving problem with Outer Approximation')
            results = opt.solve(model,
                                strategy='OA',
                                init_strategy='rNLP',
                                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.cost.expr), 68, places=1)
Exemplo n.º 10
0
 def test_FP_8PP_Norm_infinity_with_norm_constraint(self):
     """Test the feasibility pump algorithm."""
     with SolverFactory('mindtpy') as opt:
         model = EightProcessFlowsheet(convex=True)
         print(
             '\n Solving 8PP problem using feasibility pump with Norm infinity in mip regularization problem'
         )
         results = opt.solve(model,
                             strategy='FP',
                             mip_solver=required_solvers[1],
                             nlp_solver=required_solvers[0],
                             bound_tolerance=1E-5,
                             fp_main_norm='L_infinity',
                             fp_norm_constraint=False)
         log_infeasible_constraints(model)
         self.assertTrue(is_feasible(model, self.get_config(opt)))
Exemplo n.º 11
0
    def test_GOA_8PP_sympy(self):
        """Test the global outer approximation decomposition algorithm."""
        with SolverFactory('mindtpy') as opt:
            model = EightProcessFlowsheet(convex=True)
            print('\n Solving 8PP problem with Outer Approximation(sympy)')
            results = opt.solve(model,
                                strategy='GOA',
                                mip_solver=required_solvers[1],
                                nlp_solver=required_solvers[0],
                                differentiate_mode='sympy',
                                add_no_good_cuts=True)

            self.assertIn(
                results.solver.termination_condition,
                [TerminationCondition.optimal, TerminationCondition.feasible])
            self.assertAlmostEqual(value(model.cost.expr), 68, places=1)
Exemplo n.º 12
0
    def test_GOA_8PP_tabu_list(self):
        """Test the global outer approximation decomposition algorithm."""
        with SolverFactory('mindtpy') as opt:
            model = EightProcessFlowsheet(convex=True)
            print('\n Solving 8PP problem with Outer Approximation(tabu list)')
            results = opt.solve(model,
                                strategy='GOA',
                                init_strategy='rNLP',
                                mip_solver=required_solvers[1],
                                nlp_solver=required_solvers[0],
                                use_tabu_list=True,
                                bound_tolerance=1E-5)

            self.assertIn(
                results.solver.termination_condition,
                [TerminationCondition.optimal, TerminationCondition.feasible])
            self.assertAlmostEqual(value(model.cost.expr), 68, places=1)
Exemplo n.º 13
0
    def test_GOA_8PP_L2_norm(self):
        """Test the global outer approximation decomposition algorithm."""
        with SolverFactory('mindtpy') as opt:
            model = EightProcessFlowsheet()
            print('\n Solving 8PP problem with Outer Approximation(L2_norm)')
            results = opt.solve(model,
                                strategy='GOA',
                                mip_solver=required_solvers[1],
                                nlp_solver=required_solvers[0],
                                feasibility_norm='L2',
                                add_nogood_cuts=True,
                                single_tree=True)

            self.assertIn(
                results.solver.termination_condition,
                [TerminationCondition.optimal, TerminationCondition.feasible])
            self.assertAlmostEqual(value(model.cost.expr), 68, places=1)
Exemplo n.º 14
0
from pyomo.contrib.mindtpy.config_options import _get_MindtPy_config
from pyomo.contrib.mindtpy.util import set_up_solve_data, add_feas_slacks, set_solver_options
from pyomo.contrib.mindtpy.nlp_solve import handle_subproblem_other_termination, handle_feasibility_subproblem_tc, solve_subproblem, handle_nlp_subproblem_tc
from pyomo.core.base import TransformationFactory
from pyomo.opt import TerminationCondition as tc
from pyomo.contrib.gdpopt.util import create_utility_block, time_code, process_objective, setup_results_object
from pyomo.contrib.mindtpy.initialization import MindtPy_initialize_main, init_rNLP
from pyomo.contrib.mindtpy.feasibility_pump import generate_norm_constraint, handle_fp_main_tc
from pyomo.core import Block, ConstraintList
from pyomo.contrib.mindtpy.mip_solve import solve_main, handle_main_other_conditions
from pyomo.opt import SolutionStatus, SolverStatus
from pyomo.core import (Constraint, Objective, TransformationFactory, minimize,
                        Var, RangeSet, NonNegativeReals)
from pyomo.contrib.mindtpy.iterate import algorithm_should_terminate

nonconvex_model_list = [EightProcessFlowsheet(convex=False)]

LP_model = LP_unbounded()
LP_model._generate_model()

QCP_model = QCP_simple()
QCP_model._generate_model()
extreme_model_list = [LP_model.model, QCP_model.model]

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
Exemplo n.º 15
0
from pyomo.opt import TerminationCondition

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):
Exemplo n.º 16
0
from pyomo.contrib.mindtpy.tests.MINLP_simple import SimpleMINLP as SimpleMINLP
from pyomo.contrib.mindtpy.tests.MINLP2_simple import SimpleMINLP as SimpleMINLP2
from pyomo.contrib.mindtpy.tests.MINLP3_simple import SimpleMINLP as SimpleMINLP3
from pyomo.contrib.mindtpy.tests.from_proposal import ProposalModel
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):
Exemplo n.º 17
0
from pyomo.contrib.mindtpy.tests.nonconvex3 import Nonconvex3
from pyomo.contrib.mindtpy.tests.nonconvex4 import Nonconvex4
from pyomo.environ import SolverFactory, value
from pyomo.environ import *
from pyomo.opt import TerminationCondition

required_solvers = ('baron', 'cplex_persistent')
if not all(SolverFactory(s).available(False) for s in required_solvers):
    subsolvers_available = False
elif not SolverFactory('baron').license_is_valid():
    subsolvers_available = False
else:
    subsolvers_available = True

model_list = [
    EightProcessFlowsheet(convex=False),
    Nonconvex1(),
    Nonconvex2(),
    Nonconvex3(),
    Nonconvex4(),
]


@unittest.skipIf(not subsolvers_available,
                 'Required subsolvers %s are not available' %
                 (required_solvers, ))
@unittest.skipIf(not pyomo.core.base.symbolic.differentiate_available,
                 'Symbolic differentiation is not available')
@unittest.skipIf(not pyomo.contrib.mcpp.pyomo_mcpp.mcpp_available(),
                 'MC++ is not available')
class TestMindtPy(unittest.TestCase):
Exemplo n.º 18
0
    EightProcessFlowsheet
from pyomo.contrib.mindtpy.tests.MINLP_simple import SimpleMINLP as SimpleMINLP
from pyomo.contrib.mindtpy.tests.MINLP2_simple import SimpleMINLP as SimpleMINLP2
from pyomo.contrib.mindtpy.tests.MINLP3_simple import SimpleMINLP as SimpleMINLP3
from pyomo.contrib.mindtpy.tests.MINLP4_simple import SimpleMINLP4
from pyomo.contrib.mindtpy.tests.MINLP5_simple import SimpleMINLP5
from pyomo.contrib.mindtpy.tests.from_proposal import ProposalModel
from pyomo.contrib.mindtpy.tests.constraint_qualification_example import ConstraintQualificationExample
from pyomo.contrib.mindtpy.tests.online_doc_example import OnlineDocExample
from pyomo.environ import SolverFactory, value, maximize
from pyomo.solvers.tests.models.LP_unbounded import LP_unbounded
from pyomo.solvers.tests.models.QCP_simple import QCP_simple
from pyomo.opt import TerminationCondition


full_model_list = [EightProcessFlowsheet(convex=True),
                   ConstraintQualificationExample(),
                   SimpleMINLP(),
                   SimpleMINLP2(),
                   SimpleMINLP3(),
                   SimpleMINLP4(),
                   SimpleMINLP5(),
                   ProposalModel(),
                   OnlineDocExample()
                   ]
model_list = [EightProcessFlowsheet(convex=True),
              ConstraintQualificationExample(),
              SimpleMINLP2(),
              #   SimpleMINLP(),
              #   SimpleMINLP3(),
              #   SimpleMINLP4(),