# Passing arrays as variable bounds without indexing them is not supported. JuMP

**URL:** https://discourse.julialang.org/t/passing-arrays-as-variable-bounds-without-indexing-them-is-not-supported-jump/97697
**Category:** Optimization (Mathematical)
**Tags:** jump
**Created:** [April 20, 2023, 10:50am UTC](https://discourse.julialang.org/t/passing-arrays-as-variable-bounds-without-indexing-them-is-not-supported-jump/97697 "2023-04-20T10:50:25Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![himgoy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/himgoy/32/49167_2.png) [@himgoy](https://discourse.julialang.org/u/himgoy)
#### Post date: [April 20, 2023, 10:50am UTC](https://discourse.julialang.org/t/passing-arrays-as-variable-bounds-without-indexing-them-is-not-supported-jump/97697/1 "2023-04-20T10:50:25Z")

</div>

Hello Everyone,  
I am working on a linear programming problem for which I am creating lower bounds and upper bounds for each variable using for loop and pushing it into an array. I have a total of 5489 variables.

```julia
M = Model()
set_optimizer(M, HiGHS.Optimizer)
lb = []
ub = []
for i in 1:shapeOfMat[1]
  for j in 1:shapeOfMat[2]
    if datecolMatrix[i, j] == 1
      if condition
        bound = *
        push!(lb, bound)
        push!(ub, bound)
      else
        if condition
          ubound = *
          push!(lb, 1)
          push!(ub, ubound)
        else
          lowerBound = *
          upperBound = *
          push!(lb, lowerBound)
          push!(ub, upperBound)
        end
      end
    end
  end
end

# Define the variables
@variable(M, lb[i] <= y[i = 1:len] <= ub[i])

```

For the above code I am getting :-

At In[31]:57: `@variable(M, ub[i] >= y[i = 1:len] >= lb[i])`: Passing arrays as variable bounds without indexing them is not supported.

Instead of:

```julia
@variable(model, x[1:2] >= lb)

```

use

```julia
@variable(model, x[i=1:2] >= lb[i])

```

or

```julia
@variable(model, x[1:2])
set_lower_bound.(x, lb)
```

---

<div class="post-metadata">

### Author: ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)
#### Post date: [April 20, 2023, 3:55pm UTC](https://discourse.julialang.org/t/passing-arrays-as-variable-bounds-without-indexing-them-is-not-supported-jump/97697/2 "2023-04-20T15:55:49Z")

</div>

Does it work when you replace your code with JuMP’s suggestions?

As a side note, you might want to specify the type of your bound arrays beforehand: declaring `lb = Float64[]` instead of `lb = []` will do wonders for performance

---

<div class="post-metadata">

### Author: ![himgoy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/himgoy/32/49167_2.png) [@himgoy](https://discourse.julialang.org/u/himgoy)
#### Post date: [April 20, 2023, 6:42pm UTC](https://discourse.julialang.org/t/passing-arrays-as-variable-bounds-without-indexing-them-is-not-supported-jump/97697/3 "2023-04-20T18:42:40Z")

</div>

Thank You for the suggestion. And no, none of the changes suggested by JuMP are working. I have tried

```julia
@variable(M, y[i = 1:len] >= lb[i])

```

Trying the below code gave

```julia
@variable(M, y[i = 1:len])
set_lower_bound.(y, lb)

```

MethodError: no method matching set\_lower\_bound(::VariableRef, ::Vector{Float64})

---

<div class="post-metadata">

### Author: ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)
#### Post date: [April 20, 2023, 6:51pm UTC](https://discourse.julialang.org/t/passing-arrays-as-variable-bounds-without-indexing-them-is-not-supported-jump/97697/4 "2023-04-20T18:51:35Z")

</div>

How about this, with elementwise bounds that do not rely on indexing `lb` or `ub` with `i`?

```julia
@variable(model, lb .<= x[1:2] .<= ub)

```

---

<div class="post-metadata">

### Author: ![joaquimg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joaquimg/32/223_2.png) [@joaquimg](https://discourse.julialang.org/u/joaquimg)
#### Post date: [April 20, 2023, 10:03pm UTC](https://discourse.julialang.org/t/passing-arrays-as-variable-bounds-without-indexing-them-is-not-supported-jump/97697/5 "2023-04-20T22:03:18Z")

</div>

The code:

```julia
using JuMP, HiGHS
model = Model(HiGHS.Optimizer)
N = 5
lb = zeros(N)
@variable(model, y[i = 1:N] >= lb[i])
@variable(model, z[1:N])
set_lower_bound.(z, lb)

```

works perfectly for me with JuMP 1.10.0 and HiGHS 1.5.1

---

<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: [April 20, 2023, 11:30pm UTC](https://discourse.julialang.org/t/passing-arrays-as-variable-bounds-without-indexing-them-is-not-supported-jump/97697/6 "2023-04-20T23:30:19Z")

</div>

> [@himgoy](#):
>
> And no, none of the changes suggested by JuMP are working. I have tried

This should work. Please provide a reproducible example.
