dirkschumacher / ompr

R package to model Mixed Integer Linear Programs
https://dirkschumacher.github.io/ompr/
Other
269 stars 35 forks source link

Getting error "*.AbstractLinearFunction" when multiplying in objective function #435

Closed Alexandertj1996 closed 2 years ago

Alexandertj1996 commented 2 years ago

Hi

Im trying to solve the following model

MIPModel() %>%

  add_variable(Y[i], i = 1:48, type = "continuous") %>%
  set_bounds(Y[i], lb = 0, ub = 1, i = 1:48) %>%

  add_variable(X[i], i = 1:48, type = "continuous") %>%
  set_bounds(X[i], lb = 0, ub = 1, i = 1:48) %>%

  add_variable(B[i], i = 1:48, type = "continuous") %>%
  set_bounds(B[i], lb = 0, ub = 1, i = 1:48) %>%

  set_objective(sum_expr(X[i] * results_M314S103$x[i] + B[i] * results_M314S103$x[i], i = 1:48), sense = "min") %>%

  add_constraint(sum_expr(B[i], i = 1:48)-sum_expr(B[i] * Y[i]) <= UB, i = 1:48) %>%
  add_constraint(sum_expr(B[i], i = 1:48)-sum_expr(B[i] * Y[i]) >= LB, i = 1:48) %>%
  solve_model(with_ROI("glpk", verbose = TRUE))

results is a df with 48 values in x. UB and LB is some predefined values.

When i run the code i get the error:

Error in `not_supported()`:
! Operation not supported
Backtrace:
  1. base::source(...)
 16. ompr:::`*.AbstractLinearFunction`(X[i], results_M314S103$x[i])
 17. ompr:::multiply.LinearTerm(x, y)
 18. ompr:::not_supported()

I hope someone is able to help me.

sbmack commented 2 years ago
  add_constraint(sum_expr(B[i], i = 1:48)-sum_expr(B[i] * Y[i]) <= UB, i = 1:48) %>%
  add_constraint(sum_expr(B[i], i = 1:48)-sum_expr(B[i] * Y[i]) >= LB, i = 1:48) %>%

B[i] * Y[i] are non-linear terms.