Python Forum
Can't minimize this simple function with constraints
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can't minimize this simple function with constraints
#1
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Simple Python function help needed Imran23 2 2,821 Jun-07-2018, 12:20 AM
Last Post: Imran23
  minimize with scipy.optimize tobenmoben 0 2,734 Feb-17-2018, 01:47 PM
Last Post: tobenmoben

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020