Help me with indexing

For example

using JuMP,SCS

m=Model(with_optimizer(SCS.Optimizer))

branch=[1 2 0.1
        3 4 0.1 
        4 5 0.2
        4 6 0.3
        5 6 0.1
       ]

G=length(branch[:,1])

@variable(m,P[branch[1:G,1], branch[1:G,2]])

If i type in the above code I’m getting the following error, what would be change i need to do or can anyone suggest me a different notation

Thank you

ERROR: LoadError: Repeated index 4.0. Index sets must have unique elements.
Stacktrace:
[1] build_lookup(::Array{Float64,1}) at C:\Users\yaramasv.juliapro\JuliaPro_v1.3.1-1\packages\JuMP\MsUSY\src\Containers\DenseAxisArray.jl:23
[2] _broadcast_getindex_evalf at .\broadcast.jl:630 [inlined]
[3] _broadcast_getindex at .\broadcast.jl:603 [inlined]
[4] #19 at .\broadcast.jl:1023 [inlined]
[5] ntuple at .\ntuple.jl:42 [inlined]
[6] copy at .\broadcast.jl:1023 [inlined]
[7] materialize at .\broadcast.jl:819 [inlined]
[8] DenseAxisArray at C:\Users\yaramasv.juliapro\JuliaPro_v1.3.1-1\packages\JuMP\MsUSY\src\Containers\DenseAxisArray.jl:54 [inlined]
[9] construct_undef_array(::Type{VariableRef}, ::Tuple{Array{Float64,1},Array{Float64,1}}) at C:\Users\yaramasv.juliapro\JuliaPro_v1.3.1-1\packages\JuMP\MsUSY\src\Containers\DenseAxisArray.jl:96
[10] JuMP.Containers.DenseAxisArray{VariableRef,N,Ax,L} where L<:Tuple{Vararg{Dict,N}} where Ax where N(::UndefInitializer, ::Array{Float64,1}, ::Vararg{Array{Float64,1},N} where N) at C:\Users\yaramasv.juliapro\JuliaPro_v1.3.1-1\packages\JuMP\MsUSY\src\Containers\DenseAxisArray.jl:91
[11] top-level scope at C:\Users\yaramasv.juliapro\JuliaPro_v1.3.1-1\packages\JuMP\MsUSY\src\macros.jl:189
in expression starting at C:\Users\yaramasv\OneDrive - The University of Colorado Denver\Conference paper\Report\julia\powerflow34.jl:138

@variable(model, x[1:2, 1:2]) makes a 2-by-2 matrix of variables. It looks like you want

@variable(model, P[1:size(branch, 1)])
P[3]  # Corresponds to (4, 5, 0.2)

or

S = [(branch[r, 1], branch[r, 2]) for r = 1:size(branch, 1)]
@variable(model, P[S])
P[(3, 4)]  # Corresponds to (3, 4, 0.1)

Thanks for your reply. odow

It helped me a lot thank you once again

There is one more thing I want to ask.

If we want only the first column of the branch, what we have to do ?

I mean , if I write like this this

S=[(branch[r,1]) for r= 1:size(branch,1)]
@variable(m,v[S])

I’m getting the same error.

Like this

ERROR: LoadError: Repeated index 4.0. Index sets must have unique elements.
Stacktrace:
 [1] build_lookup(::Array{Float64,1}) at C:\Users\yaramasv\.juliapro\JuliaPro_v1.3.1-1\packages\JuMP\MsUSY\src\Containers\DenseAxisArray.jl:23
 [2] _broadcast_getindex_evalf at .\broadcast.jl:630 [inlined]
 [3] _broadcast_getindex at .\broadcast.jl:603 [inlined]
 [4] #19 at .\broadcast.jl:1023 [inlined]
 [5] ntuple at .\ntuple.jl:41 [inlined]
 [6] copy at .\broadcast.jl:1023 [inlined]
 [7] materialize at .\broadcast.jl:819 [inlined]
 [8] DenseAxisArray at C:\Users\yaramasv\.juliapro\JuliaPro_v1.3.1-1\packages\JuMP\MsUSY\src\Containers\DenseAxisArray.jl:54 [inlined]
 [9] construct_undef_array at C:\Users\yaramasv\.juliapro\JuliaPro_v1.3.1-1\packages\JuMP\MsUSY\src\Containers\DenseAxisArray.jl:96 [inlined]
 [10] JuMP.Containers.DenseAxisArray{VariableRef,N,Ax,L} where L<:Tuple{Vararg{Dict,N}} where Ax where N(::UndefInitializer, ::Array{Float64,1}) at C:\Users\yaramasv\.juliapro\JuliaPro_v1.3.1-1\packages\JuMP\MsUSY\src\Containers\DenseAxisArray.jl:91
 [11] top-level scope at C:\Users\yaramasv\.juliapro\JuliaPro_v1.3.1-1\packages\JuMP\MsUSY\src\macros.jl:189
in expression starting at C:\Users\yaramasv\OneDrive - The University of Colorado Denver\Conference paper\Report\julia\powerflow34.jl:149te code here

And I don’t want to use unique function also because I want all the elements from first column.

Thank you