Skip to contents

States that the expression f lies in set (see zero() and the other constraint sets). With over, the constraint is repeated for every element of one or more index sets, like a constraint written "for all i in S". add() builds these for you.

Usage

constraint(f, set, over = list())

Arguments

f

The expression node.

set

The set f must lie in: zero(), nonneg() or indicator().

over

A list of list(idx, set_ref) pairs, each repeating the constraint for every element of the set set_ref (from ir_set_ref()), with the index named idx standing for the element in f. list() for a single constraint.

Value

A plain list without a class, with the fields f, set and over. It is an element of the list a program() takes as constraints.

Examples

# x <= 4, written as 4 - x >= 0
constraint(ir_apply("-", list(ir_const(4), ir_var("x"))), nonneg())
#> $f
#> $f$kind
#> [1] "apply"
#> 
#> $f$op
#> [1] "-"
#> 
#> $f$args
#> $f$args[[1]]
#> $f$args[[1]]$kind
#> [1] "const"
#> 
#> $f$args[[1]]$value
#> [1] 4
#> 
#> 
#> $f$args[[2]]
#> $f$args[[2]]$kind
#> [1] "var"
#> 
#> $f$args[[2]]$name
#> [1] "x"
#> 
#> $f$args[[2]]$index
#> list()
#> 
#> 
#> 
#> 
#> $set
#> $set$kind
#> [1] "nonneg"
#> 
#> 
#> $over
#> list()
#>