solvers.lp
我正在尝试使用 CVXOPT和 GLPK解决具有不等式和等式约束的通用优化问题。
一切正常,但我无法提取拉格朗日乘数。
这是我的代码:
# Convert numpy matrices to cvxopt matrices
c = cvxopt.matrix(c) #(2666x4)
A_in = cvxopt.matrix(A_in)
b_in = cvxopt.matrix(b_in)
A_eq = cvxopt.matrix(A_eq)
b_eq = cvxopt.matrix(b_eq)
# set glpk optimiser settings
cvxopt.solvers.options['glpk'] = {'msg_lev': 'GLP_MSG_OFF'}
cvxopt.solvers.options['msg_lev'] = 'GLP_MSG_OFF'
cvxopt.solvers.options['LP_K_MSGLEV'] = 0
cvxopt.solvers.options['abstol'] = 1e-3
cvxopt.solvers.options['reltol'] = 1e-2
cvxopt.solvers.options['feastol'] = 1
cvxopt.solvers.options['refinement'] = 1
# solve the problem using glpk
res = cvxopt.solvers.lp(c, A_in, b_in, A=A_eq, b=b_eq, solver='glpk')
返回:
res = {
'dual infeasibility': 3.405900733836188e-17,
'dual objective': -146734334.08,
'dual slack': -0.0,
'gap': 0.0,
'primal infeasibility': 9.663381206337363e-12,
'primal objective': -146734334.08,
'primal slack': 0.0,
'relative gap': 0.0,
'residual as dual infeasibility certificate': None,
'residual as primal infeasibility certificate': None,
's': <5367x1 matrix, tc='d'>,
'status': 'optimal',
'x': <2666x1 matrix, tc='d'>,
'y': <1x1 matrix, tc='d'>,
'z': <5367x1 matrix, tc='d'>
}
我对单纯形优化背后的数学及其在 CVXOPT 求解器中的实现感到不舒服,但据我所知,该lp
方法根本不使用拉格朗日乘数来最小化目标函数。
有没有办法从结果对象中提取/计算它们?
我需要的是类似于lambda
MATLAB 返回的属性linprog
:
[x,fval,exitflag,output,lambda] = linprog(c, A_in, b_in, A_eq, b_eq, lb, ub, [], opt);