当我在 python 中使用示例时,错误显示如下: AttributeError: 'GEKKO' object has no attribute 'sos1'
我该如何解决这个错误?
代码如下所示:
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))