且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在pyomo中将积分定义为目标函数?

更新时间:2022-05-08 06:52:07

Gabe 说得对,这确实是 Integral 类中的一个 bug,已经在 github 仓库中修复了.示例模型中的另一个错误是目标组件的规范.您应该使用 'rule' 关键字而不是 'expr'

Gabe is right, this is indeed a bug in the Integral class and it has been fixed on the github repository. One other error in your example model is the specification of the Objective component. You should be using the 'rule' keyword instead of 'expr'

def myobjective(model):
     return model.n
model.obj = Objective(rule=myobjective)

另外,我想重申一下 pyomo.dae 在线文档中提到的一些内容.Integral 组件是一个原型,尚未完全开发.我不建议将它用于需要高精度解决方案的复杂积分或模型.Integral 类使用梯形规则进行数值积分.我建议您将问题中的任何积分转换为微分方程,然后使用提供的自动离散化转换来求解它们.

Also, I want to reiterate something mentioned in the online documentation for pyomo.dae. The Integral component is a prototype and not fully developed. I do not recommend using it for complex integrals or models that require high accuracy solutions. The Integral class uses the trapezoid rule for numerical integration. I would recommend converting any integrals in your problem to differential equations and solving them using the provided automatic discretization transformations.