# JuMP array or dictionary lookups

**URL:** <https://discourse.julialang.org/t/jump-array-or-dictionary-lookups/27937>\
**Category:** Optimization (Mathematical)\
**Created:** [August 24, 2019, 3:31pm UTC](https://discourse.julialang.org/t/jump-array-or-dictionary-lookups/27937 "2019-08-24T15:31:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bhalonen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bhalonen/32/9848_2.png) [@bhalonen](https://discourse.julialang.org/u/bhalonen)\
**Post date:** [August 24, 2019, 3:31pm UTC](https://discourse.julialang.org/t/jump-array-or-dictionary-lookups/27937/1 "2019-08-24T15:31:30Z")

</div>

Is it possible to look up values in an array or a dict using integer variables?  
Something like

```julia
@variable(model, x, Int)
# restrict x to appropriate values
@constraint(model, my_array[x] <= 5)

```

Or should a binary array with a single one be created and summed over to implement the look up? Like:

```julia
@variable(model, x[1:n], Bin)
@constraint(model, sum(x[i] for i in 1:n) ==1)
@constraint(model, sum(x[i]*my_array[i] for i in 1:n) <= 5)

```

Is this where you use something like MOI.SOS1? Can you use SOS1 on an array of arrays?

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [August 24, 2019, 3:39pm UTC](https://discourse.julialang.org/t/jump-array-or-dictionary-lookups/27937/2 "2019-08-24T15:39:30Z")

</div>

You should use the binary approach.

You could also use an SOS1 over `x`. But the performance is likely similar.
