2013-04-13 55 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