I have an optimisation problem I'd like to solve with Gekko. Currently I'm using genetic algos.
I have a function to optimise that starts from an initial set and after a bunch of transformation returns a real number. This function is not linear, does not have analytical form, no idea about first derivatives and contains real and integer parameters. I'm trying to use APOPT solver of Gekko (with Gekko.options.SOLVER=1). This is my first time with Gekko.
My problem is the following: one of integer parameter is the size of a moving windows used in pandas.
When I create a Gekko variable, it encodes the variable in a string for internal computation and when this variable in passed to pandas the program fails because of this.
I tried to pass to pandas size.value.value to cast it as an int as a GKVariable variable, but it doesn't work.
Any suggestion for this problem?
Thanks in advance.
Here a minimal example:
from gekko import GEKKO
import numpy as np
import pandas as pd
np.random.seed(seed=1)
def fake_function(windows: int):
df = pd.DataFrame({'B': np.random.randint(10, size=(20,))})
return df.rolling(windows).sum().values[0]
m = GEKKO() # Initialize gekko
m.options.SOLVER=1 # APOPT is an MINLP solver
gekko_param = m.Var(lb=0, ub=10, integer=True)
m.Obj(fake_function(gekko_param))
m.solve(disp=True) # Solve
print(f'Objective: {m.options.objfcnval}')
