From d19fc0844fb72c8f10d89f54915baa6dbcc44702 Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Tue, 3 Dec 2024 15:34:09 +1300 Subject: [PATCH] Update --- src/plugins/stopping_rules.jl | 13 ++----------- test/plugins/stopping_rules.jl | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/plugins/stopping_rules.jl b/src/plugins/stopping_rules.jl index 520813c19..e13877c52 100644 --- a/src/plugins/stopping_rules.jl +++ b/src/plugins/stopping_rules.jl @@ -171,14 +171,9 @@ function convergence_test( if graph.objective_sense == MOI.MIN_SENSE return sample_mean - sample_ci <= current_bound - elseif graph.objective_sense == MOI.MAX_SENSE - return current_bound <= sample_mean + sample_ci else - # If sense is none of the above for some awkward reason, return to - # previous criteria - return sample_mean - sample_ci <= - current_bound <= - sample_mean + sample_ci + @assert graph.objective_sense == MOI.MAX_SENSE + return current_bound <= sample_mean + sample_ci end end @@ -281,10 +276,6 @@ mutable struct SimulationStoppingRule{F} <: AbstractStoppingRule bound_tol::Float64 end -function _get_state_variable_value(key) - return sp -> JuMP.value(JuMP.variable_by_name(sp, "$(key)_out")) -end - """ SimulationStoppingRule(; sampling_scheme::AbstractSamplingScheme = SDDP.InSampleMonteCarlo(), diff --git a/test/plugins/stopping_rules.jl b/test/plugins/stopping_rules.jl index f715c7057..69bd055dc 100644 --- a/test/plugins/stopping_rules.jl +++ b/test/plugins/stopping_rules.jl @@ -134,6 +134,12 @@ function test_Statistical() [SDDP.Log(1, 12.0, 9.0, 1.0, 1, 1, " ", false)], rule, ) + rule = SDDP.Statistical(; num_replications = 20, iteration_period = 2) + @test !SDDP.convergence_test( + model, + [SDDP.Log(1, 6.0, 9.0, 1.0, 1, 1, " ", false)], + rule, + ) return end @@ -194,6 +200,17 @@ function test_BoundStalling() ], rule, ) + rule = SDDP.BoundStalling(5, 1.0) + @test !SDDP.convergence_test( + graph, + [ + SDDP.Log(1, 0.0, 0.0, 1.0, 1, 1, " ", false), + SDDP.Log(2, 0.0, 0.0, 1.0, 1, 1, " ", false), + SDDP.Log(3, 0.0, 0.0, 1.0, 1, 1, " ", false), + SDDP.Log(4, 0.0, 0.0, 1.0, 1, 1, " ", false), + ], + rule, + ) return end @@ -276,6 +293,10 @@ function test_SimulationStoppingRule() @test !SDDP.convergence_test(graph, log[1:10], rule) @test !SDDP.convergence_test(graph, log[1:19], rule) @test SDDP.convergence_test(graph, log[1:20], rule) + rule = SDDP.SimulationStoppingRule(; period = 1) + rule.last_iteration = 20 + @test rule.period == 1 + @test !SDDP.convergence_test(graph, log, rule) return end