简体   繁体   中英

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. How can I get those from the result of IPOPT solver... I tried to ipopt.hessian(), But it doesn't give anything. 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. You can find an example of building the KKT matrix and extracting the sensitivities here and you can find installation instructions for PyNumero here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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