You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi again, I'm having some trouble formatting the following as a MILP problem. I have 980 products and 4 groups. Each product has a attraction rate AR that differs for each group. Each product also has total sales. I want to maximize the sum of AR + Sales (normalized). I have the latest dev version.
The following MIPModel works just fine:
model <- MIPModel() %>%
add_variable(x[p, g], p = 1:n, g = 1:m, type = "binary") %>%
set_objective(sum_expr(ar[p, g] * x[p, g] +
total_sales[p] * x[p, g], p = 1:n, g = 1:m), "max") %>%
# each product can be used once
add_constraint(sum_expr(x[p, g], g = 1:m) <= 1, p = 1:n) %>%
# we want n_products selected for each group
add_constraint(sum_expr(x[p, g], p = 1:n) == n_products, g = 1:m)
I'm bit confused how to model the ar part as MILPModel. The following works but yields different (wrong) results: (#238)
ar_vector <- ar[1:nrow(ar), 1:ncol(ar)] %>% unlist()
milpmodel <- MILPModel() %>%
add_variable(x[p, g], p = 1:n, g = 1:m, type = "binary") %>%
set_objective(sum_expr(ar_vector * x[p, g] +
colwise(total_sales[p]) * x[p, g] , p = 1:n, g = 1:m), "max")
# each product can be used once
add_constraint(sum_expr(x[p, g], g = 1:m) <= 1, p = 1:n) %>%
# we want n_products selected for each group
add_constraint(sum_expr(x[p, g], p = 1:n) == n_products, g = 1:m)
I also tried the following:
arfunc <- function(p,g){
ar_sub <- ar[p, g]
ar_vec <- as.vector(ar_sub)
return(ar_vec)
}
set_objective(sum_expr(w_ar * colwise(arfunc(p, g)) * x[p, g] +
w_sales * colwise(total_sales[p]) * x[p, g], p = 1:n, g = 1:m), "max")
Error in as.data.frame.default(x[[i]], optional = TRUE) :
cannot coerce class ‘structure("LinearVariableCollection", package = "ompr")’ to a data.frame
What is the correct way to format this problem?
The text was updated successfully, but these errors were encountered:
Zuumx
changed the title
Correct way to use a matrix in MILP
Correct way to use a matrix in MILP objective function
Jun 17, 2019
Hi again, I'm having some trouble formatting the following as a MILP problem. I have 980 products and 4 groups. Each product has a attraction rate AR that differs for each group. Each product also has total sales. I want to maximize the sum of AR + Sales (normalized). I have the latest dev version.
The following MIPModel works just fine:
I'm bit confused how to model the ar part as MILPModel. The following works but yields different (wrong) results: (#238)
I also tried the following:
What is the correct way to format this problem?
The text was updated successfully, but these errors were encountered: