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

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.

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:

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

use

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

or

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

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

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

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

Trying the below code gave

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

MethodError: no method matching set_lower_bound(::VariableRef, ::Vector{Float64})

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

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

The code:

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

1 Like

This should work. Please provide a reproducible example.