2013-04-13 27 views
6

我正在寻找一个很好的R程序包来解决线性规划模型。我对默认lpSolve::lp非常满意,但无法获得影子和降价。我需要这些,以及完整性约束。用于解决线性规划问题的R

样品型号:

A = rbind(
    c(0.5, 0.2, 0.2), 
    c(-1, 1, 0), 
    c( 0, 1, -1), 
    c(-1, -1, -1), 
    c(-1, 0, 0), 
    c( 0, -1, 0), 
    c( 0, 0, -1) 
) 
b = c(5, 0, 0, -13, 0, 0, 0) 
c_ = c(8.4, 6, 9.2) 
(signs = c('=', rep('<=', 6))) 

res = lpSolve::lp('min', c_, A, signs, b, all.int = TRUE) 

# Objective function 
res 
# Variables 
res$solution 

# Shadow prices??? 
# Reduced prices??? 
+1

对不起,什么是影子和降价? – Arun

+0

@阿伦这是一个双重变量 - 见[**本文档**](http://cran.r-project.org/web/packages)中的http://en.wikipedia.org/wiki/Shadow_price – mreq

+2

Page 4 /lpSolve/lpSolve.pdf)讨论约束的“双重值”。这是你在找什么? – Arun

回答

3

由于根据意见,这个page 4 of the documentation会谈时表示。以下是文档摘录:

# Get sensitivities 
lp ("max", f.obj, f.con, f.dir, f.rhs, compute.sens=TRUE)$sens.coef.from 
## Not run: [1] -1e+30 2e+00 -1e+30 
lp ("max", f.obj, f.con, f.dir, f.rhs, compute.sens=TRUE)$sens.coef.to 
## Not run: [1] 4.50e+00 1.00e+30 1.35e+01 

# Right now the dual values for the constraints and the variables are 
# combined, constraints coming first. So in this example... 

lp ("max", f.obj, f.con, f.dir, f.rhs, compute.sens=TRUE)$duals 
## Not run: [1] 4.5 0.0 -3.5 0.0 -10.5 

# ...the duals of the constraints are 4.5 and 0, and of the variables, 
# -3.5, 0.0, -10.5. Here are the lower and upper limits on these: 

lp ("max", f.obj, f.con, f.dir, f.rhs, compute.sens=TRUE)$duals.from 
## Not run: [1] 0e+00 -1e+30 -1e+30 -1e+30 -6e+00 
lp ("max", f.obj, f.con, f.dir, f.rhs, compute.sens=TRUE)$duals.to 
## Not run: [1] 1.5e+01 1.0e+30 3.0e+00 1.0e+30 3.0e+00 
+2

:关键是'compute.sens = TRUE' – mreq