Source code for yapss.examples.hs071

"""

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


[docs] 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
[docs] 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()