I'm using SciPy for optimization and the method SLSQP seems to ignore my constraints.
Specifically, I want x[3] and x[4] to be in the range [0-1]
I'm getting the message: 'Inequality constraints incompatible'
Here is the results of the execution followed by an example code (uses a dummy function):
status: 4
success: False
njev: 2
nfev: 24
fun: 0.11923608071680103
x: array([-10993.4278558 , -19570.77080806, -23495.15914299, -26531.4862831 ,
4679.97660534])
message: 'Inequality constraints incompatible'
jac: array([ 12548372.4766904 , 12967696.88362279, 39928956.72239509,
-9224613.99092537, 3954696.30747453, 0. ])
nit: 2
Here is my code:
from random import random
from scipy.optimize import minimize
def func(x):
""" dummy function to optimize """
print 'x'+str(x)
return random()
my_constraints = ({'type':'ineq', 'fun':lambda(x):1-x[3]-x[4]},
{'type':'ineq', 'fun':lambda(x):x[3]},
{'type':'ineq', 'fun':lambda(x):x[4]},
{'type':'ineq', 'fun':lambda(x):1-x[4]},
{'type':'ineq', 'fun':lambda(x):1-x[3]})
minimize(func, [57.9499 ,-18.2736,1.1664,0.0000,0.0765],
method='SLSQP',constraints=my_constraints)
EDIT - The problem persists when even when removing the first constraint.
The problem persists when I try to use the bounds variables. i.e.,
bounds_pairs = [(None,None),(None,None),(None,None),(0,1),(0,1)]
minimize(f,initial_guess,method=method_name,bounds=bounds_pairs,constraints=non_negative_prob)