【问题标题】:R: how to hand over MIP_GAP option to glpk in ROIR:如何将 MIP_GAP 选项移交给 ROI 中的 glpk
【发布时间】:2019-08-08 07:13:37
【问题描述】:

我正在通过 R 中的 roi 包使用 glpk 求解器来求解 mip 模型。整数优化非常快地收敛到真正最优值的 0.1% 以内的解,但如果有很多整数要求解,则需要很长时间。

出于这个原因,我想将相对 mip 间隙容差(如此处记录的https://rdrr.io/cran/glpkAPI/man/glpkConstants.html)设置为比默认值更大的值,以便求解器更快地收敛。我知道这可能会产生次优解决方案,但我想了解近似解决方案。

将 mip 间隙选项移交给 glpk 时,我收到一条警告消息,该选项显然被忽略了。我的代码和输出有一个小插图示例:

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])

这给了我

<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'

通过 tm_limit 移交时间限制没有问题,所以我很难理解为什么它不接受 mip_gap 选项。

有什么想法吗?非常感谢。

【问题讨论】:

    标签: r linear-programming roi glpk mixed-integer-programming


    【解决方案1】:

    ROI.plugin.glpkinternally 使用 Rglpk,因此您可以使用Rglpk 中记录的控制参数。这意味着您不能设置mip_gap

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-06
      • 1970-01-01
      • 2019-06-21
      • 2020-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多