sci.py minimize - constrain function argument

73 views Asked by At

I need to constrain a variable that is argument of optimization below a certain value EQ<1000. #function that produces the variable is the following:

def fEQ(iEQ, iC, iTATM, index):
    if index==0:
       return iC[0]
    else:
       return iEQ[0]/psi*iTATM[index]**2

t = np.arange(1, 101)
NT = len(t)
EQ=np.zeros(NT)

#The objective function (omitted some functions to make some clarity - they are all interrelated in reality)

def fOBJ(x,sign,iI, iCPRICE,iEQ,iPERIODU,iCEMUTOTPER,iRI,iNT):

iMIU = x[0:NT]
iS = x[NT:(2*NT)]

for i in range(iNT):
    iCPRICE[i] = fCPRICE(iMIU,i)
    iI[i] = fI(iS,iY,i)
    iEQ[i]=fEQ(iEQ,iC,iTATM,i)
    iPERIODU[i] = fPERIODU(iC,iEQ,il,i)
    iCEMUTOTPER[i] = fCEMUTOTPER(iPERIODU,il,i)
    iRI = fRI(iCPC,i)
    
resUtility = np.zeros(1)
fUTILITY(iCEMUTOTPER, resUtility)

return sign*resUtility[0]

#Optimization

result = opt.minimize(fOBJ, x_start, args=(-1.0,CPRICE,I,EQ,PERIODU,CEMUTOTPER,RI,NT), method='SLSQP',bounds = tuple(bnds),options={'disp': True, 'maxiter':1000 }, constraints={'type':'ineq','fun':lambda EQ: EQ[NT]-1000})

Output of the optimization is "Positive directional derivative for linesearch (Exit mode 8)", it cannot find an optimum. Hovewer I have the suspect that my constraint is not fully working. Any suggestions?

0

There are 0 answers