Home > Blockchain >  lpSolve to solving an Integer programming problem
lpSolve to solving an Integer programming problem

Time:01-30

Solving an Integer programming problem with R, the model is:

# variables: x1, x2, x3
max z = 25000x1   18000x2   31000x3

s.t.:
x1   x2   x3 = 100
5000x1   11000x2   7000x3  <= 700000
x1 >= 10
x2 >= 10
x3 >= 10

x1, x2, x3  є {0,1}

In R, I have lines as below:

library(lpSolve)

f.obj <- c(25000, 18000, 31000)

f.con <- matrix(c(1,1,1,
              5000,11000,7000,
              1,0,0,
              0,1,0,
              0,0,1), nrow = 5, byrow = TRUE)

f.dir <- c("=", "<=", ">=", ">=", ">=")

f.rhs <- c(100, 700000, 10, 10, 10)

# Final value (z)
lp("max", f.obj, f.con, f.dir, f.rhs, int.vec = 1:5, all.bin = TRUE)

# Variables final values
lp("max", f.obj, f.con, f.dir, f.rhs, int.vec = 1:5, all.bin = TRUE)$solution

I expect the right answer to be (given):

Z = 2850000 when x1 = 20, x2 = 10, x3 = 70. 

But above codes returns:

Error: no feasible solution found

Where went wrong, and how can I correct it? Thank you!

CodePudding user response:

According to the documentation of lpSolve the parameter all.bin specifies if all variables are binary. The correct call should be

lp("max", f.obj, f.con, f.dir, f.rhs, int.vec = 1:5, all.int = TRUE)
  •  Tags:  
  • Related