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.

from gekko import GEKKO    
m = GEKKO()
x1,x2,x3,x4 = [m.Var() for i in range(4)]
# intial guess
x1.value = 1
x2.value = 5
x3.value = 5
x4.value = 1
# lower bounds
x1.lower = 1
x2.lower = 1
x3.lower = 1
x4.lower = 1
# upper bounds
x1.upper = 5
x2.upper = 5
x3.upper = 5
x4.upper = 5    
#Equations
m.Equation(x1*x2*x3*x4>=25)
m.Equation(x1**2+x2**2+x3**2+x4**2==40)
m.Obj(x1*x4*(x1+x2+x3)+x3)
m.solve()
print('Results')
print('x1: ' + str(x1.value))
print('x2: ' + str(x2.value))
print('x3: ' + str(x3.value))
print('x4: ' + str(x4.value))

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.

406 questions
36
votes
8 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
  • 595
  • 3
  • 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
  • 595
  • 3
  • 7
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
  • 335
  • 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
  • 937
  • 2
  • 11
6
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
  • 105
  • 3
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
  • 536
  • 2
  • 9
6
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
  • 806
  • 2
  • 7
  • 22
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
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
  • 332
  • 1
  • 2
  • 7
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
6
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
  • 221
  • 1
  • 8
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
  • 109
  • 5
5
votes
1 answer

GEKKO Error: "Equation without an equality (=) or inequality (>,<)" when calling functions within constraint and objective

I have been getting the below error for my code and I am at a complete loss as to the source of the error: @error: Equation Definition Equation without an equality (=) or inequality (>,<) true STOPPING... I am seeking to identify the solution 'x'…
Toby-wan
  • 65
  • 3
5
votes
1 answer

Gekko(python) for lap time optimization

I was wondering if it was a good idea to use Gekko to solve a lap time optimization: finding the optimal path on a track to minimize total time by controlling the steering angle and the power output. I'm fairly new to optimal control problem so if…
trimat
  • 101
  • 4
5
votes
1 answer

Lagrange multipliers (marginals) in Gekko

Is there a one liner in Gekko to retrieve the Lagrange multipliers (the likes of the marginal in GAMS) or if not a single line another way? Thanks for the help.
Arraval
  • 1,002
  • 9
  • 19
1
2 3
27 28