R, maximization problem, MIPModel - some questions

23 Views Asked by At

I am trying to solve the following optimization problem, and in general it works, but there are a few issues which I would like to get help with. The problem itself is based on the so-called DEA approach. Suppose that we have 7 firms that transform 1 input (cost) into 5 outputs. I would like to combine some of the firms into a merger, and would like to find the merger that is as far away from the efficient frontier as possible. It is not necessary to understand this in order to answer my questions - it is just a maximization problem where I have a vector-variable MyLambda where weights can be between 0 and 1, and they should sum up to 1. I have a vector-variable MyMerger which can either be 0 or 1. I would like to maximize the variable MySlack which is a single number. Suppose I do this with the numbers that I have:

library(dplyr)
library(lpSolveAPI)

library(magrittr)
library(ROI)
library(ompr)
library(ROI.plugin.glpk)
library(ompr.roi)

X=c(250000,1700000,160000,145000,185000,55000,85000)

Y=c(38400000,2700000,500000,600000,237000000,
    218800000,24700000,3300000,800000,1770000000,
    24000000,1200000,1900000,0,170000000,
    21500000,900000,400000,0,76000000,
    24600000,1200000,300000,300000,115000000,
    5700000,1000000,0,400000,65000000,
    9100000,700000,700000,300000,35000000)

Y <- matrix(Y,nrow=7,ncol=5,byrow=TRUE)

K=dim(Y)[1]

model <- MIPModel() %>%
  add_variable(MyLambda[i], i=1:K, type = 'continuous',lb = 0, ub = 1) %>% 
  add_variable(MyMerger[i], i=1:K, type = 'binary',lb = 0, ub = 1) %>% 
  add_variable(MySlack,type = 'continuous') %>% 
  set_objective(MySlack, sense = 'max') %>% 
  add_constraint(sum_over(MyMerger[i]*X[i], i=1:K) >= sum_over(MyLambda[j] * X[j], j=1:K) + MySlack)  %>%
  add_constraint(sum_over(MyMerger[i] * Y[i,j], i=1:K) <= sum_over(MyLambda[i]*Y[i,j],i=1:K),j=1:n) %>% #n=5 
  add_constraint(sum_over(MyLambda[i],i=1:K) == 1)

result <- solve_model(model, with_ROI("glpk", verbose = TRUE))
MyResult=result$solution
round(MyResult,2)

Then it cannot find the solution, and it says: enter image description here

But then if I simply divide the numbers by 1000000, then the solution can be found. So, if I simply add one line of code before running the MIPModel, then it works as it should. So, I add the following line:

Y=Y/1000000

and the output becomes:enter image description here

And I get the right output which is that firm 5 and 7 should be in the merger. So, how is that possible that it went from unbounded problem to a solution if I simply divide everything by a constant?

  1. As I understand, it probably has difficulties with so large numbers, and my question is how should I define the problem such that it is easy for R to solve it? Maybe scale the numbers down such that all numbers are between 0 and 100? Maybe using a different solver - something else than glpk? I do not have any good understanding of different solvers, so please suggest what I could try here.

  2. In the example above result$solution gives all variables in one vector: MyLambda followed by MyMerger, followed by MySlack. Is there an easy way to extract those numbers into three separate vectors such that I can use MyLambda, MyMerger and MySlack in the code after the maximization problem? Of course I could do it manually, like MyMerger=result$solution[1:7], but is there an easier way such that I do not need to calculate where one variable ends and another starts (I have a more advanced problems where it is not as straightforward as here).

  3. Sometimes when I run a large maximization problem, it takes a long time to calculate and it gives me the following output while calculating: enter image description here

What do these numbers mean (e.g. the percentages), and how can I know whether it is getting closer to the solution? Because right now it simply runs, and I have no idea whether it will finish soon or whether the problem is too large to be solved.

Thank you very much!

0

There are 0 best solutions below