0

I would like to use lpSolveAPI in R to solve a facility optimization problem that includes a cost burden to set-up product manufacture in the source location. I am looking for advice on how to model this in the lprec object. I'll use the example problem on page 80 here:

Minimize {1300000 x11 + 1040000 x12 +  780000 x13 + 
                   780000 x21 + 1300000 x22 + 1040000 23 + 
                   1040000 x31 + 780000 x32 + 1300000 x33 +
                   1300000 x41 + 780000 x42 + 780000 x43 +
                   500000 y1 + 500000 y2 + 500000 y3}

Subject to:

x 11 + x 12 + x 13 = l

x 21 + x 22 + x 23 = 1

x 31 + x 32 + x 33 = 1

x 41 + x 42 + x 43 = 1

I have set up my lprec object as follows:

library(lpSolveAPI)
lprec <- make.lp(0, 15)
    set.objfn(lprec, c(1300000, 1040000, 780000, 
                       780000, 1300000, 1040000, 
                       1040000, 780000, 1300000,
                       1300000, 780000, 780000,
                       500000, 500000, 500000
                       ))
    add.constraint(lprec, c(1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "=", 1)
    add.constraint(lprec, c(0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0), "=", 1)
    add.constraint(lprec, c(0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0), "=", 1)
    add.constraint(lprec, c(0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0), "=", 1)
    set.type(lprec, c(1:15), "binary")

However, I'm not sure how to model these constraints with lpSolveAPI:

1000 x11 + 1000 x21 +500 x31 +500 x41 <= 1500 y1

1000 x12 + 1000 x22 + 500 x32 + 500 x42 <= 1500 y2

1000 x13 + 1000 x23 + 500 x33 + 500 x43 <= 1500 y3 

Any advice is much appreciated!

1 Answers1

0

I made some changes to this by changing the supply variable to an integer and keeping the fixed cost as a binary. Here is what I came up with - it solves and meets all of the constraints:

    lprec <- make.lp(0, 15)
set.objfn(lprec, c(1300, 1040, 780, 
                   780, 1300, 1040, 
                   1040, 780, 1300,
                   1300, 780, 780,
                   500000, 500000, 500000
))

## supply must meet demand constraints
add.constraint(lprec, c(1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "=", 1000)
add.constraint(lprec, c(0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0), "=", 1000)
add.constraint(lprec, c(0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0), "=", 500)
add.constraint(lprec, c(0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0), "=", 500)
## demand must not exceed supply constraints and fixed cost variable
add.constraint(lprec, c(1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1500, 0, 0), "<=", 0)
add.constraint(lprec, c(0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, -1500, 0), "<=", 0)
add.constraint(lprec, c(0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, -1500), "<=", 0)

set.type(lprec, c(1:12), "integer")
set.type(lprec, 13, "binary")
set.type(lprec, 14, "binary")
solve(lprec)
get.objective(lprec)
[1] 3470000
get.variables(lprec)
 [1]    0    0 1000 1000    0    0  500    0    0    0    0  500    1    0    1
get.constraints(lprec)
[1] 1000 1000  500  500 -500    0    0