简体   繁体   中英

Lagrange multipliers with scipy.optimize.linprog

Is it possible to retriev the Lagrange multipliers from scipy linprog like in Matlab linprog? If so how?

I read the documentation but I didn't find it. There is a return parameter call slack but I think this is something different because it is only related to the inequality constraint:

slack: 1D array

The (nominally positive) values of the slack variables, b_ub - A_ub @ x.

Thanks for the help!

Although my question was already answered by Arraval. I found a work around that I want to share, also using scipy . Linprog hasn't implemented yet but the minimize function can return the Lagrange multipliers when utilizing the method='trust-constr' :

在此处输入图像描述

I hope this helps.

Starting from scipy 1.7.0, one can also receive the Lagrangian multipliers (also known as dual values or shadow prices ) by using the HiGHS dual simplex solver :

import numpy as np
from scipy.optimize import linprog

c = -1*np.array([300, 500])
A_ub = np.array([[1, 2], [1, 1], [0, 3]])
b_ub = np.array([170, 150, 180])
A_eq = np.array([[1, 1]])
b_eq = np.array([80])

# solve c'x  s.t.  A_ub*x <= b_ub, A_eq*x == b_eq, x >= 0
result = linprog(c=c, A_ub=A_ub, b_ub=b_ub, method="highs-ds")

# lagrangian multipliers
λ_ineq = result['ineqlin']['marginals']
λ_eq   = result['eqlin']['marginals']

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