Example #1
0
    def _test_regularization_2(self, linear_solver):
        m = make_model_2()
        interface = ip.InteriorPointInterface(m)
        ip_solver = ip.InteriorPointSolver(linear_solver)

        x, duals_eq, duals_ineq = ip_solver.solve(interface)
        self.assertAlmostEqual(x[0], 1)
        self.assertAlmostEqual(x[1], pe.exp(-1))
Example #2
0
    def _test_regularization_2(self, linear_solver):
        m = make_model_2()
        interface = ip.InteriorPointInterface(m)
        ip_solver = ip.InteriorPointSolver(linear_solver)

        status = ip_solver.solve(interface)
        self.assertEqual(status, ip.InteriorPointStatus.optimal)
        interface.load_primals_into_pyomo_model()
        self.assertAlmostEqual(m.x.value, 1)
        self.assertAlmostEqual(m.y.value, pe.exp(-1))
Example #3
0
 def _test_solve_interior_point_2(self, linear_solver):
     m = pe.ConcreteModel()
     m.x = pe.Var(bounds=(1, 4))
     m.obj = pe.Objective(expr=m.x**2)
     interface = ip.InteriorPointInterface(m)
     ip_solver = ip.InteriorPointSolver(linear_solver)
     status = ip_solver.solve(interface)
     self.assertEqual(status, ip.InteriorPointStatus.optimal)
     interface.load_primals_into_pyomo_model()
     self.assertAlmostEqual(m.x.value, 1)
Example #4
0
 def _test_solve_interior_point_1(self, linear_solver):
     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 = ip.InteriorPointInterface(m)
     ip_solver = ip.InteriorPointSolver(linear_solver)
     #        x, duals_eq, duals_ineq = solve_interior_point(interface, linear_solver)
     x, duals_eq, duals_ineq = ip_solver.solve(interface)
     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)
Example #5
0
    def _test_regularization(self, linear_solver):
        m = make_model()
        interface = ip.InteriorPointInterface(m)
        ip_solver = ip.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)