# How to define constraints for the PowellOptimizer?

The `PowellOptimizer` example from hipparchus

is used as follows in the Symja `NMinimize` function
`NMinimize({Sinc(x)+Sinc(y)}, {x, y})` and returns:
`{-0.434467,{x->4.49341,y->4.49341}}`

Is there an example, how I can define additional constraints?
`NMinimize({Sinc[x]+Sinc[y], x^2 + y^2 <=2}, {x, y}`which should return:
`{1.68294,{x->1.0,y->1.0}}`

We don’t have constrained optimization per se. We have been wanting to add this for… fifteen years at least.

The only thing we can do for now, and which in fact works for many cases, is to implement ParameterValidator. This takes as input the unconstrained values the optimizer would like to use for the next iteration, and it converts them to something else, taking into account any user-defined constraint.

We typically use this to clip parameters back to some domain when using an optimizer that does not take any contraint into account. As an example, in orbit determination using Keplerian elements, the orbit eccentricity must be between 0.0 and 1.0, so if the optimizer wants to try at some point an eccentricity set to -0.00001, we just clip it back to 0.0 using a custom implementation of the interface. The same thing could be done with other types of constraints (i.e. not simple boundaries like in the eccentricity case).

There is a LinearConstraintSet class in Hipparchus, but I don’t remember which optimizer is able to use it. It is based on the very ugly old `OptimizationData` hierarchy that requires reading the code to be used properly.

Yes I’m using `LinearConstraint` for the “linear case” in`SimplexSolver`.
I’m looking for something similar in the “non-linear case” for minimizing / maximizing.

From the test examples `ParameterValidator`seems to be only useful in “least squares” problems?

hi
i wrote test library for hipparcus with nonlinear costraint optimization.
It is at first version. you could use and see if suit to you.
Fra
optimization.7z (89.1 KB)
example:
TwiceDifferentiableFunction problem = new HockSchittkowskiFunction ();
InequalityConstraint ineq = new HockSchittkowskiCostraintInequality ();
EqualityConstraint eq = new HockSchittkowskiCostraintEquality();
SQPOptimizerS optimizer3 = new SQPOptimizerS() ;

``````    LagrangetSolution sol = optimizer3.optimize(new InitialGuess(new double[]{1,5,5,1}),new ObjectiveFunction(problem),ineq,eq);
``````
1 Like

Hi @roccafrancesco welcome

I will take a look at your library as soon as I get some time, thanks for sharing!

Dear @roccafrancesco,

This looks huge! Many thanks a lot for sharing !!

Hello