4

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, ub=6555)  #integer=True
x2 = m.Var(value=1,lb=1,ub=10000)  #integer=True
x3 = m.sos1([30, 42, 45, 55])
x3.value = 1.0
x = [x1, x2, x3]
m.Equation((x1 * x2* x3) * 1e-6 >= 50)
def fun(x):
    return 44440 + ((np.pi * x[0] * x[1] * x[2]) * 1e-4)**0.613
m.Obj(fun(x))

# Change to True to initialize with IPOPT
init = False
if init:
    m.options.SOLVER=3  
    m.solve(disp=False) # Solve

m.options.SOLVER=1
m.solve(disp=True) # Solve

print('Results')
print('x1: ' + str(x1.value))
print('x2: ' + str(x2.value))
print('x3: ' + str(x3.value))
print('Objective: ' + str(m.options.objfcnval))
Chinju
  • 125
  • 4

1 Answers1

2

The sos1 function is a recent addition. You can use it by upgrading your gekko package with:

pip install gekko --upgrade

If you don't have administrative privilege then you may need to add the --user flag.

pip install gekko --upgrade --user

You can check your gekko version with:

import gekko
print(gekko.__version__)

It should be v0.2.5 or higher. This is the current version and release history of Gekko on pypi.org. Here are additional instructions on package management in Python.

Eric Hedengren
  • 455
  • 1
  • 5
  • 19