Thanks for the response @odow.
Since, I’m unable to upload the csv files here, I have made the simplified data available on my github page: https://github.com/m-bah/test
A slightly more expanded version of my coding exercise;
using JuMP, Clp, DataFrames, CSV
using Base: Symbol
function df_to_dict_with_id(df::DataFrame)
Dict(col[1] => Dict(zip(df[!, 1], col[2])) for col in pairs(eachcol(df)))
end
#Read in data
data_dir = pwd()*"/test/"
data = Dict{Symbol,Any}()
set = Dict{Symbol,Any}()
readDataDFs = Dict()
inputDataItems = ["plants", "demand", "nodes","lines"]
for inputDataItem in inputDataItems #loop starts~ for each data file inputDataItems
readDataDFs[Symbol(inputDataItem)] = DataFrame(CSV.File(data_dir * inputDataItem * ".csv"), copycols=true) #read in all the CSV files into the dictionary readDataDFs
data[Symbol(inputDataItem)] = df_to_dict_with_id(readDataDFs[Symbol(inputDataItem)])
set[Symbol(inputDataItem)] = readDataDFs[Symbol(inputDataItem)].index
end
P = set[:plants] #index of all plants
C = filter(r -> any(occursin.(["conventional"], r.plant_type)), readDataDFs[:plants]).index #index of conventional plants
N = set[:nodes] #Index of nodes
T = set[:demand] #Time stamp
L = set[:lines] #Index of power lines
basic_model = Model(Clp.Optimizer)
#Define variables
@variable(basic_model, GEN[T, C] >=0) #Conventional plant generation
@variable(basic_model, FLOW[T, L] ) #power flow
@objective(basic_model,
Min,
sum(sum(GEN[t, p]*data[:plants][:cost][p] for p in C) for t in T))
@constraint(basic_model,
CapConstraint[t in T, c in C],
GEN[t,c] <= data[:plants][:g_max][c] ) # Capacity constraint
.... #steps skipped
## issue starts here
flow1 = sum(1/3*GEN[1:3,"basel"] - 1/3*GEN[1:3,"bern"])
flow2 = sum(2/3*GEN[1:3,"basel"] + 1/3*GEN[1:3,"bern"])
flow3 = sum(1/3*GEN[1:3,"basel"] + 2/3*GEN[1:3,"bern"])
@constraint(basic_model,
LineFlowA[t in T, l in L],
FLOW[t,l] == flow1 )
@constraint(basic_model,
LineFlowB[t in T, l in L],
FLOW[t,l] == flow2 )
@constraint(basic_model,
LineFlowC[t in T, l in L],
FLOW[t,l] == flow3 )
@constraint(basic_model,
FlowMax_Pos[t in T, l in L],
FLOW[t,l] <= data[:lines][:f_max][l]
) #positve line flow constraint
@constraint(basic_model,
FlowMax_Neg[t in T, l in L],
FLOW[t,l] >= -data[:lines][:f_max][l]
) #negative line flow constraint
When I try to compute flow1 for instance, i get the following error message.
julia> flow1 = sum(1/3*GEN[1:3,"basel"] - 1/3*GEN[1:3,"bern"])
ERROR: MethodError: no method matching promote_shape(::Tuple{Vector{Int64}}, ::Tuple{Vector{Int64}})
Stacktrace:
[1] promote_shape(a::JuMP.Containers.DenseAxisArray{AffExpr, 1, Tuple{Vector{Int64}}, Tuple{JuMP.Containers._AxisLookup{Dict{Int64, Int64}}}}, b::JuMP.Containers.DenseAxisArray{AffExpr, 1, Tuple{Vector{Int64}}, Tuple{JuMP.Containers._AxisLookup{Dict{Int64, Int64}}}})
@ Base .\indices.jl:169
[2] -(A::JuMP.Containers.DenseAxisArray{AffExpr, 1, Tuple{Vector{Int64}}, Tuple{JuMP.Containers._AxisLookup{Dict{Int64, Int64}}}}, B::JuMP.Containers.DenseAxisArray{AffExpr, 1, Tuple{Vector{Int64}}, Tuple{JuMP.Containers._AxisLookup{Dict{Int64, Int64}}}})
@ Base .\arraymath.jl:38
[3] top-level scope
@ REPL[26]:1
In short, my main aim is to manually code up equality constraints for individual line flows (i.e. LineFlowA - LineFlowC).
Apologies for the long and messy response
Thanks