I need to solve an optimal control problem with an objective function minimization solution. The reference for me is the APM example available at: https://www.youtube.com/watch?v=y26X-BSf8KU&list=PLLBUgWXdTBDjxcpH9hRuq-bsm_ti2UvoB&index=12.
My objective function is Z => integration exp(-r*t)*C(t).dt, where C(t) = Ii.ai + Ij.aj. Ii and Ij are the manipulated variables and ai, aj and r are constants. The goal is min Z.
The problem is subject to the following constraints: dKi/dt = Ii – deltai.Ki; dKj/dt = Ij – deltaj.Kj; and Ki = (D-B.Kj-E)/A. Ki and Kj are variables and the initial values Ki0 and Kj0 are known. D, A, B, deltai, deltaj and E are constants coefficients.
I have developed a Gekko / python script as follow. However, the optimization script not achieves a solution (“Exception: @error: Solution Not Found”. I have tried to change the initial conditions and the initial guess but I haven´t achieve the solution.
from gekko import GEKKO
import numpy as np
import matplotlib.pyplot as plt
import math
#Create Gekko model
m=GEKKO()
#Time points
nt=101
m.time=np.linspace(0,10,nt)
t = m.Param(value=m.time)
#Constants
A=-0.0000159
B=-0.0000506
E=0.614
deltai=0.031
deltaj=0.1
ai=10
aj=27632
r=0.085
Ii=m.MV(value=100)
Ij=m.MV(value=100)
Ii.STATUS=1
Ii.COST=0
Ij.STATUS=1
Ij.COST=0
Ki=m.Var(value=15.548)
Kj=m.Var(value=0.932)
m.Equation(Ki.dt()==Ii-deltai*Ki)
m.Equation(Kj.dt()==Ij-deltaj*Kj)
m.Equation(Ki==(0.577-B*Kj-E)/A)
#Objective
Z=m.Var()
#Final objective
Zf=m.FV()
Zf.STATUS=1
m.Connection(Zf, Z, pos2='end')
m.Equation(Z.dt() == ((m.exp(-r*t)))*(Ii*ai+Ij*aj))
m.Obj(Zf)
#Options
m.options.IMODE=6
m.options.NODES=3
m.options.SOLVER=3
m.solve()