Skip to content

Commit

Permalink
Change code and input data to have the flows with names instead of id
Browse files Browse the repository at this point in the history
  • Loading branch information
datejada committed Oct 20, 2023
1 parent e518531 commit ab7d1f1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/input_tables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ end
struct FlowData
id::Int # Flow ID
carrier::String # (Optional?) Energy carrier
from_asset_id::Int # Asset ID
to_asset_id::Int # Asset ID
from_asset::String # Name of Asset
to_asset::String # Name of Asset
active::Bool # Active or decomissioned
investable::Bool # Whether able to invest
variable_cost::Float64 # kEUR/MWh
Expand Down
24 changes: 14 additions & 10 deletions src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function create_parameters_and_sets_from_file(input_folder::AbstractString)
) # asset profile [p.u.]

# Parameter for profile of flow
flows = [(row.from_asset_id, row.to_asset_id) for row in eachrow(flows_data_df)]
flows = [(row.from_asset, row.to_asset) for row in eachrow(flows_data_df)]
flows_profile = Dict(
(flows[row.id], row.rep_period_id, row.time_step) => row.value for
row in eachrow(flows_profiles_df)
Expand Down Expand Up @@ -61,15 +61,15 @@ function create_parameters_and_sets_from_file(input_folder::AbstractString)
end

# Read from flows data
flows_investment_cost = Dict{UInt,Float64}()
flows_unit_capacity = Dict{UInt,Float64}()
flows_init_capacity = Dict{UInt,Float64}()
flows_investable = Dict{UInt,Bool}()
flows_investment_cost = Dict{Tuple{String, String}, Float64}()
flows_unit_capacity = Dict{Tuple{String, String}, Float64}()
flows_init_capacity = Dict{Tuple{String, String}, Float64}()
flows_investable = Dict{Tuple{String, String}, Bool}()
for row in eachrow(flows_data_df)
flows_investment_cost[(row.from_asset_id, row.to_asset_id)] = row.investment_cost
flows_unit_capacity[(row.from_asset_id, row.to_asset_id)] = row.capacity
flows_init_capacity[(row.from_asset_id, row.to_asset_id)] = row.initial_capacity
flows_investable[(row.from_asset_id, row.to_asset_id)] = row.investable
flows_investment_cost[(row.from_asset, row.to_asset)] = row.investment_cost
flows_unit_capacity[(row.from_asset, row.to_asset)] = row.capacity
flows_init_capacity[(row.from_asset, row.to_asset)] = row.initial_capacity
flows_investable[(row.from_asset, row.to_asset)] = row.investable
end

params = (
Expand All @@ -82,6 +82,7 @@ function create_parameters_and_sets_from_file(input_folder::AbstractString)
flows_investment_cost = flows_investment_cost,
flows_profile = flows_profile,
flows_unit_capacity = flows_unit_capacity,
flows_investable = flows_investable,
peak_demand = peak_demand,
rep_weight = rep_weight,
variable_cost = variable_cost,
Expand Down Expand Up @@ -146,10 +147,13 @@ function create_graph(assets_path, flows_path)
flows_df = CSV.read(flows_path, DataFrames.DataFrame; header = 2)

num_assets = DataFrames.nrow(assets_df)
name_to_id = Dict(zip(assets_df.name, assets_df.id))

graph = Graphs.DiGraph(num_assets)
for row in eachrow(flows_df)
Graphs.add_edge!(graph, row.from_asset_id, row.to_asset_id)
from_id = name_to_id[row.from_asset]
to_id = name_to_id[row.to_asset]
Graphs.add_edge!(graph, from_id, to_id)
end

return graph
Expand Down
14 changes: 7 additions & 7 deletions test/inputs/tiny/flows-data.csv
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
,,asset_id,asset_id,{true;false},{true;false},kEUR/MWh,kEUR/MW/year,MW,MW,p.u.
id,carrier,from_asset_id,to_asset_id,active,investable,variable_cost,investment_cost,capacity,initial_capacity,efficiency
1,electricity,1,6,true,,,,,,0
2,electricity,2,6,true,,,,,,0
3,electricity,3,6,true,,,,,,0
4,electricity,4,6,true,,,,,,0
5,electricity,5,6,true,,,,,,0
,,asset_name,asset_name,{true;false},{true;false},kEUR/MWh,kEUR/MW/year,MW,MW,p.u.
id,carrier,from_asset,to_asset,active,investable,variable_cost,investment_cost,capacity,initial_capacity,efficiency
1,electricity,ocgt,demand,true,false,0,0,0,0,0
2,electricity,ccgt,demand,true,false,0,0,0,0,0
3,electricity,wind,demand,true,false,0,0,0,0,0
4,electricity,solar,demand,true,false,0,0,0,0,0
5,electricity,ens,demand,true,false,0,0,0,0,0

0 comments on commit ab7d1f1

Please sign in to comment.