Skip to content

Commit

Permalink
Bug Fix: Capactiy Reserve Margin
Browse files Browse the repository at this point in the history
Update some loose end so that the CRM works.
  • Loading branch information
xuqingyu committed Nov 17, 2023
1 parent c536d00 commit 5db902e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 29 deletions.
1 change: 0 additions & 1 deletion src/model/core/transmission.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ function transmission!(EP::Model, inputs::Dict, setup::Dict)

UCommit = setup["UCommit"]
NetworkExpansion = setup["NetworkExpansion"]
CapacityReserveMargin = setup["CapacityReserveMargin"]
MultiStage = setup["MultiStage"]

## sets and indices for transmission losses and expansion
Expand Down
32 changes: 10 additions & 22 deletions src/model/policies/cap_reserve_margin.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@ function cap_reserve_margin!(EP::Model, inputs::Dict, setup::Dict)
SEG = inputs["SEG"]
Z = inputs["Z"]
L = inputs["L"]
OperationWrapping = setup["OperationWrapping"]
START_SUBPERIODS = inputs["START_SUBPERIODS"]
INTERIOR_SUBPERIODS = inputs["INTERIOR_SUBPERIODS"]
hours_per_subperiod = inputs["hours_per_subperiod"] #total number of hours per subperiod
p = inputs["hours_per_subperiod"] #total number of hours per subperiod

println("Capacity Reserve Margin Policies Module")
@expression(EP, eCapResMarBalance[res=1:NCRM, t=1:T], 1*EP[:vZERO])
Expand Down Expand Up @@ -95,8 +94,8 @@ function cap_reserve_margin!(EP::Model, inputs::Dict, setup::Dict)

if Z > 1
@expression(EP, eCapContributionTransAll[res=1:NCRM, t = 1:T],
sum(inputs["dfCapRes_network"][l, Symbol("DerateCapRes_$res")] *
inputs["dfCapRes_network"][l, Symbol("CapRes_Excl_$res")] *
sum(inputs["dfDerateTransCapRes"][l, res] *
inputs["dfTransCapRes_excl"][l, res] *
vCapContributionTrans[l, t] for l in 1:L)
)
add_to_expression!.(EP[:eCapResMarBalance], EP[:eCapContributionTransAll])
Expand Down Expand Up @@ -131,21 +130,10 @@ function cap_reserve_margin!(EP::Model, inputs::Dict, setup::Dict)
if !isempty(STOR_ALL)
@constraint(EP, cCapContriSTORCap[y in STOR_ALL, t = 1:T],
EP[:vCapContribution][y, t] <= (EP[:eTotalCap][y]))
if OperationWrapping ==1
@constraint(EP, cCapContriSTORSoC_Start[y in STOR_ALL, t in START_SUBPERIODS],
EP[:vCapContribution][y, t] <= (EP[:vS][y, t + hours_per_subperiod - 1] *
dfGen[y, :Eff_Down]/ dfGen[y, :CapRes_duration_requirement])
)
@constraint(EP, cCapContriSTORSoC_Interior[y in STOR_ALL, t in INTERIOR_SUBPERIODS],
EP[:vCapContribution][y, t] <= (EP[:vS][y, t - 1]*
dfGen[y, :Eff_Down]/ dfGen[y, :CapRes_duration_requirement])
)
else
@constraint(EP, cCapContriSTORSoC[y in STOR_ALL, t = 2:T],
EP[:vCapContribution][y, t] <= (EP[:vS][y, t-1]*
dfGen[y, :Eff_Down]/ dfGen[y, :CapRes_duration_requirement])
)
end

@constraint(EP, cCapContriSTORSoC[y in STOR_ALL, t = 1:T],
EP[:vCapContribution][y, t] <= (EP[:vS][y, hoursbefore(p,t,1)]*
dfGen[y, :Eff_Down]/ dfGen[y, :CapRes_duration_requirement]))
end

# Flexible demand
Expand All @@ -159,7 +147,7 @@ function cap_reserve_margin!(EP::Model, inputs::Dict, setup::Dict)
if SEG >= 2
@expression(EP, eCapResMarBalanceNSE[res=1:NCRM, t=1:T],
sum(EP[:eDemandResponse][t, z]
for z in findall(x -> x != 0, inputs["dfCapRes"][:, Symbol("CapRes_$res")])))
for z in findall(x -> x != 0, inputs["dfCapRes"][:, res])))
add_to_expression!.(EP[:eCapResMarBalance], EP[:eCapResMarBalanceNSE])
end

Expand All @@ -171,7 +159,7 @@ function cap_reserve_margin!(EP::Model, inputs::Dict, setup::Dict)
end

@constraint(EP, cCapacityResMargin[res=1:NCRM, t=1:T], EP[:eCapResMarBalance][res, t]
>= sum(inputs["pD"][t,z] * (1 + inputs["dfCapRes"][z,Symbol("CapRes_$res")])
for z=findall(x -> x != 0,inputs["dfCapRes"][:,Symbol("CapRes_$res")])))
>= sum(inputs["pD"][t,z] * (1 + inputs["dfCapRes"][z,res])
for z=findall(x -> x != 0,inputs["dfCapRes"][:,res])))

end
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ function write_reserve_margin_demand_response_saving(path::AbstractString, input
dfResDRSaving = DataFrame(Zone = 1:Z, AnnualSum = zeros(Z))
for i in 1:inputs["NCapacityReserveMargin"]
pariticpatingzone = zeros(Z)
pariticpatingzone[findall(x -> x != 0, inputs["dfCapRes"][:, Symbol("CapRes_$i")])] .= 1
pariticpatingzone[findall(x -> x != 0, inputs["dfCapRes"][:, i])] .= 1
resdrsaving = (transpose(value.(EP[:eDemandResponse])) .* pariticpatingzone) * dual.(EP[:cCapacityResMargin][i, :])
if setup["ParameterScale"] == 1
resdrsaving *= ModelScalingFactor^2
end
dfResDRSaving.AnnualSum .+= resdrsaving
dfResDRSaving = hcat(dfResDRSaving, DataFrame([resdrsaving], [Symbol("CapRes_$i")]))
dfResDRSaving = hcat(dfResDRSaving, DataFrame([resdrsaving], i))
end
CSV.write(joinpath(path, "ReserveMarginDemandResponseSaving.csv"), dfResDRSaving)
return dfResDRSaving
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ function write_reserve_margin_payment(path::AbstractString, inputs::Dict, setup:
Z = inputs["Z"] # Number of zonests
dfResPayment = DataFrame(Zone = 1:Z, AnnualSum = zeros(Z))
for i in 1:inputs["NCapacityReserveMargin"]
oneplusreservemargin = (inputs["dfCapRes"][:, Symbol("CapRes_$i")] .+ 1)
oneplusreservemargin[findall(x -> x == 0, inputs["dfCapRes"][:, Symbol("CapRes_$i")])] .= 0
oneplusreservemargin = (inputs["dfCapRes"][:, i] .+ 1)
oneplusreservemargin[findall(x -> x == 0, inputs["dfCapRes"][:, i])] .= 0
reservemarginpayment = (transpose(inputs["pD"]) .* oneplusreservemargin) * dual.(EP[:cCapacityResMargin][i, :])
if setup["ParameterScale"] == 1
reservemarginpayment *= (ModelScalingFactor^2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ function write_reserve_margin_transmission_revenue(path::AbstractString, inputs:
dfResTransRevenue = DataFrame(Line = 1:L, AnnualSum = zeros(L))
for i in 1:inputs["NCapacityReserveMargin"]
restransrevenue = (value.(EP[:vCapContributionTrans]) .*
inputs["dfCapRes_network"][:, Symbol("DerateCapRes_$i")] .*
inputs["dfCapRes_network"][:, Symbol("CapRes_Excl_$i")]) *
inputs["dfDerateTransCapRes"][:, i] .*
inputs["dfTransCapRes_excl"][:, i]) *
dual.(EP[:cCapacityResMargin][i, :])
if setup["ParameterScale"] == 1
restransrevenue *= (ModelScalingFactor^2)
Expand Down

0 comments on commit 5db902e

Please sign in to comment.