I successfully performed this simulation in mode 6, this is a microalgae model. I want to compare it with mode 9. But mode 9 is always infeasible. Any suggestion? About how can I fix mode 9? I try we different initial conditions but ti doest not work
#%% Bennatia Model Dynamic Optimization
#v 2.1
from gekko import GEKKO
import numpy as np
#Initialize model
m = GEKKO (remote=True)
#% Parameters
mu_ = m.Param(value=2, name="u");
rho_m = m.Param(value=9.3, name="rhom");
K_Q = m.Param(value=1.8, name="KQ");
K_s = m.Param(value=0.105, name="KS");
S_in = m.Param(value=100, name="S_in");
K_sI = m.Param(value=150, name="KsI");
K_iI = m.Param(value=2000, name="KiI");
mu_I = m.Param(value=0.6461, name="muI");
# Define Dilution rate as Manipulated variable
D = m.MV(value=0.1, lb=0.001, ub=2);
# Manipulated variable
D.STATUS = 1 # allow optimizer to change
D.DCOST = 0.1 # smooth out D movement
D.DMAX = 0.1 # slow down D
#%% Variables
# Constrains Equations
# x > 0, Q < 8.9969 , Q > 1.8, s > 0, s < 120
x = m.Var(value=0.2, lb=0 , ub=100, name ='x');
Q = m.Var(value=1.8, lb=1.8 , ub=8.9969, name = 'Q');
s = m.Var(value=0.01, lb=0 , ub=100, name = 's') ;
mu = m.Var(value=0.1, lb=0 , ub=2, name = 'mut');
#time
#t=m.Var(value=0) #for time optimization
tf = 60
nt =15*tf+1
m.time = np.linspace(0,tf,nt)
t = m.Param(value=m.time); # For maximun value
#%% Equations
# m.Equation(t.dt() == 1) # For time optimization only
#For implicit form x.dt() Q.dt() s.dt()
m.Equation(mu == mu_*(1 - K_Q/(Q) )*mu_I);
m.Equation(x.dt() == mu*x - D*x);
m.Equation(Q.dt() == rho_m*((s)/ ((s)+ K_s)) - mu*Q);
m.Equation(s.dt() == (S_in - s)*D - rho_m*((s)/ ((s)+ K_s)) * x);
m.Maximize(D*x)
#%% Solver options
m.options.SENSITIVITY = 1 # sensitivity analysis
m.options.IMODE = 9 # Mode 6 is working
m.solve(disp=True,GUI=True)
m.solve();
print(m.path)
I looked into the infeasibilities file but could not grasp the problem. Appreciate any guidance.
In Gekko, there are 9 solution modes that are controlled with
IMODE
:Modes 4 & 7, 5 & 8, and 6 & 9 should give the same solution but they use a different solution method. Modes 6 and 9 are simultaneous and hybrid sequential solution approaches. In general, I don't recommend
IMODE=8
andIMODE=9
because they often fail to find a solution. If you are getting a solution withIMODE=6
you can either stop there or else use the solution to initialize the solution forIMODE=9
.