Key 2 not found error

Hello,

What does this error mean? “Key 2 not found”

Nodes_set=[1,2,3]
Gen_set=[1,3]
Pd=[0,-4,0]
JuMP.@variable(m, 0.1 ≤ p[i in Gen_set] ≤ 2)
JuMP.@variable(m, pij[i = Nodes_set, j = Nodes_set])
JuMP.@constraint(m, Pnodal[i in Nodes_set], sum(pij[i,j] for j = Nodes_set) == p[i]+Pd[i] )

Using your variable definitions:


julia> p
1-dimensional DenseAxisArray{VariableRef,1,...} with index sets:
    Dimension 1, [1, 3]
And data, a 2-element Array{VariableRef,1}:
 p[1]
 p[3]

julia> Pd
3-element Array{Int64,1}:
  0
 -4
  0

julia> pij
2-dimensional DenseAxisArray{VariableRef,2,...} with index sets:
    Dimension 1, [1, 2, 3]
    Dimension 2, [1, 2, 3]
And data, a 3×3 Array{VariableRef,2}:
 pij[1,1]  pij[1,2]  pij[1,3]
 pij[2,1]  pij[2,2]  pij[2,3]
 pij[3,1]  pij[3,2]  pij[3,3]

Note that p doesn’t have index “2” because it is defined with Gen_set. When you use i to index it (along with pij and Pd) it fails when the index is 2.

3 Likes

Thank you