将 Pyomo 与 NL/ASL 求解器接口一起使用时从 cplex 接收 .rc 后缀

Receiving .rc suffix from cplex when using Pyomo with NL / ASL solver interface

我想从 cplex 求解器获取我的变量的 .rc 或 .urc 后缀,使用 Pyomo 和 NL / ASL 接口。对于我的模型,此接口通常比默认的 cplex 接口更快。但是我似乎无法获得 return 这些后缀的 NL 接口。如果我使用带有默认选项的 cplex 求解器,我会得到 rc 后缀的值。但是,如果我使用 solver_io='nl' 或将求解器设置为 'cplexamp'(我认为这样做是一样的),那么我将得不到 rc 值。 (我能得到双重的,但不是 rc 的。)

下面是一些示例代码:

from pyomo.environ import *
from pyomo.opt import SolverFactory

def show_rc(m, *args, **kwargs):
    opt = SolverFactory(*args, **kwargs)
    results = opt.solve(m, suffixes=['rc'])
    m.solutions.load_from(results)
    m.rc.pprint()

m = ConcreteModel()
m.X = Var(bounds=(0, 1))
m.obj = Objective(rule=lambda m: 3.14 * m.X, sense=maximize)
m.rc = Suffix(direction=Suffix.IMPORT, datatype=Suffix.FLOAT)

show_rc(m, "cplex")                  # has value 3.14
show_rc(m, "cplex", solver_io="nl")  # no value returned
show_rc(m, "cplexamp")               # no value returned

documentation 特别提到通过后缀降低成本,.rc 后缀似乎是 AMPL 中的标准位置,但我没有运气通过 Pyomo 的 NL 界面阅读它。谁能指出我正确的方向?

不幸的是,cplexamp 可执行文件并未 return 降低解决方案文件中的成本(我刚刚检查过)。我想 AMPL 必须使用 returned 的双重解决方案来计算这些。我会在 GitHub 开一张票。也许我们可以将该功能添加到我们的 ASL 界面中。

在速度方面,您应该尝试 Pyomo 基于 Python 的 Cplex 接口 (solver_io="python")。这通常要快得多,因为它不需要任何文件 I/O。您需要先安装 Cplex-Python 绑定,然后才能通过 Pyomo 使用该接口。如果可以"import cplex",那应该就可以了。

编辑:我忘了提到 solver_io="python" 确实 return 降低了 Cplex 的成本。