0

Using R, it is very easy to do linear programming with the lpSolve and lpSolveAPI packages. Now, I want to do linear programming with part of the constraints satisfied. Say, with 80% of the constraints are satisfied. It can not predefine which constraints should be satisfied. How to implement it using R?

An example here. There are 100 different tissue samples, for each sample, 10000 ~ 20000 genes were expressed. Now, I want to select at most 10 samples with the purpose to cover as many genes as possible. One solution based on lpSolve is set 100 samples as variables and 20000 genes as constraints. First, manually filter the genes, and do lp, until the solution hit 10 samples. However, this is laborious and not the most optimal.

set.seed(123)
t.mt <- matrix(sample(c(0,1),100000,rep=TRUE),nr=1000)
f.obj <- rep(1,100)
f.dir <- rep(">=",1000)
f.rhs <- rep(1,1000)
t.lp <- lp("min",f.obj,t.mt,f.dir,f.rhs,all.int=TRUE,all.bin=TRUE)
t.lp$solution

Is there possible solution using R for this problem?

Thank you!

pengchy
  • 732
  • 2
  • 14
  • 26
  • 3
    Add an extra binary variable `b(i)` for each constraint. Rewrite the constraints so they are nonbinding if `b(i)=0`, e.g. `a'x >= rhs - M*(1-b(i))`. Then count the sum `sum(i,b(i)) <= 10`. – Erwin Kalvelagen Jul 28 '17 at 16:05
  • Hi Erwin Kalvelagen, Thank you for your solution. How to limit the percentage of the satisfied constraints and implement in R? – pengchy Jul 30 '17 at 22:34
  • Hi Erwin Kalvelagen, The satisfied constraints can not be predefined, so how to design the extra binary variable? – pengchy Jul 30 '17 at 22:40
  • I think my suggested formulation is correct. – Erwin Kalvelagen Aug 01 '17 at 03:39

0 Answers0