j-asefa / slsqp4j

A JVM wrapper for the popular SLSQP optimizer
Other
27 stars 7 forks source link

Constraint with more than one variable #10

Open alexBoal opened 2 years ago

alexBoal commented 2 years ago

Hi,

I have a question...is it possible to define a constraint with more than one variable? As an e.g.: Our input vector is x= {-1, 1}. We have some bounds like: 0 < x < 5 and y >= 0. Is it possible to define a constraint like y - x^2 >= 0? If yes, how is it done if in input we only has x? Should we have as input x and y?

Thanks ;)

jamesasefa commented 2 years ago

Hi @alexBoal yes this is possible, see the example in https://github.com/j-asefa/slsqp4j/blob/master/slsqp4j/src/test/java/com/skew/slsqp4j/TestUtil.java#L125

You'd want something like:

    public static final class YourFunc implements Vector2VectorFunc
    {
        @Override
        public double[] apply(double[] x, double... arg)
        {
            return new double[] {x[0], - (x[1] * x[1]) };
        }
    }

And define this as a VectorConstraint with constraintType = INEQ