Skip to contents

Sum over one or more indexing variables.

Usage

sum_over(...)

Arguments

...

The first argument(s) must be named: the name represents the indexing variable, and the values represent the sequence over which to sum.

The last argument is the expression of the sum.

Value

The value of the sum.

Details

The syntax is similar to the one used in math. For instance, \( \sum_{i=1}^n \sum_{j=1}^m {x_{ij} * c_j} \) would be written as sum_over(i = 1:n, j = 1:n, x[i,j] * c[j]).

Examples

cost <- c(5, 2, 7)
p <- lp_problem() |>
  lp_variable(x[1:2, 1:3]) |>
  lp_minimize(sum_over(i = 1:2, j = 1:3, x[i, j] * cost[j]))
p$objective
#> minimize linear function:
#> sum_over(i = 1:2, j = 1:3, x[i, j] * cost[j])
#>