Add 1000 Constraints in linear programing using R lpSolve -


i'm trying implement big linear model, i'm having problem add more variables/constraints. example, want add constraints without adding others zeros (0) in matrix (f.con) in example:

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 

thank you!

i presume you're after this:

makef.con <- function(f.obj,f.dir){   k      <- length(f.dir)   nconst <- length(f.obj) / k   diag   <- diag(k)   c(matrix(rep(diag, each = nconst), nrow = k, byrow = true)) } all(makef.con(f.obj,f.dir) == f.con) [1] true 

though honest, i'm not familiar you're doing, may need play generalizes needs


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -