微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何解决ompr包R中的“索引未找到错误”?

如何解决如何解决ompr包R中的“索引未找到错误”?

我正在使用 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,27,42,24,30) 

#Set bins' capacities 
k <- c(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,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 = 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?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。