问题描述
我得到了一个带有许多变量和约束的pyomo具体模型。
I got a pyomo concrete model with lots of variables and constraints.
以某种方式,模型中的变量之一违反了一个约束,这使我的模型不可行:
Somehow, one of the variable inside my model violates one constraint, which makes my model infeasible:
WARNING: Loading a SolverResults object with a warning status into model=xxxx;
message from solver=Model was proven to be infeasible.
有没有办法向求解器询问不可行的原因?
Is there a way to ask the solver, the reason of the infeasibility?
例如,假设我有一个名为 x
的变量,如果我定义以下两个约束,则模型将为ofc。不可行的。
So for example, lets assume I got a variable called x
, and if I define following 2 constraints, model will be ofc. infeasible.
const1:
x >= 10
const2:
x <= 5
我要实现的目标是指出导致这种不可行性的约束和变量,因此我可以解决它。否则,使用我的大型模型,很难找到导致这种不可能性的原因。
And what I want to achieve that pointing out the constraints and variable which causes this infeasibility, so that I can fix it. Otherwise with my big model it is kinda hard to get what causing this infeasibility.
IN: write_some_comment
OUT: variable "x" cannot fulfill "const1" and "const2" at the same time.
推荐答案
许多求解器(包括IPOPT)都会退还给您求解器终止时变量的值,即使发现问题不可行也是如此。那时,您确实有一些选择。
Many solvers (including IPOPT) will hand you back the value of the variables at solver termination, even if the problem was found infeasible. At that point, you do have some options.
pyomo.util.infeasible
中包含有贡献的代码,可能帮助你。
There is contributed code in pyomo.util.infeasible
that might help you out. https://github.com/Pyomo/pyomo/blob/master/pyomo/util/infeasible.py
用法:
from pyomo.util.infeasible import log_infeasible_constraints
...
SolverFactory('your_solver').solve(model)
...
log_infeasible_constraints(model)
这篇关于找出Pyomo模型不可行的原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!