I am using the glpk solver via the roi package in R to solve a mip model. The integer optimization converges very fast to a solution that is within 0.1% of the true optimum but then takes forever if there are a lot of integers to solve for.
For that reason I want to set the relative mip gap tolerance (as documented here https://rdrr.io/cran/glpkAPI/man/glpkConstants.html) to a larger value than default so that the solver converges faster. I am aware that this may yield suboptimal solutions but I want to get a feeling about the approximate solution.
When handing over the mip gap option to glpk I get a warning message and the option is obviously ignored. There is a small illustration example of my code and output:
library(magrittr)
library(dplyr)
library(ompr)
library(ROI)
library(Rglpk)
library(ROI.plugin.glpk)
library(ompr.roi)
#fun <- function(big_M){
big_M<-1200
set.seed(123)
n_h <- 10
n_l <- 10
capacities_1 <- matrix(sample(0:1000, n_l*n_h/2, replace=TRUE),ncol =n_h/2,nrow=n_l)
capacities_2 <- matrix(sample(0:100, n_l*n_h/2, replace=TRUE),ncol =n_h/2,nrow=n_l)
capacities <- cbind(capacities_1,capacities_2)
demand <- 0.9*matrix(apply(capacities,1,sum))
x_min <- 50
plant_capacities <- 1.1*matrix(apply(capacities,2,sum))
u <- matrix(sample(1:100, n_l*n_h, replace=TRUE),ncol =n_h,nrow=n_l)*sign(capacities)
model <-
MIPModel() %>%
add_variable(b[l,h], l = 1:n_l, h= 1:n_h, type = "binary") %>%
add_variable(x[l,h], l = 1:n_l, h = 1:n_h, type = "continuous",lb =0,ub=1200) %>%
add_constraint(x_min*b[l,h] <= x[l,h], l=1:n_l, h=1:n_h ) %>%
add_constraint( x[l,h] <= big_M * b[l,h], l=1:n_l, h=1:n_h ) %>%
set_objective(sum_expr(u[l,h] * x[l,h], l = 1:n_l, h = 1:n_h)) %>%
add_constraint(sum_expr(x[l,h], l = 1:n_l) <= plant_capacities[h], h = 1:n_h ) %>%
add_constraint(x[l,h] <= capacities[l,h] , l = 1:n_l, h = 1:n_h ) %>%
add_constraint(sum_expr(x[l,h], h = 1:n_h) ==demand[l], l = 1:n_l ) %>%
solve_model(with_ROI("glpk",verbose=TRUE,tm_limit = 1000 * 360,mip_gap = 1e-6))
result_table <- get_solution(model, x[l,h])
and this gives me
<SOLVER MSG> ----
GLPK Simplex Optimizer, v4.47
320 rows, 200 columns, 700 non-zeros
0: obj = 0.000000000e+000 infeas = 2.555e+004 (10)
* 155: obj = 1.350009700e+006 infeas = 0.000e+000 (0)
* 212: obj = 1.422776500e+006 infeas = 0.000e+000 (0)
OPTIMAL SOLUTION FOUND
GLPK Integer Optimizer, v4.47
320 rows, 200 columns, 700 non-zeros
100 integer variables, all of which are binary
Integer optimization begins...
+ 212: mip = not found yet <= +inf (1; 0)
+ 314: >>>>> 1.387478500e+006 <= 1.388678500e+006 < 0.1% (22; 0)
+ 315: >>>>> 1.388678500e+006 <= 1.388678500e+006 0.0% (9; 13)
+ 315: mip = 1.388678500e+006 <= tree is empty 0.0% (0; 43)
INTEGER OPTIMAL SOLUTION FOUND
<!SOLVER MSG> ----
Warning message:
In ROI::ROI_solve(op, solver, ...) :
the control argument "mip_gap" is not available in solver 'glpk'
Handing over the time limit via tm_limit works without problems so I am struggling to understand why it won't accept the mip_gap option.
Any ideas? Thanks a lot.