Closed tdincer closed 3 years ago
Sure, use the m.max3()
or m.max2()
functions. There is more information in the documentation: https://gekko.readthedocs.io/en/latest/model_methods.html?highlight=max3#logical-functions
I am aware of the max2 and max3 functions. These functions compare only two inputs. In my case, X+B is an N dimensional array. Is the only solution to compare each element of X+B with another one by one?
Try list comprehensions and loops:
X = [x1, x2, x3, xN] #(decision variables)
B = [b1, b2, b3, bN] #(a constant vector)
n = len(B)
Y = [X[i]+B[i] for i in range(n)]
mx = 0
for i in range(n):
mx = m.max3(mx,Y[i])
Cost = Some stuff + mx
Thank you so much! This is very useful. I think a model building function that would do this operation would be a nice addition to the GEKKO library.
I agree. The np.vectorize()
function may help.
Great library! Thank you for your amazing work and making GEKKO public.
I have a question! My cost function involves a maximum operator, which returns the maximum of decision variables in addition to another term. Is there an easy way in GEKKO to write this maximum operator?
My problem can be described as follows:
X = x1, x2, x3, ... , xN - (decision variables) B = b1, b2, b3, ... , bN - (a constant vector)
Cost(X) = Some stuff + max(X + B)