本文介绍了pyomo 的 AbstractModel VS ConcreteModel?“opt.options[“tol"]"如何?在寻找最佳解决方案方面有所作为吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 AbstractModel 和一个 ConcreteModel 来解决同样的问题,但它们的表现不同.主要是一个变量的初始值和ipopt的容忍度.

I have an AbstractModel and a ConcreteModel solving the same problem, but they are performing differently. It is mainly about initial value of a variable and tolerance of ipopt.

  1. 当我将变量 model.x 初始化为 10 并且 opt.options["tol"] = 1E-64 时:ConcreteModel 可以找到最优解,而抽象模型Solved To Acceptable Level".(但他们找到的解决方案其实是一样的)

  1. When I initialize my variable model.x as 10 and opt.options["tol"] = 1E-64:ConcreteModel can find optimal solution, while abstract model "Solved To Acceptable Level". (But the solutions they find are actually the same)

当我将变量 model.x 初始化为 100 并且 opt.options["tol"] = 1E-64 时:ConcreteModel 可以找到最佳解决方案,而抽象模型有时会解决到可接受的水平",有时无法加载状态不佳的 SolverResults 对象:错误".

When I initialize my variable model.x as 100 and opt.options["tol"] = 1E-64:ConcreteModel can find the optimal solution, while abstract model sometimes "Solved To Acceptable Level" and sometimes "Cannot load a SolverResults object with bad status: error".

如果我只是使用ipopt的默认容差值,无论我如何初始化变量model.x,ConcreteModel和AbstractModel都能找到相同的最优解.

If I just use the ipopt's default value of the tolerance, both ConcreteModel and AbstractModel can find the same optimal solution no matter how I initialize the variable model.x.

所以我想知道 opt.options["tol"] 有什么不同?为什么在这种情况下 ConcreteModel 总是能够找到最佳解决方案而 AbstractModel 不能?

So I wonder how opt.options["tol"] makes a difference? Why is ConcreteModel always able to find an optimal solution in this case while AbstractModel not?

变量

model.x = Var(model.Crops, model.Inputs, initialize = 100, within=NonNegativeReals)

AbstractModel 的求解脚本

solve script of AbstractModel

instance = model.create_instance(data="AbstractCDFarm.dat")
opt = SolverFactory("ipopt")
opt.options["tol"] = 1E-64
results = opt.solve(instance, tee=True)
instance.display()

ConcreteModel 求解脚本

solve script of ConcreteModel

opt = SolverFactory('ipopt')
opt.solve(model, tee=True)
opt.options["tol"] = 1E-64
results = opt.solve
model.display()

推荐答案

您为 ConcreteModel 调用了两次solve,看起来您看到的输出是针对默认 Ipopt 容差的,而不是针对 1E-64 容差的.你为什么设置这么低的容差?1E-64 比机器精度小,所以它是一个不可能收敛到的小公差.

You're calling solve twice for the ConcreteModel and it looks like the output you're seeing is for the default Ipopt tolerance not for the tolerance of 1E-64. Why are you setting such a low tolerance? 1E-64 is smaller than machine precision so it's an impossibly small tolerance to converge to.

这篇关于pyomo 的 AbstractModel VS ConcreteModel?“opt.options[“tol"]"如何?在寻找最佳解决方案方面有所作为吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-11 18:02