我正在使用 R s 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], i = 1:k, j = 1:l), "max") %>%
# each product needs to be assigned to line
add_constraint(sum_expr(x[i, j], 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 中了,但如果我能得到任何帮助,我将不胜感激!有什么想法我哪里出错了吗?