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

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
  • 69
  • 4
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,110
  • 9
  • 20
5
votes
1 answer

How to use if2/3 in Gekko

The problem I am optimizing is the building of power plants in a transmission network. To do this I'm placing power plants at every bus and let the optimization tell me which ones should be build to minimize running cost. To model the placing of…
Arraval
  • 1,110
  • 9
  • 20
5
votes
2 answers

Trying to maximize this simple non linear problem using #gekko but getting this error

(@error: No solution found) positions = ["AAPL", "NVDA", "MS","CI", "HON"] cov = df_ret.cov() ret = df_ret.mean().values weights = np.array(np.random.random(len(positions))) def maximize(weights): std =…
5
votes
1 answer

GEKKO - optimization in matrix form

I am trying to solve an optimization problem where I need to specify the problem and the constraints using a 2D matrix. I have been using SCIPY, where the 1D arrays are the requirements. I want to check if GEKKO allows one to specify the objective…
Chet
  • 421
  • 1
  • 4
  • 8
5
votes
1 answer

Python GEKKO: Modelling a chemical reaction

I'm using Python GEKKO to model a chemical reaction, which can be described like this: 1 -> 2 -> 3 -> 4 with side reactions as follows: 2 -> 5 3 -> 5 The product (4) ist stable. This leads to the following set of ODEs (rate equations), with rate…
lois_power
  • 53
  • 3
5
votes
1 answer

Nonlinear constrained optimization package for Python with direct support of matrix variables

I've been looking around for a nonlinear constrained optimization package for Python (to deal with problems that are NOT necessarily convex) that can directly handle matrix variables. More specifically, I'm dealing with optimization problems where…
5
votes
1 answer

Using GEKKO moving horizon estimation and Model predictive control, React on measurement data and not on the average measurement

I have been working on this model what simulates the inventory of a store. Only thing i can not get right is using the measurement data with in the calculation of the inventory. Currently it only uses the average measurement data for the…
5
votes
2 answers

Python GEKKO MINLP optimization of energy system: How to build intermediates that are 2D arrays

I am currently implementing a MINLP optimization problem in Python GEKKO for determining the optimal operational strategy of a trigeneration energy system. As I consider the energy demand during all periods of different representative days as input…
5
votes
1 answer

Why is GEKKO not picking up the initial measurement?

In using GEKKO to model a dynamic system with an initial measurement, GEKKO seems to be ignoring the measurement completely even with FSTATUS turned on. What causes this and how can I get GEKKO to recognize the initial measurement? I would expect…
Daniel Hill
  • 841
  • 6
  • 12
5
votes
1 answer

When do I use Param rather than Const in Gekko?

I'm trying to fit a cubic spline to the data points below, I'm a bit confused when I would use a Param like the example m.x = m.Param(value=np.linspace(-1, 6)) or when I would use a constant Const. import numpy as np from gekko import GEKKO xm =…
J Edward Hammond
  • 509
  • 1
  • 3
  • 12
5
votes
2 answers

How to solve Absolute Value abs() objective with Python Gekko?

An optimization problem with a squared objective solves successfully with IPOPT in Python Gekko. from gekko import GEKKO import numpy as np m = GEKKO() x = m.Var(); y = m.Param(3.2) m.Obj((x-y)**2) m.solve() print(x.value[0],y.value[0]) However,…
TexasEngineer
  • 684
  • 6
  • 15
5
votes
1 answer

Algebraic/implicit loops handling by Gekko

I have got a specific question with regards to algebraic / implicit loops handling by Gekko. I will give examples in the field of Chemical Engineering, as this is how I found the project and its other libraries. For example, when it comes to…
5
votes
1 answer

Exporting large array variables (type = object) to CSV files

I have used Gekko from APM in Python to solve an optimization problem. The two main decision variables (DVs) are large arrays. The problem has converged successfully, however, I need the results of these tables in an excel worksheet for further…
em_cee
  • 173
  • 4
1
2
3
53 54