How to include a customized function which takes expressions as input values inside a constraint?

You cannot model constraints like this directly in JuMP. You must reformulate into a mixed-integer linear program.

using JuMP
# To model y = 1 if sum(x) > 0
model = Model()
@variable(model, x[1:3], Bin)
@variable(model, y, Bin)
# If any x > 0, then y = 1
@constraint(model, 3 * y >= sum(x))
# if all x = 0, then y = 0
@constraint(model, y <= sum(x))
1 Like