Lotka Volterra fishing problem (GEKKO)

From mintOC
Jump to: navigation, search

This page contains a solution of the MIOCP Lotka Volterra fishing problem in GEKKO Python format. The model in Python code for a fixed control discretization grid using orthogonal collocation and a simultaneous optimization method. The GEKKO package is available with pip install gekko.

import numpy as np
import matplotlib.pyplot as plt
from gekko import GEKKO
 
m = GEKKO() # create GEKKO model
 
# Add 0.01 as first step
# 0,0.01,0.1,0.2,0.3,...11.9,12.0)
m.time = np.insert(np.linspace(0,12,121),1,0.01)
 
# change solver options
m.solver_options = ['minlp_gap_tol 0.001',\
                    'minlp_maximum_iterations 10000',\
                    'minlp_max_iter_with_int_sol 100',\
                    'minlp_branch_method 1',\
                    'minlp_integer_tol 0.001',\
                    'minlp_integer_leaves 0',\
                    'minlp_maximum_iterations 200']
 
c0 = 0.4 
c1 = 0.2
 
last = m.Param(np.zeros(122))
last.value[-1] = 1
 
x0 = m.Var(value=0.5,lb=0)
x1 = m.Var(value=0.7,lb=0)
x2 = m.Var(value=0.0,lb=0)
w = m.MV(value=0,lb=0,ub=1,integer=True)
w.STATUS = 1
 
m.Obj(last*x2)
 
m.Equations([x0.dt() == x0 - x0*x1 - c0*x0*w,\
             x1.dt() == - x1 + x0*x1 - c1*x1*w,\
             x2.dt() == (x0-1)**2 + (x1-1)**2])
 
m.options.IMODE = 6
m.options.NODES = 3
m.options.SOLVER = 1
m.options.MV_TYPE = 0
m.solve()
 
plt.figure(1)
plt.step(m.time,w.value,'r-',label='w (0/1)')
plt.plot(m.time,x0.value,'b-',label=r'$x_0$')
plt.plot(m.time,x1.value,'k-',label=r'$x_1$')
plt.plot(m.time,x2.value,'g-',label=r'$x_2$')
plt.xlabel('Time')
plt.ylabel('Variables')
plt.legend(loc='best')
plt.show()

An MINLP solution is calculated with APOPT with an objective function value of x_2(t_f) = 1.349497.

Volterra fishing GEKKO.png