I am trying to minimize the L2 norm of the peak flows in a drainage system. I want to use gekko since it can handle integer-binary programming.
In my program, my objective is to minimize the peak flows. I created a function that
- Inputs the vector in the inp file of the drainage model, runs, and saves it as a new file.
- Extract the peak flows in the new file.
- Returns the L2-norm of the peak flows.
Because of the complexity, I created functions for each step in my objective function. Thus, my obj function has functions. I tested my obj function with different inputs, and it runs smoothly.
The input is a vector with 8 elements. Each element must be 1 or 0. The only constraint is that the sum of the elements is 4.
Unfortunately, when I use gekko, it keeps having the error:
Exception: @error: Model Expression
*** Error in syntax of function string: Invalid element: <functionfuncat0x12fb5
b2e0>
Position: 1
<functionfuncat0x12fb5b2e0>
?
I even tried having integer = False and just added a converter in my objective function. The error is still the same. I guess that the error came from my objective function. Can anyone help me? Your response would be well appreciated.
from gekko import GEKKO
m = GEKKO(remote=False)
x = m.Array(m.Var,8,lb=0,ub=1,integer=True)
x0,x1,x2,x3,x4,x5,x6,x7 = x
def Func(x):
#Inputs x in the inp file, determines the peak flows with the new x, and saves a new file.
Mod_File('Example1.inp',x)
#Creates the file name of the modified file.
Mod_File_name = Mod_File_Name('Example1.inp')
#Extracts the Peak flows in the mod file and computes the L2 norm.
L2_Norm = Norm_Peak_Flows(Mod_File_name ,Dict_Links('Example1.inp'))
return L2_Norm
x0.value = 0
x1.value = 1
x2.value = 0
x3.value = 1
x4.value = 0
x5.value = 1
x6.value = 0
x7.value = 1
m.Minimize(Func)
m.Equation(sum(x)==4)
m.options.SOLVER=1
m.solve()
print(x)