Hi,
I want to add a new constraint to my optimization model. I work with ompr library. I have stores (j) and customers (i). I want to minimize transportation cost.
My model:
MIPModel() %>%
# 1 iff i gets assigned to warehouse j
add_variable(x[i, j], i = 1:n, j = 1:m, type = "binary") %>%
# 1 iff warehouse j is built
add_variable(y[j], j = 1:m, type = "binary") %>%
# maximize the preferences
set_objective(sum_expr(transportcost(i, j) * x[i, j], i = 1:n, j = 1:m) +
sum_expr(fixedcost[j] * y[j], j = 1:m), "min") %>%
# every customer needs to be assigned to a warehouse
add_constraint(sum_expr(x[i, j], j = 1:m) == 1, i = 1:n) %>%
# if a customer is assigned to a warehouse, then this warehouse must be built
add_constraint(x[i,j] <= y[j], i = 1:n, j = 1:m)
I want to add a new constraint. For example I have 30 different stores. First 10 stores have to sell minimum 15 units, second 20 stores have to sell minimum 10 units and third 30 stores have to sell 5 units.
I try to write like this but it didn't work:
add_constraint(sum_expr(x[i, j], j = 1:10) >= 15, i = 1:n)
Thank you!!