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

Forming system of constraint equations using GEKKO optimization framework

I'm trying to solve a simple minimum time optimal control problem using double integrator dynamics of the form, dx1/dt = x2 dx2/dt = u with the GEKKO optimization framework as follows: from gekko import GEKKO import numpy as np import…
4
votes
1 answer

Learning more about APOPT solver

I have a few questions about how APOPT solves MINLPs. What nonlinear programming method APOPT uses (interior point, trust region, etc.)? How does APOPT deal with mixed integers (B&B, outer approximation, generalized benders decomposition,etc)?
4
votes
2 answers

how can I use gekko optimizer without a known objective function(let say some random function) and with known variables and constraints?

I a trying to minimize and maximize a random 'test function' using gekko which is connected to A. A consists of 4 parameters between the range (0-100) and sum of A < 100.However I keep getting weird results,because the minimum of the test function…
Abdirizak
  • 87
  • 7
4
votes
0 answers

How do you determine what to call a compound when accessing it in Gekko's Chemical Library?

I am working with Gekko's Chemical Library and I am trying to add compounds to my model. The readthedocs page for Gekko says that there are 4 methods for adding each compound: 1) IUPAC Name (1,2-ethanediol) 2) Common Name (ethylene glycol) 3) CAS…
Joseph
  • 755
  • 1
  • 5
  • 7
4
votes
1 answer

no solver display while running in mode 6 python gekko

I have been having an issue with the display of the IPOPT solver in Gekko (python), since upgrading from version 0.2.0 scripts work as expected but there is no more live display in the console while the solver is working, solve(disp=true) doesn't…
AdrienB
  • 41
  • 1
4
votes
1 answer

Using m.CV vs m.Var

I'm optimizing a tubular column design using gekko python. I experimented with the code using the different variable types m.SV and m.CV in place of m.Var and there was no apparent effect on the solver or the results. What purpose do these different…
4
votes
1 answer

How to know how long GEKKO took to solve my model?

How can I get an output from GEKKO on how long it took to solve my model? I know based off of Measure time elapsed in Python that I can get my code to print the total time taken to run my code but I do not know how to isolate the solver time. from…
dmccrea
  • 43
  • 3
4
votes
1 answer

Adaptive modelling using GEKKO sysid

I have 100 points of data that I'm trying to describe using sysid in GEKKO. At some point ( t = 50 in this case) the data changes significantly and the prediction is no longer accurate. I'm trying to include an if statement that evaluates actual vs…
reyPanda
  • 510
  • 2
  • 11
4
votes
1 answer

GEKKO AttributeError : sos1

When I use example in python,the error show like : AttributeError: 'GEKKO' object has no attribute 'sos1' how can I fix this error? The code is shown below: import numpy as np from gekko import GEKKO m = GEKKO() x = [] x1 = m.Var(value=20,lb=20,…
Chinju
  • 125
  • 4
4
votes
1 answer

Set the initial value for dynamic simulation w/ steady-state results in GEKKO

I'm doing a dynamic simulation with 'IMODE=4'. I'm wondering if there is an option in the GEKKO to set the steady-state simulation result with 'IMODE=1' as an initial value of the dynamic simulation. Or, do I need to run the steady-state simulation…
Junho Park
  • 997
  • 4
  • 12
4
votes
1 answer

How can i remove the blinking of the command window while running a gekko MPC code in offline mode?

I have built several successful codes for MPC using Gekko python in offline mode. However, i still want to remove the blinking of the command window while running the program. Any suggestions ? Thank you.
Mohamad Ibrahim
  • 315
  • 2
  • 8
4
votes
2 answers

Approximate the nonlinear function by piece-wise linear segments

I'm thinking if I can use GEKKO for the following problem. Please feel free to share your comments. Thank you in advance. Given that I'd like to approximate some nonlinear functions by piece-wise linear(PWL) segments. For instance, I'd like to use N…
NS Huang
  • 91
  • 3
4
votes
2 answers

How to use a vector set point with mpc inorder to give program information on how the future set point will change

I am using an MPC to run a heater system. Currently I have it take an individual value from my set point array at a given point in time to adjust the process to reach. I would like to be able to give it the current desired value and a couple of…
Andrew T
  • 562
  • 3
  • 9
4
votes
1 answer

Default objective function in GEKKO MPC example

This Model Predictive Control (MPC) example using GEKKO (relating gas pedal movement to car velocity), doesn't explicitly state a cost function to minimize: from gekko import GEKKO import numpy as np import matplotlib.pyplot as plt m =…
Mitch
  • 167
  • 1
  • 7
4
votes
1 answer

How can i use gekko python to control the level of a tank of a cstr by manipulating the inlet flow to the tank?

I am trying to use GEKKO on PYTHON to control the level of a CSTR tank while manipulating the inlet flow q. I tried the same problem using a pid controller and it worked. However, on GEKKO the height is not tracking its setpoint. Once I did the…
Mohamad Ibrahim
  • 315
  • 2
  • 8