Python Forum

Full Version: Can't minimize this simple function with constraints
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I want to minimize this objective funrtion:
-10 000 000/100*(0*p0+100*p100)
with constraints
p0^56>=0.05
p0+p100=1
0<=p0<=1
0<=p100<=1
So that i used this code
import numpy as np
from scipy.optimize import minimize
def objective(p):
    p0=p[0]
    p100=p[1]
    return -10000000/100*(0*p0+100*p100)
def constraint1(p):
    return p[0]**56-0.05
def constraint2(p):
    sum_p=1
    for i in range(2):
        sum_p=sum_p-p[i]
    return sum_p
p0=[0,0]
p1=[0.94791, 0.0520895]
#print(objective(p1))
b=(0.0,1.0)
bnds=(b,b)
con1={'type':'ineq','fun':constraint1}
con2={'type':'eq','fun':constraint2}
cons=[con1,con2]
sol=minimize(objective,p0,method='SLSQP',bounds=bnds,constraints=cons)
print(sol)
The solution should be p0=0.94791, p100=0.0520895 and f(p)=-520 895.
I've tried trust-constr,SLSQP,TNC,L-BFGS-B,COBYLA and all cant find a solution.
Please, help me.