Hi,
I am trying to create anonymous variables and collect them in a vector. But only those with index starting from 1 can be collected. Others will result in error. Is there any method to push those variables into a vector? I paste an example below. Thanks
using JuMP,Gurobi
I=1:5
m=Model(solver=GurobiSolver())
x=Vector{Variable}[] # the vector used to collec variables
y1=@variable(m,[i=1:4],basename="y1") # variable with index starting from 1
y2=@variable(m,[i=4:6],basename="y2") # variable with index not starting from 1
y3=@variable(m,[i in I],basename="y3") # variable with index in an array
push!(x,y1) # good
push!(x,y2) # error
push!(x,y3) # error
The error reported is
MethodError: Cannot `convert` an object of type JuMP.JuMPArray{JuMP.Variable,1,Tuple{UnitRange{Int64}}} to an object of type Array{JuMP.Variable,1}
This may have arisen from a call to the constructor Array{JuMP.Variable,1}(...),
since type constructors fall back to convert methods.
in push!(::Array{Array{JuMP.Variable,1},1}, ::JuMP.JuMPArray{JuMP.Variable,1,Tuple{UnitRange{Int64}}}) at .\array.jl:479