Skip to content

Commit

Permalink
Add operation weights (#817)
Browse files Browse the repository at this point in the history
* Add weights

* Add comments

* Update src/create-model.jl

Co-authored-by: Abel Soares Siqueira <[email protected]>

* Make sure years are ordered

* Another way to read in data

---------

Co-authored-by: Abel Soares Siqueira <[email protected]>
  • Loading branch information
gnawin and abelsiqueira authored Sep 23, 2024
1 parent 327bc1d commit 21057f9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
36 changes: 36 additions & 0 deletions src/create-model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,25 @@ function profile_aggregation(agg, profiles, year, commission_year, key, block, d
end
end

"""
create_intervals(years)
Create a dictionary of intervals for `years`. The interval is assigned to the its starting year.
The last interval is 1.
"""
function create_intervals_for_years(years)
intervals = Dict()

# This assumes that `years` is ordered
for i in 1:length(years)-1
intervals[years[i]] = years[i+1] - years[i]
end

intervals[years[end]] = 1

return intervals
end

"""
create_model!(energy_problem; verbose = false)
Expand Down Expand Up @@ -1141,9 +1160,25 @@ function create_model(
)
)

# Create a dict of intervals for milestone years
intervals_for_milestone_years = create_intervals_for_years(Y)

# Create a dict of operation discounts only for milestone years
operation_discounts_for_milestone_years = Dict(
y => 1 / (1 + model_parameters.discount_rate)^(y - model_parameters.discount_year)
for y in Y
)

# Create a dict of operation discounts for milestone years including in-between years
weight_for_operation_discounts = Dict(
y => operation_discounts_for_milestone_years[y] * intervals_for_milestone_years[y]
for y in Y
)

flows_variable_cost = @expression(
model,
sum(
weight_for_operation_discounts[row.year] *
representative_periods[row.year][row.rep_period].weight *
duration(row.timesteps_block, row.rep_period, representative_periods[row.year]) *
graph[row.from, row.to].variable_cost[row.year] *
Expand All @@ -1154,6 +1189,7 @@ function create_model(
units_on_cost = @expression(
model,
sum(
weight_for_operation_discounts[row.year] *
representative_periods[row.year][row.rep_period].weight *
duration(row.timesteps_block, row.rep_period, representative_periods[row.year]) *
graph[row.asset].units_on_cost[row.year] *
Expand Down
10 changes: 8 additions & 2 deletions src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@ function create_internal_structures(connection)
_check_if_table_exist(connection, table)
end

# Get the years struct ordered by year
years = [
Year(row.year, row.length, row.is_milestone) for
row in TulipaIO.get_table(Val(:raw), connection, "year_data")
Year(row.year, row.length, row.is_milestone) for row in DBInterface.execute(
connection,
"SELECT *
FROM year_data
ORDER BY year",
)
]

milestone_years = [year.id for year in years]

# Calculate the weights from the "rep_periods_mapping" table in the connection
Expand Down

0 comments on commit 21057f9

Please sign in to comment.