let us consider following code :
from scipy.optimize import minimize
def obj(x):
x1 =x[0]
x2 =x[1]
x3 =x[2]
return (x1*1000+x2*1000+x3*500)
def constr(x):
x1 = x[0]
x2 = x[1]
x3 = x[2]
return 150-(x1+x2+x3)
bound_x1 =(0,None)
bound_x2 =(0,None)
bound_x3 =(0,None)
const_form ={"type":"ineq","fun":constr}
x0 =[0,0,0]
result =minimize(obj,x0,method ='SLSQP',constraints=const_form,bounds=[bound_x1,bound_x2,bound_x3])
print(result['x'])
print(result)
this problem is taken from the following site :Optimization
i want to maximize, if i run this program , result is :
minimization works pretty fine, but i want maximization, based on a little research, i have updated code like this :
def obj(x,sign=-1.0):
x1 =x[0]
x2 =x[1]
x3 =x[2]
return (x1*1000+x2*1000+x3*500)*sign
and got following output :
based on website, the answer should be :
is there anything missed in my code?