1

我正在使用 ompr 包来开发 BIN PACKING 问题,如以下链接所示:

https://developers.google.com/optimization/bin/bin_packing

这是我运行的代码:

# Import lpSolve package
library(lpSolve)

#Import required packages
library(dplyr)
library(ROI)
library(ROI.plugin.symphony)
library(ompr)
library(ompr.roi)

#Set weights 
w <- c(48, 30, 19, 36, 36, 27, 42, 42, 36, 24, 30) 

#Set bins' capacities 
k <- c(100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100) 

#Set number of available Bins
m <- length(w)

#Set number of Items
n <- length(w)


#Build model
Model <- MIPModel() %>% #define variables
         add_variable(y[j], j = 1:m, type = "binary") %>%
         add_variable(x[i][j], i = 1:n , j = 1:m, type = "binary") %>%
         set_objective(sum_expr(y[j], j = 1:m), "min") %>%   #define objective function
         add_constraint(sum_expr(w[i] * x[i, j], i = 1:n) <= k[j] * y[j], j = 1:m) %>% #define constraints
         add_constraint(sum_expr(x[i, j], j = 1:m) == 1 , i = 1:n) %>%
         solve_model(with_ROI(solver = "symphony", verbosity = 1))
``
End this is the error I get:

    Error in `[[<-`(`*tmp*`, var_name, value = var) : 
  index not found at level 1 

What does it mean ? How can I address this issue?
4

0 回答 0