我正在尝试实现一个大的线性模型,但是在添加更多变量/约束时遇到了问题。例如,我想添加约束而不在矩阵 (f.con) 中添加其他零 (0),如示例中所示:
library(linprog)
f.obj <- c(3,24,79,140,230,306,338,
26,78,145,226,309,336,354,
146,250,312,364,417,496,508,
314,382,424,472,503,525,548)
f.con <- matrix (c(1,1,1,1,1,1,1, 0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0,0,
0,0,0,0,0,0,0, 1,1,1,1,1,1,1, 0,0,0,0,0,0,0, 0,0,0,0,0,0,0,
0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 1,1,1,1,1,1,1, 0,0,0,0,0,0,0,
0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0,0, 1,1,1,1,1,1,1)
,nrow=4, byrow=TRUE)
f.rhs <- c(10,22,8,30)
f.dir <- c("<=", "<=","<=","<=")
lp ("max", f.obj, f.con, f.dir, f.rhs)
n<-lp ("max", f.obj, f.con, f.dir, f.rhs)$solution
n
谢谢!