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
52
votes
9 answers

How to check if python package is latest version programmatically?

How do you check if a package is at its latest version programmatically in a script and return a true or false? I can check with a script like this: package='gekko' import pip if hasattr(pip, 'main'): from pip import main as pipmain else: …
Joseph
  • 755
  • 1
  • 5
  • 7
9
votes
2 answers

Using Gekko's brain module, how do I determine how many layers and what type of layer to use to solve a deep learning problem?

I am learning to use Gekko's brain module for deep learning applications. I have been setting up a neural network to learn the numpy.cos() function and then produce similar results. I get a good fit when the bounds on my training are: x =…
Joseph
  • 755
  • 1
  • 5
  • 7
8
votes
1 answer

How to fix Python Gekko Max Equation Length error

My code work on small variables. But when I do in 128*128 array of variables, the error below is appearing: APM model error: string > 15000 characters Consider breaking up the line into multiple equations The may also be due to only …
Chinju
  • 125
  • 4
8
votes
3 answers

How to fix 'can't open file 'pip': [Errno 2] No such file or directory' when installing gekko

I'm trying to install the gekko module in my python terminal using python install -m pip gekko but it is throwing an error not recognizing pip: can't open file 'pip': [Errno 2] No such file or directory. I'm using the terminal in Pycharm with…
J Edward Hammond
  • 509
  • 1
  • 3
  • 12
8
votes
3 answers

how to use arrays in gekko optimizer for python

I tried to convert an example from gekko python optimizer by using the list, array x[] instead of variables x1..x4. This is the code which gives the result, but I think it is not correct from gekko import GEKKO import numpy as np # Initialize…
Radovan Omorjan
  • 241
  • 2
  • 8
7
votes
1 answer

What solver should I use if my objective function is an nonlinear (also exponential explanation) function? Python GEKKO

I'm trying to optimise an exponential objective function with GEKKO, but I don't know if the selected solver is the best one for these kind of problems. Is the selected one a valid choice?? import numpy as np 'GEKKO MODELING' from gekko import…
7
votes
1 answer

How to retrieve the 'infeasibilities.txt' from the gekko

I've got an infeasibility error message from GEKKO simulation. I want to retrieve the 'infeasibilities.txt' file for debugging the algorithm. Please let me know where I can find the file. R1 =…
Junho Park
  • 997
  • 4
  • 12
6
votes
1 answer

Using Gekko Optimization, Why is my model builder so much slower than my solver?

I am working on a fairly large MINLP with a model size of about 270,000 variable and equations - 5,000 binaries. In using Gekko with the APOPT solver, I can solve the problem in about 868 seconds (less than 15 minutes). However, solving it on a…
em_cee
  • 173
  • 4
6
votes
2 answers

GEKKO Infeasible system of ODE equations of a fed-batch Bioreactor

I am new to GEKKO and also to modeling bioreactors, so I might be missing something obvious. I have a system of 10 ODEs that describe a fed-batch bioreactor. All constants are given. The picture below shows the expected behavior of this model…
Felipe Mello
  • 395
  • 2
  • 8
6
votes
1 answer

How to read the gekko error code (e.g. Position : 5, v3 etc)

I got a syntax error in 'Position: 5'. I can't find the source of the error as not knowing where 'the Position 5' indicates. How can I recognize the problematic line in the original code by reading the error code? And, what does the v3 mean? Error…
Junho Park
  • 997
  • 4
  • 12
6
votes
1 answer

Is there a way to update MPC with MHE in the same gekko class?

I am currently using an MPC to have the TCLab heater reach a certain set point temperature. I am trying to have an MHE update certain parameter values every 50 seconds. I have a previous MPC model that worked amazing and I tried to add a part in my…
Andrew T
  • 562
  • 3
  • 9
6
votes
1 answer

How to use your own solving method in GEKKO?

I want to use my own Genetic Algorithm (GA) to solve a Mixed Integer problem: https://mintoc.de/index.php/Batch_reactor Can I incorporate my solving method in GEKKO? something like... m = GEKKO() . . . m.options.SOLVER = 'my_GA'
6
votes
2 answers

Gekko Non-Linear optimization, object type error in constraint function evaluating if statement

I'm trying to solve a non-linear optimization problem. I've duplicated my issue by creating the code below. Python returns TypeError: object of type 'int' has no len(). How can I include an IF statement in my constraint functions? Console prints the…
diveblock1
  • 61
  • 1
5
votes
1 answer

Meaning of each column solver output in Gekko

I am curious what each solver output column from IPOPT solver suggests. Is there any material that explains this? Below is solver output from IPOPT solver. And I'd like to know what the inf_pr, inf_du, lg(mu), ||d||, etc. terms mean.
5
votes
1 answer

How to solve overshoot by tuning parameters with gekko?

GEKKO is optimization software for 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). I use gekko to control my TCLab…
ys guo
  • 133
  • 6
1
2 3
53 54