-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create write_operating_reserve_price_revenue.jl #611
Changes from 12 commits
b01c606
012959f
87fe00c
962f18f
e89b0bf
6c9dfdd
6ec3a46
435bbe0
df459bc
7c12325
848b192
1ffe28a
ee76261
f522df7
bae5fee
3ac2cce
63e4ed8
36c439b
c0644e5
c5d0371
34adab3
d777c1b
2fbd18f
5c3cca5
a334250
475aa47
3b35243
1f4a7f6
d763f73
99af8ba
3cee2c0
6503a17
4469420
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
@doc raw""" | ||
write_operating_reserve_price_revenue(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) | ||
|
||
Function for reporting the operating reserve prices and revenue earned by generators listed in the input file. | ||
GenX will print this file only when operating reserve is modeled and the shadow price can be obtained form the solver. | ||
The revenue is calculated as the operating reserve contribution of each time steps multiplied by the shadow price, and then the sum is taken over all modeled time steps. | ||
The last column is the total revenue received from all operating reserve constraints. | ||
As a reminder, GenX models the operating reserve at the time-dependent level, and each constraint either stands for an overall market or a locality constraint. | ||
""" | ||
function write_operating_reserve_revenue(path::AbstractString, inputs::Dict, setup::Dict, EP::Model) | ||
scale_factor = setup["ParameterScale"] == 1 ? ModelScalingFactor : 1 | ||
dfGen = inputs["dfGen"] | ||
RSV = inputs["RSV"] | ||
REG = inputs["REG"] | ||
|
||
dfOpRsvRevenue = DataFrame(Region = dfGen[RSV, :region], Resource = dfGen[RSV, :Resource], Zone = dfGen[RSV, :Zone], Cluster = dfGen[RSV, :cluster], AnnualSum = Array{Float64}(undef, length(RSV)),) | ||
dfOpRegRevenue = DataFrame(Region = dfGen[REG, :region], Resource = dfGen[REG, :Resource], Zone = dfGen[REG, :Zone], Cluster = dfGen[REG, :cluster], AnnualSum = Array{Float64}(undef, length(REG)),) | ||
|
||
weighted_reg_price = operating_regulation_price(EP, inputs, setup) | ||
weighted_rsv_price = operating_reserve_price(EP, inputs, setup) | ||
|
||
rsvrevenue = value.(EP[:vRSV][RSV, :].data).* transpose(weighted_rsv_price) | ||
regrevenue = value.(EP[:vREG][REG, :].data) .* transpose(weighted_reg_price) | ||
|
||
if setup["ParameterScale"] == 1 | ||
rsvrevenue *= scale_factor | ||
regrevenue *= scale_factor | ||
end | ||
|
||
dfOpRsvRevenue.AnnualSum .= rsvrevenue * inputs["omega"] | ||
dfOpRegRevenue.AnnualSum .= regrevenue * inputs["omega"] | ||
write_simple_csv(joinpath(path, "OperatingReserveRevenue.csv"), dfOpRsvRevenue) | ||
write_simple_csv(joinpath(path, "OperatingRegulationRevenue.csv"), dfOpRegRevenue) | ||
return dfOpRegRevenue, dfOpRsvRevenue | ||
end | ||
|
||
@doc raw""" | ||
operating_regulation_price(EP::Model, | ||
inputs::Dict, | ||
setup::Dict)::Vector{Float64} | ||
|
||
Operating regulation price for each time step. | ||
This is equal to the dual variable of the regulatin requirement constraint. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo: "can be obtained form the solver." -> "can be obtained from the solver." There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo: "of each time steps" --> "in each time step" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @cfe316 . Addressed these. |
||
|
||
Returns a vector, with units of $/MW | ||
""" | ||
|
||
function operating_regulation_price(EP::Model, inputs::Dict, setup::Dict)::Vector{Float64} | ||
ω = inputs["omega"] | ||
scale_factor = setup["ParameterScale"] == 1 ? ModelScalingFactor : 1 | ||
return dual.(EP[:cReg]) ./ ω * scale_factor | ||
end | ||
|
||
@doc raw""" | ||
operating_reserve_price(EP::Model, | ||
inputs::Dict, | ||
setup::Dict)::Vector{Float64} | ||
|
||
Operating reserve price for each time step. | ||
This is equal to the dual variable of the reserve requirement constraint. | ||
|
||
Returns a vector, with units of $/MW | ||
""" | ||
|
||
function operating_reserve_price(EP::Model, inputs::Dict, setup::Dict)::Vector{Float64} | ||
ω = inputs["omega"] | ||
scale_factor = setup["ParameterScale"] == 1 ? ModelScalingFactor : 1 | ||
return dual.(EP[:cRsvReq]) ./ ω * scale_factor | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
@doc raw""" | ||
write_net_revenue(path::AbstractString, inputs::Dict, setup::Dict, EP::Model, dfCap::DataFrame, dfESRRev::DataFrame, dfResRevenue::DataFrame, dfChargingcost::DataFrame, dfPower::DataFrame, dfEnergyRevenue::DataFrame, dfSubRevenue::DataFrame, dfRegSubRevenue::DataFrame, dfVreStor::DataFrame) | ||
write_net_revenue(path::AbstractString, inputs::Dict, setup::Dict, EP::Model, dfCap::DataFrame, dfESRRev::DataFrame, dfResRevenue::DataFrame, dfChargingcost::DataFrame, dfPower::DataFrame, dfEnergyRevenue::DataFrame, dfSubRevenue::DataFrame, dfRegSubRevenue::DataFrame, dfVreStor::DataFrame, dfOpRegRevenue::DataFrame, dfOpRsvRevenue::DataFrame) | ||
|
||
Function for writing net revenue of different generation technologies. | ||
""" | ||
function write_net_revenue(path::AbstractString, inputs::Dict, setup::Dict, EP::Model, dfCap::DataFrame, dfESRRev::DataFrame, dfResRevenue::DataFrame, dfChargingcost::DataFrame, dfPower::DataFrame, dfEnergyRevenue::DataFrame, dfSubRevenue::DataFrame, dfRegSubRevenue::DataFrame, dfVreStor::DataFrame) | ||
function write_net_revenue(path::AbstractString, inputs::Dict, setup::Dict, EP::Model, dfCap::DataFrame, dfESRRev::DataFrame, dfResRevenue::DataFrame, dfChargingcost::DataFrame, dfPower::DataFrame, dfEnergyRevenue::DataFrame, dfSubRevenue::DataFrame, dfRegSubRevenue::DataFrame, dfVreStor::DataFrame, dfOpRegRevenue::DataFrame, dfOpRsvRevenue::DataFrame) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a comment. We should really have an "outputs" dictionary so that we don't have this huge list of dataframes. |
||
dfGen = inputs["dfGen"] | ||
T = inputs["T"] # Number of time steps (hours) | ||
Z = inputs["Z"] # Number of zones | ||
G = inputs["G"] # Number of generators | ||
G = inputs["G"] | ||
RSV = inputs["RSV"] | ||
REG = inputs["REG"] # Number of generators | ||
COMMIT = inputs["COMMIT"] # Thermal units for unit commitment | ||
STOR_ALL = inputs["STOR_ALL"] | ||
VRE_STOR = inputs["VRE_STOR"] | ||
|
@@ -129,6 +131,14 @@ function write_net_revenue(path::AbstractString, inputs::Dict, setup::Dict, EP:: | |
dfNetRevenue.SubsidyRevenue = dfSubRevenue[1:G,:SubsidyRevenue] # Unit is confirmed to be US$ | ||
end | ||
|
||
# Add energy and subsidy revenue to the dataframe | ||
dfNetRevenue.OperatingReserveRevenue = zeros(nrow(dfNetRevenue)) | ||
dfNetRevenue.OperatingRegulationRevenue = zeros(nrow(dfNetRevenue)) | ||
if setup["Reserves"] > 0 && has_duals(EP) == 1 | ||
dfNetRevenue.OperatingReserveRevenue[RSV] = dfOpRsvRevenue.AnnualSum # Unit is confirmed to be US$ | ||
dfNetRevenue.OperatingRegulationRevenue[REG] = dfOpRegRevenue.AnnualSum # Unit is confirmed to be US$ | ||
end | ||
|
||
# Add capacity revenue to the dataframe | ||
dfNetRevenue.ReserveMarginRevenue = zeros(nrow(dfNetRevenue)) | ||
if setup["CapacityReserveMargin"] > 0 && has_duals(EP) == 1 # The unit is confirmed to be $ | ||
|
@@ -170,7 +180,7 @@ function write_net_revenue(path::AbstractString, inputs::Dict, setup::Dict, EP:: | |
dfNetRevenue.RegSubsidyRevenue = dfRegSubRevenue[1:G,:SubsidyRevenue] | ||
end | ||
|
||
dfNetRevenue.Revenue = dfNetRevenue.EnergyRevenue .+ dfNetRevenue.SubsidyRevenue .+ dfNetRevenue.ReserveMarginRevenue .+ dfNetRevenue.ESRRevenue .+ dfNetRevenue.RegSubsidyRevenue | ||
dfNetRevenue.Revenue = dfNetRevenue.EnergyRevenue .+ dfNetRevenue.SubsidyRevenue .+ dfNetRevenue.ReserveMarginRevenue .+ dfNetRevenue.ESRRevenue .+ dfNetRevenue.RegSubsidyRevenue .+ dfNetRevenue.OperatingReserveRevenue .+ dfNetRevenue.OperatingRegulationRevenue | ||
dfNetRevenue.Cost = (dfNetRevenue.Inv_cost_MW | ||
.+ dfNetRevenue.Inv_cost_MWh | ||
.+ dfNetRevenue.Inv_cost_charge_MW | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -179,6 +179,14 @@ function write_outputs(EP::Model, path::AbstractString, setup::Dict, inputs::Dic | |
dfResMar_slack = write_reserve_margin_slack(path, inputs, setup, EP) | ||
end | ||
end | ||
|
||
if setup["Reserves"]==1 && has_duals(EP) == 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I realize this code is duplicated from elsewhere in the file, but There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @cfe316 . Addressed these in all the instances |
||
dfOpRegRevenue, dfOpRsvRevenue = write_operating_reserve_revenue(path, inputs, setup, EP) | ||
elapsed_time_op_res_rev = @elapsed write_operating_reserve_revenue(path, inputs, setup, EP) | ||
println("Time elapsed for writing oerating reserve price is") | ||
println(elapsed_time_op_res_rev) | ||
end | ||
|
||
if setup["CO2Cap"]>0 && has_duals(EP) == 1 | ||
dfCO2Cap = write_co2_cap(path, inputs, setup, EP) | ||
end | ||
|
@@ -198,7 +206,7 @@ function write_outputs(EP::Model, path::AbstractString, setup::Dict, inputs::Dic | |
end | ||
|
||
|
||
elapsed_time_net_rev = @elapsed write_net_revenue(path, inputs, setup, EP, dfCap, dfESRRev, dfResRevenue, dfChargingcost, dfPower, dfEnergyRevenue, dfSubRevenue, dfRegSubRevenue, dfVreStor) | ||
elapsed_time_net_rev = @elapsed write_net_revenue(path, inputs, setup, EP, dfCap, dfESRRev, dfResRevenue, dfChargingcost, dfPower, dfEnergyRevenue, dfSubRevenue, dfRegSubRevenue, dfVreStor, dfOpRegRevenue, dfOpRsvRevenue) | ||
println("Time elapsed for writing net revenue is") | ||
println(elapsed_time_net_rev) | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't need to be wrapped with the
if
statement sincescale_factor
is always defined.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @cfe316 . Addressed this.