CVXOPT + GLPK - 从LP解决方案中提取拉格朗日乘数

时间:2016-12-22 11:17:46

标签: python linear-programming glpk cvxopt

我尝试使用CVXOPT solvers.lp和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方法并不使用拉格朗日根本就是乘数来最小化目标函数。

有没有办法从结果对象中提取/计算它们?

我需要的是类似于MATLAB&{39} lambda返回的linprog属性:

[x,fval,exitflag,output,lambda] = linprog(c, A_in, b_in, A_eq, b_eq, lb, ub, [], opt);

0 个答案:

没有答案