1

I am trying to solve an exercise related to optimization using binary constraint. Below is a description of the problem.

Supply chain - basic BIP

For this problem I am using R and lpSolveAPI - so far I managed to translate the problem into a list of constraints and build the correct objective function for the problem however my program does not produce the correct output because I place the three Y variables (yE, yT and yN) into my objective function. My objective function should not contain the three trailing 0 (see the definition of the objective function on the picture above).

My question, how can I define the variable y such that they are binary and only used as part of the constraint (so they don't appear in the objective function)?

# SELECT FROM ....
require(lpSolveAPI)
# Set the decision variables
obj <- c(21, 22.5, 22.5, 24.5, 23, 25.5, 0, 0, 0)
# Set the constrains parameters
#               EG,EK,TG,TK,NG,NK,yE,yT,yN
LHS <- matrix(c(1, 1, 0, 0, 0, 0, 0, 0, 0,
                0, 0, 1, 1, 0, 0, 0, 0, 0,
                0, 0, 0, 0, 1, 1, 0, 0, 0,
                1, 0, 1, 0, 1, 0, 0, 0, 0,
                0, 1, 0, 1, 0, 1, 0, 0, 0,
                1, 1, 0, 0, 0, 0, -425, 0, 0,
                0, 0, 1, 1, 0, 0, 0, -400, 0,
                0, 0, 0, 0, 1, 1, 0, 0, -750,
                0, 0, 0, 0, 0, 0, 1, 1, 1), nrow=9, byrow = TRUE)
RHS <- c(425, 400, 750, 550, 450, 0, 0, 0, 2)
constranints_direction <- c("<=", "<=", "<=", ">=", ">=", "<=", "<=", "<=", "<=")
# Set 9 constraints and 9 decision variables ==> THERE SHOULD BE ONLY 6 !!!
lprec <- make.lp(nrow = 9, ncol = 9)
# Set the type of problem we are trying to solve
lp.control(lprec, sense="min")
set.type(lprec, 7:9, c("binary"))
set.objfn(lprec, obj)
add.constraint(lprec, LHS[1, ], constranints_direction[[1]], RHS[1])
add.constraint(lprec, LHS[2, ], constranints_direction[[2]], RHS[2])
add.constraint(lprec, LHS[3, ], constranints_direction[[3]], RHS[3])
add.constraint(lprec, LHS[4, ], constranints_direction[[4]], RHS[4])
add.constraint(lprec, LHS[5, ], constranints_direction[[5]], RHS[5])
add.constraint(lprec, LHS[6, ], constranints_direction[[6]], RHS[6])
add.constraint(lprec, LHS[7, ], constranints_direction[[7]], RHS[7])
add.constraint(lprec, LHS[8, ], constranints_direction[[8]], RHS[8])
add.constraint(lprec, LHS[9, ], constranints_direction[[9]], RHS[9])

# Display the LPsolve matrix
lprec
get.type(lprec)

# Solve problem
solve(lprec)
# Get the decision variables values
get.variables(lprec)
# Get the value of the objective function
get.objective(lprec)

This code produce the objective output 22850

> # Get the decision variables values
> get.variables(lprec)
[1]   0 425   0   0 550  25   1   0   1
> # Get the value of the objective function
> get.objective(lprec)
[1] 22850

However it must produce 22850.50 for the same variable allocation.

Michael
  • 2,436
  • 1
  • 36
  • 57

1 Answers1

0

If you would run:

obj <- c(21, 22.5, 22.5, 24.5, 23, 25.5)
x <- c(0, 425,   0,   0, 550,  25)
obj %*% x

you would see:

      [,1]
[1,] 22850

i.e. this allocation gives an objective of 22850.

Erwin Kalvelagen
  • 15,677
  • 2
  • 14
  • 39