Exemplo n.º 1
0
 def _test_solve_interior_point_2(self, linear_solver):
     m = pyo.ConcreteModel()
     m.x = pyo.Var(bounds=(1, 4))
     m.obj = pyo.Objective(expr=m.x**2)
     interface = InteriorPointInterface(m)
     ip_solver = InteriorPointSolver(linear_solver)
     status = ip_solver.solve(interface)
     self.assertEqual(status, InteriorPointStatus.optimal)
     interface.load_primals_into_pyomo_model()
     self.assertAlmostEqual(m.x.value, 1)
Exemplo n.º 2
0
    def _test_regularization_2(self, linear_solver):
        m = make_model_2()
        interface = InteriorPointInterface(m)
        ip_solver = InteriorPointSolver(linear_solver)

        status = ip_solver.solve(interface)
        self.assertEqual(status, InteriorPointStatus.optimal)
        interface.load_primals_into_pyomo_model()
        self.assertAlmostEqual(m.x.value, 1)
        self.assertAlmostEqual(m.y.value, pyo.exp(-1))
Exemplo n.º 3
0
 def _test_solve_interior_point_1(self, linear_solver):
     m = pyo.ConcreteModel()
     m.x = pyo.Var()
     m.y = pyo.Var()
     m.obj = pyo.Objective(expr=m.x**2 + m.y**2)
     m.c1 = pyo.Constraint(expr=m.y == pyo.exp(m.x))
     m.c2 = pyo.Constraint(expr=m.y >= (m.x - 1)**2)
     interface = InteriorPointInterface(m)
     ip_solver = InteriorPointSolver(linear_solver)
     status = ip_solver.solve(interface)
     self.assertEqual(status, InteriorPointStatus.optimal)
     x = interface.get_primals()
     duals_eq = interface.get_duals_eq()
     duals_ineq = interface.get_duals_ineq()
     self.assertAlmostEqual(x[0], 0)
     self.assertAlmostEqual(x[1], 1)
     self.assertAlmostEqual(duals_eq[0], -1-1.0/3.0)
     self.assertAlmostEqual(duals_ineq[0], 2.0/3.0)
     interface.load_primals_into_pyomo_model()
     self.assertAlmostEqual(m.x.value, 0)
     self.assertAlmostEqual(m.y.value, 1)
Exemplo n.º 4
0
    def _test_regularization(self, linear_solver):
        m = make_model()
        interface = InteriorPointInterface(m)
        ip_solver = InteriorPointSolver(linear_solver)
        ip_solver.set_interface(interface)

        interface.set_barrier_parameter(1e-1)

        # Evaluate KKT matrix before any iterations
        kkt = interface.evaluate_primal_dual_kkt_matrix()
        reg_coef = ip_solver.factorize(kkt)

        # Expected regularization coefficient:
        self.assertAlmostEqual(reg_coef, 1e-4)

        desired_n_neg_evals = (ip_solver.interface.n_eq_constraints() +
                               ip_solver.interface.n_ineq_constraints())

        # Expected inertia:
        n_pos_evals, n_neg_evals, n_null_evals = linear_solver.get_inertia()
        self.assertEqual(n_null_evals, 0)
        self.assertEqual(n_neg_evals, desired_n_neg_evals)
Exemplo n.º 5
0
    def _test_ip_with_reallocation(self, linear_solver, interface):
        ip_solver = InteriorPointSolver(linear_solver,
                max_reallocation_iterations=3,
                reallocation_factor=1.1,
                # The small factor is to ensure that multiple iterations of
                # reallocation are performed. The bug in the previous
                # implementation only occurred if 2+ reallocation iterations
                # were needed (max_reallocation_iterations >= 3).
                max_iter=1)
        ip_solver.set_interface(interface)

        ip_solver.solve(interface)

        return ip_solver
Exemplo n.º 6
0
import pyomo.environ as pe
from pyomo.contrib.interior_point.interior_point import InteriorPointSolver
from pyomo.contrib.interior_point.interface import InteriorPointInterface
from pyomo.contrib.interior_point.linalg.mumps_interface import MumpsInterface
import logging


logging.basicConfig(level=logging.INFO)
# Supposedly this sets the root logger's level to INFO.
# But when linear_solver.logger logs with debug, 
# it gets propagated to a mysterious root logger with
# level NOTSET...

m = pe.ConcreteModel()
m.x = pe.Var()
m.y = pe.Var()
m.obj = pe.Objective(expr=m.x**2 + m.y**2)
m.c1 = pe.Constraint(expr=m.y == pe.exp(m.x))
m.c2 = pe.Constraint(expr=m.y >= (m.x - 1)**2)
interface = InteriorPointInterface(m)
linear_solver = MumpsInterface(
#        log_filename='lin_sol.log',
        icntl_options={11: 1}, # Set error level to 1 (most detailed)
        )

ip_solver = InteriorPointSolver(linear_solver)
x, duals_eq, duals_ineq = ip_solver.solve(interface)
print(x, duals_eq, duals_ineq)