I am working on an allocation problem using R s ompr package. The aim is to allocate Products to production lines. I have written the following code for this:
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)
I am getting the following error code
Error in check_for_unknown_vars_impl(model, the_ast) : The expression contains a variable that is not part of the model.
I am not used to modeling MIP in general, let alone in R, but would appreciate any help I can get on this! Any ideas where I go wrong ?