In this optimization problem (a single variable simplified version of mine) I have one variable and I am trying to maximize the objective. The answer should be x = 4 with an objfcnval equal to 2 since as x increases these will be the calculations 0 - 0 = 0, 1 - 2 = -1, 2 - 2 = 0, 3 - 2 = 1, 4 - 2 = 2, 5 - 4 = 1.
Here is the code:
def my_ceiling(elem1, elem2):
if (elem1 // elem2) == (elem1 / elem2):
return elem1 / elem2
else:
return (elem1 // elem2) + 1
m = gekko.GEKKO(remote=False)
m.options.SOLVER = 1
x = m.Var(value=0, lb=0, ub=5, integer=True)
m.Obj((-1) * (x - 2 * my_ceiling(x, 4)))
m.solve(disp=False)
print('Objective: ' + str((-1) * m.options.objfcnval))
if (elem1 // elem2) == (elem1 / elem2):
TypeError: unsupported operand type(s) for //: 'GKVariable' and 'int'
The problem is that apparently this kind of operation is not supported. How would I go about using Gekko for problems like these?