Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Dec 3, 2024
1 parent 37aa0ee commit d19fc08
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
13 changes: 2 additions & 11 deletions src/plugins/stopping_rules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(),
Expand Down
21 changes: 21 additions & 0 deletions test/plugins/stopping_rules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit d19fc08

Please sign in to comment.