Skip to content
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

Jd/fix modified rts #101

Merged
merged 4 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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"
Expand Down
51 changes: 24 additions & 27 deletions src/library/psi_library.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
jd-lara marked this conversation as resolved.
Show resolved Hide resolved
new_slopes[1] = old_slopes[1] - cost_noise
@assert new_slopes[1] > 0.0
for ix ∈ 2:length(old_slopes)
jd-lara marked this conversation as resolved.
Show resolved Hide resolved
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)
jd-lara marked this conversation as resolved.
Show resolved Hide resolved
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
jd-lara marked this conversation as resolved.
Show resolved Hide resolved
)))
@show old_slopes
@show new_slopes
end

# set service participation
Expand Down
Loading