Skip to contents

Pairs a constraint function with the value it is compared against and the comparison type. Pass a list of these as constraints to optim_minimize() with method = "augmented_lagrange".

Usage

optim_constraint(f, value, type = c("eq", "le", "ge"), tolerance = 1e-08)

Arguments

f

a function taking a numeric parameter vector and returning a single number – the left-hand side of the constraint.

value

the number f is compared against.

type

"eq" for f(x) == value, "le" for f(x) <= value, or "ge" for f(x) >= value.

tolerance

how far from value still counts as feasible, matching the upstream Constraint class's own default.

Value

a corehydro_constraint list.

Examples

# x + y == 4
optim_constraint(function(p) p[1] + p[2], value = 4, type = "eq")
#> <corehydro_constraint> f(x) == 4 (tolerance 1e-08)