我正在尝试使用 ipopt 求解器解决 Pyomo 上的非线性可行性问题。问题有 2 个组合大小为 28 的 RangeSet 声明、4 个组合大小为 68 的 Param 声明和 5 个组合大小为 88 的 Var 声明。还有 90 个约束声明(2 个冗余),其中一些是线性的,一些是非线性的。
该模型应该模拟化学系统。调用model.pprint()会提供它必须的所有信息:所有声明,如上所述。这是我收到的错误输出:
Traceback (most recent call last):
File "sample.py", line 420, in <module>
main()
File "sample.py", line 416, in main
org_n, aq_n, org, aq = _equilibrium_solver(inputfile, T, org_n, aq_n, org, aq)
File "sample.py", line 370, in _equilibrium_solver
opt.solve(model, tee=True)
File "$HOME/.local/lib/python3.6/site-packages/pyomo/opt/base/solvers.py", line 569, in solve
self._presolve(*args, **kwds)
File "$HOME/.local/lib/python3.6/site-packages/pyomo/opt/solver/shellcmd.py", line 200, in _presolve
OptSolver._presolve(self, *args, **kwds)
File "$HOME/.local/lib/python3.6/site-packages/pyomo/opt/base/solvers.py", line 669, in _presolve
**kwds)
File "$HOME/.local/lib/python3.6/site-packages/pyomo/opt/base/solvers.py", line 740, in _convert_problem
**kwds)
File "$HOME/.local/lib/python3.6/site-packages/pyomo/opt/base/convert.py", line 105, in convert_problem
problem_files, symbol_map = converter.apply(*tmp, **tmpkw)
File "$HOME/.local/lib/python3.6/site-packages/pyomo/solvers/plugins/converter/model.py", line 191, in apply
io_options=io_options)
File "$HOME/.local/lib/python3.6/site-packages/pyomo/core/base/block.py", line 1716, in write
io_options)
File "$HOME/.local/lib/python3.6/site-packages/pyomo/repn/plugins/ampl/ampl_.py", line 378, in __call__
include_all_variable_bounds=include_all_variable_bounds)
File "$HOME/.local/lib/python3.6/site-packages/pyomo/repn/plugins/ampl/ampl_.py", line 1528, in _print_model_NL
wrapped_repn.repn.nonlinear_expr)
File "$HOME/.local/lib/python3.6/site-packages/pyomo/repn/plugins/ampl/ampl_.py", line 527, in _print_nonlinear_terms_NL
self._print_nonlinear_terms_NL(exp.arg(1))
File "$HOME/.local/lib/python3.6/site-packages/pyomo/repn/plugins/ampl/ampl_.py", line 637, in _print_nonlinear_terms_NL
% (exp_type))
ValueError: Unsupported expression type (<class 'pyomo.core.expr.expr_pyomo5.LinearExpression'>) in _print_nonlinear_terms_NL
我认为这是一个相当简单的计算,不应该有任何问题,但现在我不知道出了什么问题。我不确定它引发的价值错误是什么意思。我是否要求它以非线性术语打印一些线性表达式?我能想到的只有一件事:我使用了两次quicksum,它使用了linear_expression对象。我应该用其他一些求和表达式(如求和)替换它(不确定求和是否使用相同的对象)?
编辑:我将错误追溯到这个特定的约束。约束给出了摩尔分数和摩尔之间的关系。
def x2n_org(m,i):
return model.org[i]*sum_product(model.org_n) == model.org_n[i]
model.xton_org = Constraint(model.nc, rule=x2n_org)
不知何故,sum_product或Summation是引发 ValueError 的原因。如果有人能看出这个表达式有什么问题,那就太好了。
如果我禁用此约束,求解器将返回不同的错误:
ValueError: Cannot load a SolverResults object with bad status: error
但是,这个错误至少告诉我求解器正在尝试求解模型,即使它找不到解决方案。