我正在为 Pyomo(或 AMPL)开发一个免费的 MINLP 求解器,称为 APOPT。可以下载当前解决NLP problems in Pyomo (MINLP not yet supported)的版本。它将 .nl 问题发送到服务器,然后将 .sol 解决方案返回给 Pyomo。
我有使用 Python Gekko 解决 MINLP 问题的界面。这也是 Pyomo 求解器性能的预览。您可以使用以下方式安装 Gekko:
pip install gekko
或者,如果您在 Jupyter 笔记本中,则可以通过在单元格中运行此命令来安装 Gekko(只需要一次):
!pip install gekko
这是一个 MINLP 问题的示例:
from gekko import GEKKO
m = GEKKO() # Initialize gekko
m.options.SOLVER=1 # APOPT is an MINLP solver
# optional solver settings with APOPT
m.solver_options = ['minlp_maximum_iterations 500', \
# minlp iterations with integer solution
'minlp_max_iter_with_int_sol 10', \
# nlp sub-problem max iterations
'nlp_maximum_iterations 50', \
# maximum deviation from whole number
'minlp_integer_tol 0.05', \
# covergence tolerance
'minlp_gap_tol 0.01']
# Initialize variables
x1 = m.Var(value=1,lb=1,ub=5)
x2 = m.Var(value=5,lb=1,ub=5)
# Integer constraints for x3 and x4
x3 = m.Var(value=5,lb=1,ub=5,integer=True)
x4 = m.Var(value=1,lb=1,ub=5,integer=True)
# 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) # Objective
m.solve(disp=False) # Solve
print('Results')
print('x1: ' + str(x1.value))
print('x2: ' + str(x2.value))
print('x3: ' + str(x3.value))
print('x4: ' + str(x4.value))
print('Objective: ' + str(m.options.objfcnval))
它产生以下输出:
Results
x1: [1.3589086474]
x2: [4.5992789966]
x3: [4.0]
x4: [1.0]
Objective: 17.532267301