dirkschumacher / ompr

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

Using index "e" fails in sum_expr #327

Closed dirkschumacher closed 2 years ago

dirkschumacher commented 3 years ago
library(ompr)
library(magrittr)

MIPModel() %>% 
  add_variable(x[e], e = 1:3) %>% 
  set_objective(sum_expr(x[e], e = 1:3))
#> Error in sum_expr(x[e], e = 1:3): lazyeval::is_call(ast) is not TRUE

MIPModel() %>% 
  add_variable(x[e], e = 1:3) %>% 
  set_objective(sum_expr(x[i], i = 1:3))
#> Mixed integer linear optimization problem
#> Variables:
#>   Continuous: 3 
#>   Integer: 0 
#>   Binary: 0 
#> Model sense: maximize 
#> Constraints: 0

Created on 2021-01-25 by the reprex package (v0.3.0)

dirkschumacher commented 3 years ago

The reason is R's partial argument matching as described in 4.3.2 of the language definition.

dirkschumacher commented 2 years ago

Is fixed in MIPModel2 which will, fingers crossed, become the successor of MIPModel. See #349