我想在R中使用lpSolveAPI来解决设施优化问题,其中包括在源位置设置产品制造的成本负担。我正在寻找有关如何在lprec对象中建模的建议。我将在page 80 here上使用示例问题:
Minimize {1300000 x11 + 1040000 x12 + 780000 x13 +
780000 x21 + 1300000 x22 + 1040000 23 +
1040000 x31 + 780000 x32 + 1300000 x33 +
1300000 x41 + 780000 x42 + 780000 x43 +
500000 y1 + 500000 y2 + 500000 y3}
Subject to:
x 11 + x 12 + x 13 = l
x 21 + x 22 + x 23 = 1
x 31 + x 32 + x 33 = 1
x 41 + x 42 + x 43 = 1
我按如下方式设置了我的lprec对象:
library(lpSolveAPI)
lprec <- make.lp(0, 15)
set.objfn(lprec, c(1300000, 1040000, 780000,
780000, 1300000, 1040000,
1040000, 780000, 1300000,
1300000, 780000, 780000,
500000, 500000, 500000
))
add.constraint(lprec, c(1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "=", 1)
add.constraint(lprec, c(0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0), "=", 1)
add.constraint(lprec, c(0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0), "=", 1)
add.constraint(lprec, c(0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0), "=", 1)
set.type(lprec, c(1:15), "binary")
但是,我不确定如何使用lpSolveAPI对这些约束进行建模:
1000 x11 + 1000 x21 +500 x31 +500 x41 <= 1500 y1
1000 x12 + 1000 x22 + 500 x32 + 500 x42 <= 1500 y2
1000 x13 + 1000 x23 + 500 x33 + 500 x43 <= 1500 y3
非常感谢任何建议!
答案 0 :(得分:0)
我通过将供应变量更改为整数并将固定成本保持为二进制来对此进行了一些更改。这就是我想出的 - 它解决并满足所有约束条件:
lprec <- make.lp(0, 15)
set.objfn(lprec, c(1300, 1040, 780,
780, 1300, 1040,
1040, 780, 1300,
1300, 780, 780,
500000, 500000, 500000
))
## supply must meet demand constraints
add.constraint(lprec, c(1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "=", 1000)
add.constraint(lprec, c(0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0), "=", 1000)
add.constraint(lprec, c(0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0), "=", 500)
add.constraint(lprec, c(0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0), "=", 500)
## demand must not exceed supply constraints and fixed cost variable
add.constraint(lprec, c(1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1500, 0, 0), "<=", 0)
add.constraint(lprec, c(0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, -1500, 0), "<=", 0)
add.constraint(lprec, c(0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, -1500), "<=", 0)
set.type(lprec, c(1:12), "integer")
set.type(lprec, 13, "binary")
set.type(lprec, 14, "binary")
solve(lprec)
get.objective(lprec)
[1] 3470000
get.variables(lprec)
[1] 0 0 1000 1000 0 0 500 0 0 0 0 500 1 0 1
get.constraints(lprec)
[1] 1000 1000 500 500 -500 0 0