Accessing wanted indices of a vector

I have a vector ( Vector{VariableRef} ) :
@variable(model,v[1:2583)])

I want to choose some indices by means of irreversible_indices
which I get it’s type as Vector{Int64}

but when I try to run this :
v[irreversible_indices]
this is the error:
BoundsError: attempt to access 2583-element Vector{VariableRef} at index [[0, 1, 4, 5, 6, 7, 8, 9, 10, 12 … 2571, 2572, 2574, 2576, 2577, 2578, 2579, 2580, 2581, 2582]]

or if I try like this :
@constraint(model,[j in irreversible_indices],v[j]>=0)
error:
BoundsError: attempt to access 2583-element Vector{VariableRef} at index [0]

however if I print elements of irreversible_indices the result is like 0, 1, 5, 6 ,… not [0], [1], [5]…

what is wrong here???

The 0 in irreversible_indices is probably the problem, because arrays/vecors are 1-based in Julia:

julia> v=[1,2,3]
3-element Vector{Int64}:
 1
 2
 3

julia> i=[0,2,3]
3-element Vector{Int64}:
 0
 2
 3

julia> v[i]
ERROR: BoundsError: attempt to access 3-element Vector{Int64} at index [[0, 2, 3]]
Stacktrace:
 [1] throw_boundserror(A::Vector{Int64}, I::Tuple{Vector{Int64}})
   @ Base .\abstractarray.jl:651
 [2] checkbounds
   @ .\abstractarray.jl:616 [inlined]
 [3] _getindex
   @ .\multidimensional.jl:831 [inlined]
 [4] getindex(A::Vector{Int64}, I::Vector{Int64})
   @ Base .\abstractarray.jl:1170
 [5] top-level scope
   @ REPL[10]:1
2 Likes

Thanks a lot!!! :pray: :pray: :pray:
taking indices from python resulted in a zero index

2 Likes