-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a0bde6f
commit ab065cd
Showing
6 changed files
with
114 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "PowerModelsONM" | ||
uuid = "25264005-a304-4053-a338-565045d392ac" | ||
authors = ["David M Fobes <[email protected]>"] | ||
version = "3.5.0" | ||
version = "3.6.0" | ||
|
||
[deps] | ||
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
""" | ||
evaluate_partition_optimality( | ||
data, | ||
load_scenarios, | ||
model_type, | ||
solver; | ||
save_partial_results, | ||
partial_result_folder, | ||
time_elapsed, | ||
kwargs... | ||
) | ||
Function to evaluate the optimality of a specific partition by considering a collection of load scenarios. | ||
`data` has the partition configuration applied. | ||
""" | ||
function evaluate_partition_optimality( | ||
data::Dict{String,<:Any}, | ||
load_scenarios, | ||
model_type::Type, | ||
solver; | ||
save_partial_results::Bool=false, | ||
partial_result_folder::String=".", | ||
time_elapsed::Float64 = missing, | ||
kwargs...) | ||
|
||
_results = Dict{String,Any}() | ||
|
||
for ls in keys(load_scenarios) | ||
single_load_scenario = Dict{String,Dict{String,Any}}() | ||
single_load_scenario["1"] = load_scenarios[ls] | ||
|
||
eng = deepcopy(data) | ||
|
||
if !ismissing(time_elapsed) | ||
eng["time_elapsed"] = time_elapsed | ||
end | ||
|
||
@debug "starting load scenario evaluation $(ls)/$(length(load_scenarios))" | ||
|
||
result = solve_robust_block_mld(eng, model_type, solver, single_load_scenario; kwargs...) | ||
|
||
if save_partial_results | ||
open("$(partial_result_folder)/result_$(ls).json", "w") do io | ||
JSON.print(io, result) | ||
end | ||
end | ||
|
||
_results[ls] = result | ||
end | ||
|
||
return _results | ||
end | ||
|
||
|
||
""" | ||
retrieve_load_scenario_optimality(results::Dict) | ||
Returns a Dict of objectives for the different load scenarios considered in the robust partition evaluation. | ||
""" | ||
function retrieve_load_scenario_optimality(results::Dict)::Dict{String,Float64} | ||
return Dict{String,Float64}("$i" => results["$i"]["1"]["objective"] for i in 1:length(results)) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
function randomize_partition_config( | ||
case, | ||
num_closed_switches) | ||
|
||
if num_closed_switches > length(keys(case["switch"])) | ||
error("Number of closed switches exceeds the total number of switches") | ||
end | ||
|
||
part_config = Dict{String,Any}() | ||
|
||
switch_keys = collect(keys(case["switch"])) | ||
shuffled_keys = shuffle(switch_keys) | ||
closed_switches = shuffled_keys[1:num_closed_switches] | ||
|
||
# Set the status of the selected switches to "CLOSED" and the rest to "OPEN" | ||
for key in switch_keys | ||
if key in closed_switches | ||
part_config[key] = PMD.SwitchState(1) | ||
else | ||
part_config[key] = PMD.SwitchState(0) | ||
end | ||
end | ||
|
||
case["fixed_partition_config"] = part_config | ||
|
||
return case | ||
end | ||
|
||
|
||
@testset "robust partition evaluation" begin | ||
case = ONM.parse_file("test/data/ieee13_feeder.dss") | ||
case = randomize_partition_config(case, 2) | ||
|
||
num_load_scenarios = 20 | ||
uncertainty_val = 0.2 | ||
ls = ONM.generate_load_scenarios(case, num_load_scenarios, uncertainty_val) | ||
|
||
solver = ONM.optimizer_with_attributes(HiGHS.Optimizer, "primal_feasibility_tolerance" => 1e-6, "dual_feasibility_tolerance" => 1e-6, "small_matrix_value" => 1e-12, "allow_unbounded_or_infeasible" => true) | ||
|
||
results_eval_optimality = ONM.evaluate_partition_optimality(case, ls, PMD.LPUBFDiagPowerModel, solver) | ||
|
||
optimality = ONM.retrieve_load_scenario_optimality(results_eval_optimality) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters