简体   繁体   English

如何使用 Python 和 Pyomo 和 Ipopt 获得 Hessian 和 Lagragian 梯度来计算 KKT 矩阵

[英]How to get Hessian and gradient of Lagragian to calculate KKT matrix using Python and Pyomo with Ipopt

from pyomo.environ import *
from pyomo.opt import SolverFactory, ProblemFormat
m = ConcreteModel()
m.i = Set(initialize=[1, 2, 3])
init_vals = {1:25E+07, 2:0.0, 3:0.0}
#: Variables
m.x = Var(m.i, initialize=init_vals)
#: Objective
m.oF = Objective(expr=m.x[1]**2 +m.x[2]**2 + m.x[3]**2,
        sense=minimize)
ipopt = SolverFactory('ipopt')
ipopt.solve(m, tee=True)

I want to calculate the KKT matrix using the hessian and gradient of Lagrangian for NLP sensitivity.我想使用拉格朗日的 Hessian 和梯度计算 NLP 敏感性的 KKT 矩阵。 How can I get those from the result of IPOPT solver... I tried to ipopt.hessian(), But it doesn't give anything.我怎样才能从 IPOPT 求解器的结果中得到那些...我试图 ipopt.hessian(),但它没有给出任何东西。 Please give me some help.请给我一些帮助。

I think there is a way to do this with sIPOPT and suffixes (see the sIPOPT documentation) but the easier route might be to use a contributed package to Pyomo called PyNumero.我认为有一种方法可以使用 sIPOPT 和后缀(请参阅 sIPOPT 文档)来做到这一点,但更简单的方法可能是使用一个名为 PyNumero 的 Pyomo 贡献包。 You can find an example of building the KKT matrix and extracting the sensitivities here and you can find installation instructions for PyNumero here你可以找到建设KKT矩阵并提取敏感的例子在这里,你可以找到PyNumero安装说明这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM