Skip to contents

Add one or more constraints to the model using quantifiers.

Usage

add_constraint(.model, .constraint_expr, ..., .show_progress_bar = TRUE)

add_constraint_(
  .model,
  .constraint_expr,
  ...,
  .dots,
  .show_progress_bar = TRUE
)

Arguments

.model

the model

.constraint_expr

the constraint. Must be a linear (in)equality with operator "<=", "==" or ">=".

...

quantifiers for the indexed variables. For all combinations of bound variables a new constraint is created. In addition you can add filter expressions

.show_progress_bar

displays a progressbar when adding multiple constraints

.dots

Used to work around non-standard evaluation.

Value

a Model with new constraints added

Examples

library(magrittr)
MIPModel() %>%
  add_variable(x[i], i = 1:5) %>%
  # creates 5 constraints
  add_constraint(x[i] >= 1, i = 1:5) %>%
  # you can also use filter expressions
  add_constraint(x[i] >= 1, i = 1:5, i %% 2 == 0) %>%
  # and depent on other indexes
  add_constraint(x[j] >= 1, i = 1:10, j = 1:i, j <= 5)
#> Mixed integer linear optimization problem
#> Variables:
#>   Continuous: 5 
#>   Integer: 0 
#>   Binary: 0 
#> No objective function. 
#> Constraints: 47