I am trying to use lpsolve in R to solve the following lp program. I want to maximize the obj function. The constraints are that the variable weights sum up to 1, and the individual weights have to be either 0 or a minimum of 0.125, and a maximum of .5. I Was under the impression I can solve this by turning the variables into binary variables, but I seem to be running into issues when I try to solve this. Any help would be greatly appreciated!
library(lpsolveapi)
obj.coef <- c(3, 2, 5, 4)
lpmodelapi <- make.lp(0,length(obj.coef))
lp.control(lpmodelapi,sense='max')
set.objfn(lpmodelapi,obj.coef)
add.constraint(lpmodelapi, c(2, 1, 4, 3), ">=", 2)
add.constraint(lpmodelapi, c(1,1,1,1),"=", rhs =1)
add.constraint(lpmodelapi,c(1,0,0,0), ">=",.125)
add.constraint(lpmodelapi,c(0,1,0,0), ">=",.125)
add.constraint(lpmodelapi,c(0,0,1,0), ">=",.125)
add.constraint(lpmodelapi,c(0,0,0,1), ">=",.125)
add.constraint(lpmodelapi,c(1,0,0,0), "<=",.5)
add.constraint(lpmodelapi,c(0,1,0,0), "<=",.5)
add.constraint(lpmodelapi,c(0,0,1,0), "<=",.5)
add.constraint(lpmodelapi,c(0,0,0,1), "<=",.5)
set.type(lpmodelapi, 1:length(obj.coef), type = "binary")
solve(lpmodelapi)
get.variables(lpmodelapi)