Skip to contents

Change the lower and upper bounds of a named variable, indexed variable or a group of variables.

Usage

set_bounds(.model, .variable, ..., lb = NULL, ub = NULL)

set_bounds_(.model, .variable, ..., lb = NULL, ub = NULL, .dots)

Arguments

.model

the model

.variable

the variable name/definition or a linear constraint

...

quantifiers for the indexed variable

lb

the lower bound of the variable.

ub

the upper bound of the variable

For MIPModel you can also pass (in)equalities to define bounds. Please look at the examples.

.dots

Used to work around non-standard evaluation.

Examples

library(magrittr)
MIPModel() %>%
  add_variable(x[i], i = 1:5) %>%
  add_constraint(x[i] >= 1, i = 1:5) %>% # creates 5 constraints
  set_bounds(x[i], lb = 3, i = 1:3) %>%
  variable_bounds()
#> $lower
#> [1]    3    3    3 -Inf -Inf
#> 
#> $upper
#> [1] Inf Inf Inf Inf Inf
#> 

MIPModel() %>%
  add_variable(x[i], i = 1:5) %>%
  set_bounds(x[i] <= i, i = 1:5) %>% # upper bound
  set_bounds(x[i] >= 0, i = 1:5) %>% # lower bound
  set_bounds(x[5] == 45) %>%
  variable_bounds()
#> $lower
#> [1]  0  0  0  0 45
#> 
#> $upper
#> [1]  1  2  3  4 45
#>