Calculate the number of values greater than a certain value

You cannot write JuMP constraints like this.

The reformulations is usually something like this, where M is a large upper bound on x - 60:

M = 1_000
model = Model()
@variable(model, x)
@variable(model, z, Bin)

@constraint(model, x - 60 <= M * z)
# if x > 60, then x - 60 > 0, so z must be 1
# if x < 60, then x - 60 < 0, so z might be 0 or 1

@constraint(model, 60 - x <= M * (1 - z))
# if x > 60, then 60 - x < 0, so (1 - z) might be 0 or 1
# if x < 60, then 60 - x > 0, so (1 - z) must be 0
1 Like