Hello,
I am trying to fit in a DC load flow equation into my zonal dispatch model without much success.
#using DataFrames, JuMp
generators = DataFrame(index = ["conventional_gas", "conventional_nuc", "West_A_Wind", "Central_C_Wind", "North_D_Wind",
"West_A_ROR", "Central_C_ROR", "North_D_ROR"], R_ID = 1:8, node_id = [1,2,1,2,3,1,2,3],
g_max = [100,250,40,60,80,30,100,60], cost = [20,8,0,0,0,0,0,0], conventional = [1,1,0,0,0,0,0,0], WIND = [0,0,1,1,1,0,0,0],
ROR = [0,0,0,0,0,1,1,1])
network = DataFrame(network_zones = ["z1","z2","z3","z4"], network_lines = 1:4, z1 = [1,0,0,1],
z2 = [-1,1,1,0], z3 = [0,-1,0,0], z4 = [0,0,-1,-1], reactance_unit = [1,1,1,1])
lines = select(network[1:4,:],
:network_lines, :z1, :z2, :z3)
incidence = [1 -1 0 0; 0 1 -1 0; 0 1 0 -1; 1 0 0 -1]
#Sets
L = lines.network_lines
T = convert(Array{Int64}, 1:4)
Z = convert(Array{Int64}, 1:4)
#Dispatch_Model = Model(Clp.Optimizer)
#@variable(Dispatch_Model, vFLOW[T,L])
#@variable(Dispatch_Model, vVoltage[T,Z])
@constraint(Dispatch_Model,
DC_LineFlow[t in T, l in L],
vFLOW[t,l] == sum(incidence[z][l] * vVoltage[t,z]/network.reactance_unit[l] for z in Z))
#Error message when running the DC_LineFlow constraint
ERROR: BoundsError
Stacktrace:
[1] getindex(x::Int64, i::Int64)
@ Base .\number.jl:96
[2] macro expansion
@ C:\Users\mbahe\.julia\packages\MutableArithmetics\0Y9ZS\src\rewrite.jl:279 [inlined]
[3] macro expansion
@ C:\Users\mbahe\.julia\packages\JuMP\klrjG\src\macros.jl:676 [inlined]
[4] (::var"#17#18")(t::Int64, l::Int64)
@ Main C:\Users\mbahe\.julia\packages\JuMP\klrjG\src\Containers\macro.jl:194
[5] #38
@ C:\Users\mbahe\.julia\packages\JuMP\klrjG\src\Containers\container.jl:105 [inlined]
[6] iterate
@ .\generator.jl:47 [inlined]
[7] collect_to!(dest::Matrix{ConstraintRef{Model, MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64}, MathOptInterface.EqualTo{Float64}}, ScalarShape}}, itr::Base.Generator{JuMP.Containers.VectorizedProductIterator{Tuple{Vector{Int64}, Vector{Int64}}}, JuMP.Containers.var"#38#39"{var"#17#18"}}, offs::Int64, st::Tuple{Tuple{Int64, Int64}, Tuple{Int64, Int64}})
@ Base .\array.jl:724
[8] collect_to_with_first!(dest::Matrix{ConstraintRef{Model, MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64}, MathOptInterface.EqualTo{Float64}}, ScalarShape}}, v1::ConstraintRef{Model, MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64}, MathOptInterface.EqualTo{Float64}}, ScalarShape}, itr::Base.Generator{JuMP.Containers.VectorizedProductIterator{Tuple{Vector{Int64}, Vector{Int64}}}, JuMP.Containers.var"#38#39"{var"#17#18"}}, st::Tuple{Tuple{Int64, Int64}, Tuple{Int64, Int64}})
@ Base .\array.jl:702
[9] collect(itr::Base.Generator{JuMP.Containers.VectorizedProductIterator{Tuple{Vector{Int64}, Vector{Int64}}}, JuMP.Containers.var"#38#39"{var"#17#18"}})
@ Base .\array.jl:683
[10] map(f::Function, A::JuMP.Containers.VectorizedProductIterator{Tuple{Vector{Int64}, Vector{Int64}}})
@ Base .\abstractarray.jl:2323
[11] container(f::Function, indices::JuMP.Containers.VectorizedProductIterator{Tuple{Vector{Int64}, Vector{Int64}}}, #unused#::Type{JuMP.Containers.DenseAxisArray})
@ JuMP.Containers C:\Users\mbahe\.julia\packages\JuMP\klrjG\src\Containers\container.jl:105
[12] container(f::Function, indices::JuMP.Containers.VectorizedProductIterator{Tuple{Vector{Int64}, Vector{Int64}}})
@ JuMP.Containers C:\Users\mbahe\.julia\packages\JuMP\klrjG\src\Containers\container.jl:66
[13] macro expansion
@ C:\Users\mbahe\.julia\packages\JuMP\klrjG\src\macros.jl:142 [inlined]
[14] top-level scope
@ c:\Users\mbahe\Desktop\JuliaDiscourse\dc_load_flow_question.jl:30
I have two main problems here. First is constraining the flow over the lines (vFLOW) to the basic equation. Secondly, how do i use the incidence matrix that is in the network dataframe instead of manually hardcoding it…
Any thoughts or suggestions is much appreciated. Thanks