HS071 Optimization Problem
For a description of the HS071 parameter optimization problem, see the JupyterLab notebook documentation for this problem.
The python script in this example can be executed from the command line with:
$ python -m yapss.examples.hs071
Functions
YAPSS solution of the HS071 constrained function minimization problem.
- main() None[source]
Demonstrate the solution to the HS071 constrained function minimization problem.
Code
"""
YAPSS solution of the HS071 constrained function minimization problem.
"""
__all__ = ["main", "print_solution", "setup"]
import numpy as np
# third party imports
from numpy.typing import NDArray
# package imports
from yapss import DiscreteArg, ObjectiveArg, Problem, Solution
def setup() -> Problem:
"""Set up the problem statement for Hock and Schittkowski Problem 71 (HS071)."""
# parameter optimization problem with 4 parameters and 2 constraints
ocp = Problem(name="HS071", nx=[], ns=4, nd=2)
def objective(arg: ObjectiveArg) -> None:
"""HS071 objective callback function."""
x = arg.parameter
arg.objective = x[0] * x[3] * (x[0] + x[1] + x[2]) + x[2]
def discrete(arg: DiscreteArg) -> None:
"""HS071 discrete constraint callback function."""
x = arg.parameter
arg.discrete[:] = (
x[0] * x[1] * x[2] * x[3],
x[0] * x[0] + x[1] * x[1] + x[2] * x[2] + x[3] * x[3],
)
ocp.functions.objective = objective
ocp.functions.discrete = discrete
# bounds
ocp.bounds.discrete.lower = 25.0, 40.0
ocp.bounds.discrete.upper[1] = 40.0
ocp.bounds.parameter.lower = 4 * [1.0]
ocp.bounds.parameter.upper = 4 * [5.0]
# guess
ocp.guess.parameter = 1.0, 5.0, 5.0, 1.0
# yapss options
ocp.derivatives.order = "second"
ocp.derivatives.method = "auto"
ocp.ipopt_options.print_level = 5
return ocp
def print_solution(solution: Solution) -> None:
"""Print the solution of the HS071 constrained function minimization problem.
Parameters
----------
solution : Solution
The solution of the HS071 function minimization problem.
"""
def print_variable(name: str, values: NDArray[np.float64]) -> None:
for i, _value in enumerate(values):
print(f"{name}[{i}] = {_value:1.6e}")
x = solution.parameter
print()
print("Solution of the primal variables, x")
print_variable("x", x)
print("\nSolution of the bound multipliers, z_L and z_U")
nlp_info = solution.nlp_info
print_variable("z_L", nlp_info.mult_x_L)
print_variable("z_U", nlp_info.mult_x_U)
print("\nSolution of the constraint multipliers, lambda")
print_variable("lambda", solution.discrete_multiplier)
print("\nObjective value")
print(f"f(x*) = {solution.objective:1.6e}")
def main() -> None:
"""Demonstrate the solution to the HS071 constrained function minimization problem."""
problem = setup()
solution = problem.solve()
print_solution(solution)
if __name__ == "__main__":
main()
Text Output
******************************************************************************
This program contains Ipopt, a library for large-scale nonlinear optimization.
Ipopt is released as open source code under the Eclipse Public License (EPL).
For more information visit https://github.com/coin-or/Ipopt
******************************************************************************
This is Ipopt version 3.14.11, running with linear solver spral.
Number of nonzeros in equality constraint Jacobian...: 4
Number of nonzeros in inequality constraint Jacobian.: 4
Number of nonzeros in Lagrangian Hessian.............: 15
Total number of variables............................: 4
variables with only lower bounds: 0
variables with lower and upper bounds: 4
variables with only upper bounds: 0
Total number of equality constraints.................: 1
Total number of inequality constraints...............: 1
inequality constraints with only lower bounds: 1
inequality constraints with lower and upper bounds: 0
inequality constraints with only upper bounds: 0
iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls
0 1.6109693e+01 1.12e+01 5.28e-01 0.0 0.00e+00 - 0.00e+00 0.00e+00 0
1 1.7410406e+01 7.49e-01 2.25e+01 -0.3 7.97e-01 - 3.19e-01 1.00e+00f 1
2 1.8001613e+01 7.52e-03 4.96e+00 -0.3 5.60e-02 2.0 9.97e-01 1.00e+00h 1
3 1.7199482e+01 4.00e-02 4.24e-01 -1.0 9.91e-01 - 9.98e-01 1.00e+00f 1
4 1.6940955e+01 1.59e-01 4.58e-02 -1.4 2.88e-01 - 9.66e-01 1.00e+00h 1
5 1.7003411e+01 2.16e-02 8.42e-03 -2.9 7.03e-02 - 9.68e-01 1.00e+00h 1
6 1.7013974e+01 2.03e-04 8.65e-05 -4.5 6.22e-03 - 1.00e+00 1.00e+00h 1
7 1.7014017e+01 2.76e-07 2.18e-07 -10.3 1.43e-04 - 9.99e-01 1.00e+00h 1
8 1.7014017e+01 2.13e-14 2.29e-14 -11.0 1.04e-07 - 1.00e+00 1.00e+00h 1
Number of Iterations....: 8
(scaled) (unscaled)
Objective...............: 1.7014017140224134e+01 1.7014017140224134e+01
Dual infeasibility......: 2.2928101314633036e-14 2.2928101314633036e-14
Constraint violation....: 2.1316282072803006e-14 2.1316282072803006e-14
Variable bound violation: 9.9907857542547163e-09 9.9907857542547163e-09
Complementarity.........: 1.0023967333275279e-11 1.0023967333275279e-11
Overall NLP error.......: 1.0023967333275279e-11 1.0023967333275279e-11
Number of objective function evaluations = 9
Number of objective gradient evaluations = 9
Number of equality constraint evaluations = 9
Number of inequality constraint evaluations = 9
Number of equality constraint Jacobian evaluations = 9
Number of inequality constraint Jacobian evaluations = 9
Number of Lagrangian Hessian evaluations = 8
Total seconds in IPOPT (w/o function evaluations) = 0.013
Total seconds in NLP function evaluations = 0.008
EXIT: Optimal Solution Found.
Solution of the primal variables, x
x[0] = 1.000000e+00
x[1] = 4.743000e+00
x[2] = 3.821150e+00
x[3] = 1.379408e+00
Solution of the bound multipliers, z_L and z_U
z_L[0] = 1.087871e+00
z_L[1] = 2.671608e-12
z_L[2] = 3.544911e-12
z_L[3] = 2.635449e-11
z_U[0] = 2.499943e-12
z_U[1] = 3.896984e-11
z_U[2] = 8.482036e-12
z_U[3] = 2.762163e-12
Solution of the constraint multipliers, lambda
lambda[0] = -5.522937e-01
lambda[1] = 1.614686e-01
Objective value
f(x*) = 1.701402e+01