inequalities evaluated to true/false at build time should still be passed to the solver
dirkschumacher opened this issue · comments
Dirk Schumacher commented
At the moment model building fails if an inequality is constructed without any variables that result in FALSE
. Similarly an inequality yielding TRUE
is not added to the solver, as it is always true.
I believe it is better in both situations to pass the inequalities to the solver and let the solver handle that. Otherwise your model building can fail based on input. It also might confuse folks that the number of constraints might differ to what a user expects.
library(ompr)
model <- MIPModel() |>
add_variable(x) |>
add_constraint(0 <= 5) |>
add_constraint(x <= 1)
extract_constraints(model)
#> $matrix
#> 1 x 1 sparse Matrix of class "dgCMatrix"
#>
#> [1,] 1
#>
#> $sense
#> [1] "<="
#>
#> $rhs
#> [1] 1
MIPModel() |>
add_variable(x) |>
add_constraint(10 <= 5)
#> Error: Some constraints are not proper linear constraints or are not true.
Created on 2022-03-13 by the reprex package (v2.0.1)