pythonmathematical-optimizationgekkoipopt

How does GEKKO integrals choose the variable to be integrated?


I am building an optimization model where the objective function features one variable that needs to be integrated, while another variable is part of the integrated function, whithout being itself integrated. How do I make sure that GEKKO integrates over the right variable ?

Here is my code :

m = GEKKO()

m.time = np.linspace(0.7 ,1.7,100)

z1 = m.Var( lb = 0.7)
Z = m.Var()
x = m.Var( lb = 1)

Z = m.Intermediate( m.integral( (z1 * 4.67 +x**0.27) ** 11.03 / (x **3) ) )

m.Obj(Z)

m.options.IMODE = 6
m.solve()

I need to make sure that variable z1 is integrated overm.time, while variable x acts as a parameter in the integrated expression (and can be manipulated by the solver).

Note : this is a simplified model, I normally run a discrete time optimization model, where x is time bound over T periods (e.g. defined as an m.array of dimension T)


Solution

  • The m.integral() function integrates whatever is in the parenthesis. Here is modified code to only integrate z1:

    from gekko import GEKKO
    import numpy as np
    
    m = GEKKO()
    
    m.time = np.linspace(0.7 ,1.7,100)
    
    z1 = m.Var(lb = 0.7)
    x  = m.Var(lb = 1)
    
    # zeros everywhere except 1 at the final time point
    p = np.zeros_like(m.time)
    p[-1] = 1
    final = m.Param(p)
    
    # integral of z1
    z1i = m.integral(z1)
    
    # define objective everywhere in time horizon
    obj = m.Intermediate((z1i*4.67+x**0.27)**11.03/(x**3))
    
    # minimize only at final time
    m.Minimize(obj*final)
    
    # solve
    m.options.IMODE = 6
    m.solve()
    

    Define a final parameter to minimize only at the final point in the time horizon.