# \[JuMP\] Defining Ordinal Parameters

**URL:** https://discourse.julialang.org/t/jump-defining-ordinal-parameters/9207
**Category:** Optimization (Mathematical)
**Created:** [February 20, 2018, 4:54pm UTC](https://discourse.julialang.org/t/jump-defining-ordinal-parameters/9207 "2018-02-20T16:54:55Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![shoshievass](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shoshievass/32/3260_2.png) [@shoshievass](https://discourse.julialang.org/u/shoshievass)
#### Post date: [February 20, 2018, 4:54pm UTC](https://discourse.julialang.org/t/jump-defining-ordinal-parameters/9207/1 "2018-02-20T16:54:55Z")

</div>

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`?

---

<div class="post-metadata">

### Author: ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)
#### Post date: [February 20, 2018, 5:03pm UTC](https://discourse.julialang.org/t/jump-defining-ordinal-parameters/9207/2 "2018-02-20T17:03:08Z")

</div>

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

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

```

---

<div class="post-metadata">

### Author: ![daschw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/daschw/32/2926_2.png) [@daschw](https://discourse.julialang.org/u/daschw)
#### Post date: [February 21, 2018, 3:47pm UTC](https://discourse.julialang.org/t/jump-defining-ordinal-parameters/9207/3 "2018-02-21T15:47:12Z")

</div>

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

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

```
