Questions tagged [gekko]

GEKKO (pip install gekko) is a Python package for machine learning and optimization of mixed-integer and differential algebraic equations. It is coupled with large-scale solvers for linear, quadratic, nonlinear, and mixed integer programming (LP, QP, NLP, MILP, MINLP). Modes of operation include parameter regression, dynamic simulation, and nonlinear predictive control. GEKKO is an object-oriented Python library and is released under the MIT License.

Introduction

GEKKO is a Python software library for large-scale nonlinear optimization. It is designed to find (local) solutions of mathematical optimization problems of the form

   min     f(x)
x in R^n

s.t.       g(dx/dt,x) <= 0
           h(dx/dt,x)  = 0
           x_L <=  x   <= x_U

where f(x): R^n --> R is the objective function, g(dx/dt,x): R^n --> R^m are the inequality constraint functions, and h(dx/dt,x): R^n --> R^m are the equality constraint functions. The vectors x_L and x_U are the simple bounds on the variables x. The functions f, g, and h can be nonlinear and nonconvex, but should be twice continuously differentiable. The variables may be binary, integer, differential, or continuous. GEKKO was created from NSF grant #1547110 and is released under the MIT License.

Background

GEKKO is a Python package for machine learning and optimization of mixed-integer and differential algebraic equations. It is coupled with large-scale solvers for linear, quadratic, nonlinear, and mixed integer programming (LP, QP, NLP, MILP, MINLP). Modes of operation include parameter regression, data reconciliation, real-time optimization, dynamic simulation, and nonlinear predictive control. GEKKO is an object-oriented Python library to facilitate local execution of APMonitor. The original author of the package is Logan Beal and it is maintained by the BYU PRISM group.

GEKKO can be used on Linux/UNIX, Mac OS X, ARM, and Windows platforms and any other platform that runs Python.

Example

The following is the solution to the Hock Schittkowski benchmark problem #71.

hs71_optimization

from gekko import GEKKO    
import numpy as np
m = GEKKO()
x = m.Array(m.Var,4,value=1,lb=1,ub=5)
x1,x2,x3,x4 = x
# change initial values
x2.value = 5; x3.value = 5
m.Equation(x1*x2*x3*x4>=25)
m.Equation(x1**2+x2**2+x3**2+x4**2==40)
m.Minimize(x1*x4*(x1+x2+x3)+x3)
m.solve()
print('x: ', x)
print('Objective: ',m.options.OBJFCNVAL)

Solution with IPOPT:

 ---------------------------------------------------
 Solver         :  IPOPT (v3.12)
 Solution time  :   9.699999995063990E-003 sec
 Objective      :    17.0140171270735     
 Successful solution
 ---------------------------------------------------
 
Results
x1: [1.000000057]
x2: [4.74299963]
x3: [3.8211500283]
x4: [1.3794081795]

Related Links

APMonitor is run locally or as a web-service as a backend solution engine for GEKKO.

Documentation: Installation, options, and examples.

GitHub: Source code repository.

Online Course: GEKKO for machine learning and dynamic optimization

References: GEKKO and APMonitor references.

Wikipedia: Overview of GEKKO.

798 questions
5
votes
1 answer

Stochastic optimal control problems in Python

Does anyone know of a python package that solves stochastic optimal control problems? I have found Gekko that solves control problems, but I could not find a way to use it for stochastic problems.
python_enthusiast
  • 896
  • 2
  • 7
  • 26
4
votes
1 answer

GEEKO Result explanation

would you mind sparing some time explaining why the obj is zero here in some iterations? tcstd and tdstd is min-max standardize of tc and td. I want to minimize tcstd*tdstd so the value of objective function should be 0-1. however during the…
kennnn
  • 83
  • 3
4
votes
1 answer

Bioreactor Simulation for Ethanol Production using GEKKO

I am trying to simulate a DAE system that solves a fed-batch bioreactor problem for ethanol production using GEKKO. This is done so I can later optimize it more easily to maximize Ethanol production. It was previously solved in MATLAB and produced…
4
votes
2 answers

How do I display solution in GEKKO GUI?

I would like to explore the functionality of the GEKKO web GUI for visualising results as described in https://www.researchgate.net/publication/326740143_GEKKO_optimization_suite. I have enabled m.options.WEB=1 and solved with…
JacquesStrydom
  • 319
  • 1
  • 9
4
votes
1 answer

how to multiply a gekko array of FV or variables to a gekko intermediate array if both have different dimensions without changing the amount of FV?

of course there is code afterwards but to keep it simple and to express my problem I will only share this. everything is working fine I basically just need the array "x" to change from size 24 to the number of my other array (in this case 100). The…
4
votes
1 answer

GEKKO gives TypeError: must be real number, not GK_Operators, I have several approaches that is recommended

I am trying to solve an NLP with GEKKO, however I have a few problem while implementing the Python code. The model that I am trying to solve is pretty trivial, I am trying to find the optimal point that has minimum loss function value in a 3D convex…
4
votes
1 answer

Solving optimal control problem with constraint x(0) + x(2) =0 with GEKKO

I am starting to learn Gekko and I am testing optimal control problems. I am trying to solve the following optimal control problem with Gekko The solution of this problem is (x_1(t) = (t-2)^2 - 2) How to build the constraint x(0) + x(2) = 0? My…
MRon
  • 43
  • 4
4
votes
1 answer

GEKKO how to solve a optimal lunar soft landing problem?

I tried to solve a 2D optimal lunar soft landing problem by GEKKO. I assume that the moon is not rotating. The spacecraft is supposed to land softly on the surface of the moon, i.e. the final vertical velocity v and the final horizontal velocity u…
abmin
  • 133
  • 2
  • 12
4
votes
1 answer

Constraining a Mixed-Integer Non-Linear optimization problem by L0-norm/number of non-zero elements in GEKKO

I want to minimize the cost for achieving a given set of non-negative integer values b that are computed linearly from two sets of non-negative integer variables x, y in GEKKO. If have stated my problem in a way, that the b's are constraints on the…
4
votes
1 answer

What types of non-linearities can GEKKO handle?

I've been using GEKKO successfully for a variety of problems but one thing I haven't been able to pin down is what the limits are in terms of non-linear terms in objective functions or constraints. I've found that some non-linear terms are…
4
votes
1 answer

Issue with integer optimization with Gekko

I tried with this code and the result was (2,2). Obviously it's not true, since (0,4) is a best solution. could you please tell me where is it the problem? import numpy as np from gekko import GEKKO m = GEKKO() x=[m.Var(lb=0,ub=4,integer=True) for…
4
votes
2 answers

Gekko MPC controller - update parameters at each time step

I am working on an MPC problem with individual linear models predicting the control variable at each time step in the prediction horizon (see below where u is the manipulated variable and y is the control variable). The coefficients of each linear…
cdgood
  • 61
  • 3
4
votes
1 answer

Optimal control problem using Gekko: “Solution Not Found”

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…
4
votes
1 answer

How to estimate theta value in FOPDT equation using gekko?

I'm trying to use GEKKO to fit to a certain dataset, using the FOPDT Optimization Method to estimate k, tau and theta. I saw the example using odeint on https://apmonitor.com/pdc/index.php/Main/FirstOrderOptimization and tried to do the same thing…
4
votes
1 answer

MPC Mode in GEKKO

I just need clarification about the definition of the prediction and control horizon in MPC mode in GEKKO. In the examples found online (For example here https://apmonitor.com/do/index.php/Main/TCLabF), a horizon is defined with m.time(), with m our…
tt40kiwi
  • 361
  • 1
  • 8
1 2
3
53 54