You can access the solution by setting debug=0
when you call solve
:
m.solve(debug=0)
The default is debug=1
that throws an exception when there is an error such as reaching the maximum number of iterations. Here is an example that normally solves in 5 iterations. With m.options.max_iter=4
, it reaches the maximum iterations before a successful solution is reached.
from gekko import GEKKO
m = GEKKO(remote=False) # create GEKKO model
x = m.Var(value=0) # define new variable, initial value=0
y = m.Var(value=1) # define new variable, initial value=1
m.Equations([x + 2*y==0, x**2+y**2==1]) # equations
m.options.MAX_ITER=4
m.solve(debug=0) # solve
print([x.value[0],y.value[0]]) # print solution
With debug=0
, the incorrect answer at iteration 4 is returned where the solver almost completed the solution.
[-0.89473125735, 0.44736562868]
I recommend this article if you need suggestions on initializing your problem to help you find a successful solution:
- Safdarnejad, S.M., Hedengren, J.D., Lewis, N.R., Haseltine, E., Initialization Strategies for Optimization of Dynamic Systems, Computers and Chemical Engineering, 2015, Vol. 78, pp. 39-50, DOI: 10.1016/j.compchemeng.2015.04.016.