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:

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:

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” inSimplexSolver.
I’m looking for something similar in the “non-linear case” for minimizing / maximizing.

From the test examples ParameterValidatorseems to be only useful in “least squares” problems?

i wrote test library for hipparcus with nonlinear costraint optimization.
It is at first version. you could use and see if suit to you.
optimization.7z (89.1 KB)
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);

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 !!


thanks for your contribution.
I didn’t find the source code for your optimizer in the attached 7z file.
Is it available as open source?

Hi Luc
I tried to write you a private mail from my Telespazio address but i cant reach you.

it will be

I have opened issue 296 for this and started a new branch with Francesco’s contribution.

It is not ready to be merged in the master branch, it still lacks lots of documentation, triggers a lot of checkstyle warnings (I have already fixed a few hundreds of them) and the tests are not in Junit form (they are main programs).

Thanks a lot for this tremendous work, Francesco!


Junit tests have been implemented.

A first version of the contribution has been merged into master.
It generates lots of errors in SonarQube at this stage, as javadoc and test coverage are lacking.
See issue 296.

1 Like

The SonarQube errors have now all be solved.
The project is still flagged with a red badge because we are clearly lacking a lot of tests. The current settings have been lowered to 80% on new code, but we still globally target 90% or more for all code, so we should target 90% to avoid decreasing our current status.
I cannot do this, @roccafrancesco could you take a look and add more tests to improve test coverage?

A big thank you Francesco for the original contribution and Luc for the “integration”. This is a game changer for Hipparchus I believe.



Is there an example how to define a non-linear InequalityConstraint?

For example for x^2+y^2 < 5 ?

I think this was intended with InequalityConstraintSet because it takes a collection of TwiceDifferentiableFunction as arguments, but it doesn’t seem to be used anywhere in the code…