6

我正在寻找一个很好的 R 包来解决线性规划模型。我对默认值很满意lpSolve::lp,但没有办法得到阴影和降价。我需要这些以及完整性约束。

样品型号:

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???
4

2 回答 2

4

搜索

sos::findFn("integer shadow reduced")

... 返回指向 Benchmarking 包的链接,说明它将提供双重价值(影子价格)。

http://finzi.psych.upenn.edu/R/library/Benchmarking/html/Benchmarking-package.html

于 2013-04-13T17:36:04.907 回答
4

正如评论中所说,文档的第 4 页讨论了这一点。这是文档的摘录:

# 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
于 2013-04-14T13:18:54.443 回答