使用ompr在R中进行产品到生产线分配错误:表达式包含不属于模型的变量

问题描述

我正在使用R的ompr软件包解决分配问题。目的是将产品分配给生产线。我为此编写了以下代码:

volume <- product$VolumeQ4          #The volume of quarter 4 of each of the products
capacity <- lines$Capacity          #The capacity of the line in quarter 4
k <- length(product$k)              #The products (k) 54 in total 
l <- length(lines$l)                #The lines (l) 11 in total
product_lines_matrix                #this is a 54x11 dataframe showing if a line is capable 
                                    #to produce a product,1 = if capable,0 if not capable. 

model <- MIPModel() %>%
  
# 1 if product i  is assigned to line j 
  
add_variable(x[i,j],i = 1:k,j = 1:l,type = "binary") %>%
  
  # # objective is to assign all skus to lines where the line is capable
  
  set_objective(sum_expr(product_lines_matrix[i,j] * x[i,j = 1:l),"max") %>%
  
  # each product needs to be assigned to line 
  
  add_constraint(sum_expr(x[i,j = 1:l) == 1,i = 1:k) %>% 
  
   # we cannot exceed the Q4 capacity of a line
  
  add_constraint(sum_expr(x[i,j]*volume[i],i = 1:k) <= capacity[j],j = 1:l) 

我收到以下错误代码

check_for_unknown_vars_impl(model,the_ast)中的错误: 该表达式包含一个不属于模型的变量。

我一般不习惯对MIP进行建模,更不用说R了,但是我很乐意为此提供帮助! 有什么想法我做错了吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)