I would like to find optimal solution for the problem discribed in the attached figure https://i.stack.imgur.com/W6fhf.jpg
My code is
from scipy.optimize import minimize
def create_constraints(t, tau, ub):
constraints = [{
'type': 'ineq',
'fun': lambda x: x[0] * (-1),
}]
con1 = {
'type': 'ineq',
'fun': lambda x: x[0] - x[1] + tau[0],
}
constraints.append(con1)
con2 = {
'type': 'ineq',
'fun': lambda x: x[1] - ub + tau[1],
}
constraints.append(con2)
return constraints
def f(x):
return (x[0] + x[1]) * (-1)
t0 = np.array([1, 10])
tau0 = [5, 5]
cons = create_constraints(t0, tau0, 30)
res = minimize(f, t0, constraints=cons, method='trust-constr')
with the above parameters for constraints I expect that optimal solution would be close to [20, 25]. However the result of optimization is x: array([ 6.66666669, 18.33333334])
. What am I doing wrong? why minimizer does not work as expected?
Any help appreciated.