I am to maximize my non-linear function and trying to do that with GEKKO
m=GEKKO()
x=m.Var(value=1,lb=0, ub=50)
y=m.Var(value=1, lb=0, ub=50)
m.Equation(puree*x+cutlet*y==1500)
m.Obj(-min(x,y))
m.solve(disp=False)
x.value
y.value
but I get TypeError: object of type 'int' has no len() in this string m.Obj(-min(x,y)) and I don't know what to change to make it work...
Your
xandyare specific Gekko variable types, even though when you display them they display as integers. There is no min function defined on that specific type. So when you callmin, the Python builtinminfunction depends onlen, and the Gekko specificlenfunction takes as its argument the value of the variable, so effectivelymincallslen(x.value), which does not work becausex.valueis an int (equivalently fory). If you want to set your objective function to be some function ofxandy, then you need to do it as such:and Gekko will try to minimize
f. So if you just want to minimizex+y, then all you need ism.Obj(x+y).