I am using 'lpSolveAPI' to solve multiple binary linear programming problems in R. How do I get it too return ALL the variable combinations for a maximizing problem.
Ive searched the documentation and can not find a command for this. Trying to switch from package 'lpSolve' as it inconsistently crashes R.
Here's an example problem:
library(lpSolveAPI)
#matrix of constraints
A <- matrix(rbind(
c(1,1,0,0,0,0,0,0),
c(1,0,0,0,1,0,0,0),
c(0,0,1,0,0,1,0,0),
c(0,0,1,0,0,0,1,0),
c(0,0,1,0,0,0,0,1),
c(0,0,0,1,1,0,0,0),
c(0,0,0,0,0,0,1,1)), 7, 8)
#create an LP model with 7 constraints and 8 decision variables
num_con <- nrow(A)
num_points <- ncol(A)
lpmodel <- make.lp(num_con,num_points)
# all right hand
set.constr.type(lpmodel,rep("<=",num_con))
set.rhs(lpmodel, rep(1,num_con))
set.type(lpmodel,columns = c(1:num_points), "binary")
# maximize
lp.control(lpmodel,sense="max")
# add constraints
for (i in 1:num_points){
set.column(lpmodel,i,rep(1,length(which(A[,i]==1))),which(A[,i]==1))
}
set.objfn(lpmodel, rep(1,num_points))
solve(lpmodel)
get.variables(lpmodel)
This returns:
"[1] 0 1 0 0 1 1 0 1"
I know that this problem has 6 possible solutions:
[1] 0 1 0 0 1 1 0 1
[2] 1 0 0 1 0 1 0 1
[3] 1 0 0 1 0 1 1 0
[4] 0 1 0 1 0 1 0 1
[5] 0 1 0 1 0 1 1 0
[6] 0 1 0 0 1 1 1 0
How do I get it too return all of these too me?