Skip to content

Commit

Permalink
fixed an issue with the retrofit constraints and efficiency
Browse files Browse the repository at this point in the history
  • Loading branch information
filippopecci committed Mar 11, 2024
1 parent 10505d4 commit b7ff1b4
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 28 deletions.
10 changes: 5 additions & 5 deletions Example_Systems/RetrofitExample/OneZone/Resources/Thermal.csv
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ coal_super_2,1,1,2,0,1,0,1,0,6000,0,0,112000,10287,0,7.43,coal,300,17,2,4,4,0.64
coal_super_3,1,1,3,0,1,0,1,0,6000,0,0,112000,10287,0,7.43,coal,300,17,2,4,4,0.64,0.64,0.55,0.25,0.25,0,0,1,Coal_super,NE,3
coal_super_4,1,1,4,0,1,0,1,0,6000,0,0,112000,10287,0,7.43,coal,300,17,2,4,4,0.64,0.64,0.55,0.25,0.25,0,0,1,Coal_super,NE,4
coal_super_5,1,1,5,0,1,0,1,0,6000,0,0,112000,10287,0,7.43,coal,300,17,2,4,4,0.64,0.64,0.55,0.25,0.25,0,0,1,Coal_super,NE,5
20A_retrofit_1,1,1,1,1,0,0.85,0,1,0,-1,0,2342,10287,0,5,blue_ammonia,300,17,2,4,4,0.64,0.64,0.55,0.25,0.25,0,0,1,ammonia,NE,1
20A_retrofit_2,1,1,2,1,0,0.85,0,1,0,-1,0,2342,10287,0,5,blue_ammonia,300,17,2,4,4,0.64,0.64,0.55,0.25,0.25,0,0,1,ammonia,NE,2
20A_retrofit_3,1,1,3,1,0,0.85,0,1,0,-1,0,2342,10287,0,5,blue_ammonia,300,17,2,4,4,0.64,0.64,0.55,0.25,0.25,0,0,1,ammonia,NE,3
20A_retrofit_4,1,1,4,1,0,0.85,0,1,0,-1,0,2342,10287,0,5,blue_ammonia,300,17,2,4,4,0.64,0.64,0.55,0.25,0.25,0,0,1,ammonia,NE,4
20A_retrofit_5,1,1,5,1,0,0.85,0,1,0,-1,0,2342,10287,0,5,blue_ammonia,300,17,2,4,4,0.64,0.64,0.55,0.25,0.25,0,0,1,ammonia,NE,5
20A_retrofit_1,1,1,1,1,0,0.85,0,1,0,-1,0,2342,10287,0,5,blue_ammonia,255,17,2,4,4,0.64,0.64,0.55,0.25,0.25,0,0,1,ammonia,NE,1
20A_retrofit_2,1,1,2,1,0,0.85,0,1,0,-1,0,2342,10287,0,5,blue_ammonia,255,17,2,4,4,0.64,0.64,0.55,0.25,0.25,0,0,1,ammonia,NE,2
20A_retrofit_3,1,1,3,1,0,0.85,0,1,0,-1,0,2342,10287,0,5,blue_ammonia,255,17,2,4,4,0.64,0.64,0.55,0.25,0.25,0,0,1,ammonia,NE,3
20A_retrofit_4,1,1,4,1,0,0.85,0,1,0,-1,0,2342,10287,0,5,blue_ammonia,255,17,2,4,4,0.64,0.64,0.55,0.25,0.25,0,0,1,ammonia,NE,4
20A_retrofit_5,1,1,5,1,0,0.85,0,1,0,-1,0,2342,10287,0,5,blue_ammonia,255,17,2,4,4,0.64,0.64,0.55,0.25,0.25,0,0,1,ammonia,NE,5
24 changes: 12 additions & 12 deletions src/load_inputs/load_resources_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1057,18 +1057,18 @@ function add_resources_to_input_data!(inputs::Dict, setup::Dict, case_path::Abst
# store a unique set of retrofit_ids
inputs["RETROFIT_IDS"] = Set(retrofit_id.(gen[inputs["RETROFIT_CAP"]]))

# Check if retrofit options and retrofitting units with unit commitment have the same capacity when UCommit == 1
if setup["UCommit"] == 1
can_retrofit_commit = intersect(inputs["RETROFIT_CAP"], inputs["COMMIT"])
retrofit_options_commit = intersect(inputs["RETROFIT_OPTIONS"], inputs["COMMIT"])
cap_size_can_retrofit_commit = cap_size.(gen[can_retrofit_commit])
cap_size_retrofit_options_commit = cap_size.(gen[retrofit_options_commit]) .* retrofit_efficiency.(gen[retrofit_options_commit])
if cap_size_can_retrofit_commit != cap_size_retrofit_options_commit
msg = "Retrofit options and retrofitting units with unit commitment should have the same capacity.\n" *
"Check \"Cap_Size\" and \"Retrofit_Efficiency\" for the retrofitting units and retrofit options in the input files."
@warn(msg)
end
end
# # Check if retrofit options and retrofitting units with unit commitment have the same capacity when UCommit == 1
# if setup["UCommit"] == 1
# can_retrofit_commit = intersect(inputs["RETROFIT_CAP"], inputs["COMMIT"])
# retrofit_options_commit = intersect(inputs["RETROFIT_OPTIONS"], inputs["COMMIT"])
# cap_size_can_retrofit_commit = cap_size.(gen[can_retrofit_commit])
# cap_size_retrofit_options_commit = cap_size.(gen[retrofit_options_commit]) .* retrofit_efficiency.(gen[retrofit_options_commit])
# if cap_size_can_retrofit_commit != cap_size_retrofit_options_commit
# msg = "Retrofit options and retrofitting units with unit commitment should have the same capacity.\n" *
# "Check \"Cap_Size\" and \"Retrofit_Efficiency\" for the retrofitting units and retrofit options in the input files."
# @warn(msg)
# end
# end
end

new_cap_energy = Set{Int64}()
Expand Down
6 changes: 3 additions & 3 deletions src/model/resources/retrofits/retrofits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ function retrofit(EP::Model, inputs::Dict)
RETROFIT_OPTIONS = inputs["RETROFIT_OPTIONS"] # Set of all resources being created
RETROFIT_IDS = inputs["RETROFIT_IDS"] # Set of unique IDs for retrofit resources

@constraint(EP, cRetrofitZone[id in RETROFIT_IDS],
@constraint(EP, cRetrofitCapacity[id in RETROFIT_IDS],
sum(cap_size(gen[y]) * EP[:vRETROFITCAP][y] for y in intersect(RETROFIT_CAP, COMMIT, resources_in_retrofit_pool_by_rid(gen,id)); init=0)
+ sum(EP[:vRETROFITCAP][y] for y in setdiff(intersect(RETROFIT_CAP, resources_in_retrofit_pool_by_rid(gen,id)), COMMIT); init=0)
== sum(cap_size(gen[y]) * EP[:vCAP][y] * retrofit_efficiency(gen[y]) for y in intersect(RETROFIT_OPTIONS, COMMIT, resources_in_retrofit_pool_by_rid(gen,id)); init=0)
+ sum(EP[:vCAP][y] * retrofit_efficiency(gen[y]) for y in setdiff(intersect(RETROFIT_OPTIONS, resources_in_retrofit_pool_by_rid(gen,id)), COMMIT); init=0))
== sum(cap_size(gen[y]) * EP[:vCAP][y] * (1/retrofit_efficiency(gen[y])) for y in intersect(RETROFIT_OPTIONS, COMMIT, resources_in_retrofit_pool_by_rid(gen,id)); init=0)
+ sum(EP[:vCAP][y] * (1/retrofit_efficiency(gen[y])) for y in setdiff(intersect(RETROFIT_OPTIONS, resources_in_retrofit_pool_by_rid(gen,id)), COMMIT); init=0))

return EP
end
8 changes: 0 additions & 8 deletions src/model/solve_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,6 @@ function solve_model(EP::Model, setup::Dict)
println("MILP solved for primal")
end

if !has_duals(EP) && setup["WriteShadowPrices"] == 1
# function to fix integers and linearize problem
fix_integers(EP)
# re-solve statement for LP solution
println("Solving LP solution for duals")
optimize!(EP)
end

## Record solver time
solver_time = time() - solver_start_time
elseif setup["ComputeConflicts"]==0
Expand Down
9 changes: 9 additions & 0 deletions src/write_outputs/write_outputs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ function write_outputs(EP::Model, path::AbstractString, setup::Dict, inputs::Dic

output_settings_d["WriteStatus"] && write_status(path, inputs, setup, EP)

if !has_duals(EP) && setup["WriteShadowPrices"] == 1
# function to fix integers and linearize problem
fix_integers(EP)
# re-solve statement for LP solution
println("Solving LP solution for duals")
set_silent(EP)
optimize!(EP)
end

if output_settings_d["WriteCosts"]
elapsed_time_costs = @elapsed write_costs(path, inputs, setup, EP)
println("Time elapsed for writing costs is")
Expand Down

0 comments on commit b7ff1b4

Please sign in to comment.