From 79c865c98218fb58f263e35d429f901fe67d3b43 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Tue, 2 Jul 2024 16:01:04 -0600 Subject: [PATCH 1/4] change noise logic --- src/library/psi_library.jl | 51 ++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/src/library/psi_library.jl b/src/library/psi_library.jl index ce31cfe..caf8942 100644 --- a/src/library/psi_library.jl +++ b/src/library/psi_library.jl @@ -1422,36 +1422,33 @@ function _duplicate_system(main_sys::PSY.System, twin_sys::PSY.System, HVDC_line ThermalStandard, main_sys, ) - noise_values = rand(MersenneTwister(COST_PERTURBATION_NOISE_SEED), 1_000_000) - old_pwl_array = get_points(get_value_curve(get_variable(get_operation_cost(g)))) - new_pwl_array = similar(old_pwl_array) - for (ix, (x, y)) in enumerate(old_pwl_array) - if ix ∈ [1, length(old_pwl_array)] + noise_values = rand(MersenneTwister(COST_PERTURBATION_NOISE_SEED), 10_000_000) + old_value_curve = get_value_curve(get_variable(get_operation_cost(g))) + old_slopes = get_slopes(old_value_curve) + new_slopes = zeros(size(old_slopes)) + noise_val, rand_ix = iterate(noise_values, rand_ix) + cost_noise = round(100.0 * noise_val, digits=2) + new_slopes[1] = old_slopes[1] - cost_noise + @assert new_slopes[1] > 0.0 + for ix ∈ 2:length(old_slopes) + while new_slopes[ix - 1] > new_slopes[ix] noise_val, rand_ix = iterate(noise_values, rand_ix) - cost_noise = 50.0 * noise_val - new_pwl_array[ix] = (x = x, y = (y + cost_noise)) - else - try_again = true - while try_again - noise_val, rand_ix = iterate(noise_values, rand_ix) - cost_noise = 50.0 * noise_val - noise_val, rand_ix = iterate(noise_values, rand_ix) - power_noise = 0.01 * noise_val - slope_previous = - ((y + cost_noise) - old_pwl_array[ix - 1].y) / - ((x - power_noise) - old_pwl_array[ix - 1].x) - slope_next = - (-(y + cost_noise) + old_pwl_array[ix + 1].y) / - (-(x - power_noise) + old_pwl_array[ix + 1].x) - new_pwl_array[ix] = (x = (x - power_noise), y = (y + cost_noise)) - try_again = slope_previous > slope_next - if rand_ix == length(noise_values) - break - end - end + cost_noise = round(100.0 * noise_val, digits=2) + new_slopes[ix] = old_slopes[ix] + cost_noise end end - set_variable!(get_operation_cost(g), CostCurve(PiecewisePointCurve(new_pwl_array))) + @assert old_slopes != new_slopes + set_variable!( + get_operation_cost(g), + CostCurve( + PiecewiseIncrementalCurve( + get_input_at_zero(old_value_curve), + get_initial_input(old_value_curve), + get_x_coords(old_value_curve), + new_slopes + ))) + @show old_slopes + @show new_slopes end # set service participation From 66f5ec698ca48400ede9f4500124dcad7afc683b Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Tue, 2 Jul 2024 16:01:11 -0600 Subject: [PATCH 2/4] update project toml --- Project.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 472f7bd..153e141 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "PowerSystemCaseBuilder" uuid = "f00506e0-b84f-492a-93c2-c0a9afc4364e" authors = ["Sourabh Dalvi", "Jose Daniel Lara"] -version = "1.3.1" +version = "1.3.2" [deps] CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" @@ -29,7 +29,7 @@ HDF5 = "0.17" InfrastructureSystems = "2" JSON3 = "1" LazyArtifacts = "1" -PowerSystems = "4" +PowerSystems = "^4.1.1" PrettyTables = "2" Random = "1" SHA = "0.7" From af1d94fa81314c9eb7db04276dde64ecf2a3825f Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Tue, 2 Jul 2024 16:38:53 -0600 Subject: [PATCH 3/4] fix first input --- src/library/psi_library.jl | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/library/psi_library.jl b/src/library/psi_library.jl index caf8942..970742c 100644 --- a/src/library/psi_library.jl +++ b/src/library/psi_library.jl @@ -1418,37 +1418,43 @@ function _duplicate_system(main_sys::PSY.System, twin_sys::PSY.System, HVDC_line # cost perturbation must be the same for each sub-system rand_ix = 1 for g in get_components( - x -> x.prime_mover_type in [PrimeMovers.CT, PrimeMovers.CC], + x -> get_fuel(x) in [ThermalFuels.NATURAL_GAS, ThermalFuels.COAL], ThermalStandard, main_sys, ) + PSY.get_name(g) noise_values = rand(MersenneTwister(COST_PERTURBATION_NOISE_SEED), 10_000_000) old_value_curve = get_value_curve(get_variable(get_operation_cost(g))) old_slopes = get_slopes(old_value_curve) new_slopes = zeros(size(old_slopes)) noise_val, rand_ix = iterate(noise_values, rand_ix) - cost_noise = round(100.0 * noise_val, digits=2) + cost_noise = round(100.0 * noise_val; digits = 2) + get_initial_input(old_value_curve) + old_y = + get_initial_input(old_value_curve) / + (get_active_power_limits(g).min * get_base_power(g)) + new_first_input = + (old_y - cost_noise) * get_active_power_limits(g).min * get_base_power(g) new_slopes[1] = old_slopes[1] - cost_noise @assert new_slopes[1] > 0.0 - for ix ∈ 2:length(old_slopes) + for ix in 2:length(old_slopes) while new_slopes[ix - 1] > new_slopes[ix] noise_val, rand_ix = iterate(noise_values, rand_ix) - cost_noise = round(100.0 * noise_val, digits=2) + cost_noise = round(100.0 * noise_val; digits = 2) new_slopes[ix] = old_slopes[ix] + cost_noise end end @assert old_slopes != new_slopes + set_variable!( get_operation_cost(g), CostCurve( PiecewiseIncrementalCurve( - get_input_at_zero(old_value_curve), - get_initial_input(old_value_curve), - get_x_coords(old_value_curve), - new_slopes + nothing, + new_first_input, + get_x_coords(old_value_curve), + new_slopes, ))) - @show old_slopes - @show new_slopes end # set service participation From d1396c59b5f2155511252dcd787502dc059c4879 Mon Sep 17 00:00:00 2001 From: Jose Daniel Lara Date: Tue, 2 Jul 2024 16:47:02 -0600 Subject: [PATCH 4/4] add direction of change --- src/library/psi_library.jl | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/library/psi_library.jl b/src/library/psi_library.jl index 970742c..e4b10a8 100644 --- a/src/library/psi_library.jl +++ b/src/library/psi_library.jl @@ -1422,7 +1422,11 @@ function _duplicate_system(main_sys::PSY.System, twin_sys::PSY.System, HVDC_line ThermalStandard, main_sys, ) - PSY.get_name(g) + # This makes the twin system cheaper for the first tranche + # Creates an imbalance in which side is more expensive for testing + # purposes + direction = occursin("twin", PSY.get_name(g)) ? -1 : 1 + @show PSY.get_name(g), direction noise_values = rand(MersenneTwister(COST_PERTURBATION_NOISE_SEED), 10_000_000) old_value_curve = get_value_curve(get_variable(get_operation_cost(g))) old_slopes = get_slopes(old_value_curve) @@ -1434,8 +1438,9 @@ function _duplicate_system(main_sys::PSY.System, twin_sys::PSY.System, HVDC_line get_initial_input(old_value_curve) / (get_active_power_limits(g).min * get_base_power(g)) new_first_input = - (old_y - cost_noise) * get_active_power_limits(g).min * get_base_power(g) - new_slopes[1] = old_slopes[1] - cost_noise + (old_y + direction * cost_noise) * get_active_power_limits(g).min * + get_base_power(g) + new_slopes[1] = old_slopes[1] + direction * cost_noise @assert new_slopes[1] > 0.0 for ix in 2:length(old_slopes) while new_slopes[ix - 1] > new_slopes[ix] @@ -1445,7 +1450,6 @@ function _duplicate_system(main_sys::PSY.System, twin_sys::PSY.System, HVDC_line end end @assert old_slopes != new_slopes - set_variable!( get_operation_cost(g), CostCurve(