0

是否可以访问与 Pyomo 中的变量界限相关的双重信息?对于约束,您可以声明一个后缀,但变量边界是否有等价物?

4

1 回答 1

1

您可以声明一个名为rc(reduced cost) 的后缀,以从以下接口获取:

  • 古罗比:LP、MPS、Python
  • Cplex:LP、MPS、Python
  • Glpk:LP,MPS

Xpress 也可能在该列表中,但我无法验证这一点。

AMPL 的 Gurobi 和 Cplex 求解器不会将此信息作为后缀返回(我不知道为什么),因此您无法通过 Pyomo 中这些求解器的 NL 文件接口获取这些信息。

此外,对于 Ipopt,您可以通过分别为下界和上界的对偶声明名为ipopt_zL_out和的后缀来获得此信息。ipopt_zU_out请参阅示例以获得更好的解释。

上面的列表只是我所知道的。可能还有其他 AMPL 求解器通过后缀提供此信息,因此只要您知道后缀的名称,您就可以通过 Pyomo 的 NL 文件接口访问该解决方案信息。

更新:这是 gurobi 的示例:

import pyomo.environ as aml

model = aml.ConcreteModel()
model.x = aml.Var(bounds=(0,1))
model.o = aml.Objective(expr=model.x)
model.c = aml.Constraint(expr=model.x >= -1)

model.rc = aml.Suffix(direction=aml.Suffix.IMPORT)

gurobi = aml.SolverFactory("gurobi",
                           solver_io="lp")
results = gurobi.solve(model)
assert str(results.solver.termination_condition) == "optimal"

print(model.rc[model.x])

正如我上面解释的,你可以solver_io在这个例子中使用 Gurobi 设置为“lp”、“mps”或“python”。

于 2017-05-18T21:03:56.277 回答