[JuMP] Defining Ordinal Parameters

I would like to define a JuMP optimization program with a vector of variables x that is ordered, i.e. x[1] < x[2] < x[3] .... Is there any elegant way to do this in lieu of manually adding constraints for every pair of elements in x?

While I agree that loops are ugly and ideally should not appear in optimization code, this looks like a case where one is appropriate. If all your are doing is x_{i}<x_{i+1}, your loop would simply look like

for i ∈ 1:(length(x)-1)
    @constraint(m, x[i] < x[i+1])
end 
2 Likes

Essentially the same as @ExpandingMan’s proposal, but in one line:

@constraint(m, [i in 1:(length(x) - 1)], x[i] <= x[i + 1])
1 Like