Skip to content

Commit a993582

Browse files
committed
Borg: stop when MaxRestarts is reached
1 parent 87a042d commit a993582

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

src/borg_moea.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ mutable struct BorgMOEA{FS<:FitnessScheme,V<:Evaluator,P<:Population,M<:GeneticO
2828
wrecombinate_update_period::Int
2929
restart_check_period::Int
3030
max_steps_without_ϵ_progress::Int
31+
max_restarts::Union{Int, Nothing} # how many restarts before termination
3132

3233
recombinate::Vector{CrossoverOperator} # recombination operators
3334

@@ -53,7 +54,7 @@ mutable struct BorgMOEA{FS<:FitnessScheme,V<:Evaluator,P<:Population,M<:GeneticO
5354
params[], params[], params[:γ_δ], params[:PopulationSize],
5455
Categorical(ones(length(recombinate))/length(recombinate)),
5556
params[], params[], params[:OperatorsUpdatePeriod], params[:RestartCheckPeriod],
56-
params[:MaxStepsWithoutEpsProgress],
57+
params[:MaxStepsWithoutEpsProgress], params[:MaxRestarts],
5758
recombinate,
5859
TournamentSelector(fit_scheme, ceil(Int, params[]*popsize(pop))), modify, embed)
5960
end
@@ -68,7 +69,8 @@ const BorgMOEA_DefaultParameters = chain(EpsBoxArchive_DefaultParameters, Params
6869
=> 1.0, # dampening coefficient for recombination operator weights
6970
:RestartCheckPeriod => 1000,
7071
:OperatorsUpdatePeriod => 100,
71-
:MaxStepsWithoutEpsProgress => 100
72+
:MaxStepsWithoutEpsProgress => 100,
73+
:MaxRestarts => nothing,
7274
))
7375

7476
function borg_moea(problem::OptimizationProblem, options::Parameters = EMPTY_PARAMS)
@@ -120,6 +122,10 @@ function step!(alg::BorgMOEA)
120122
return alg
121123
end
122124

125+
check_stop_condition(alg::BorgMOEA, ctrl) =
126+
isnothing(alg.max_restarts) || (alg.n_restarts < alg.max_restarts) ? "" :
127+
"Max number of restarts ($(alg.max_restarts)) reached"
128+
123129
# "kernel function" of step() that would specialize to given xover operator type
124130
function recombinate!(alg::BorgMOEA, recomb_op_ix::Int, recomb_op::CrossoverOperator)
125131
# select parents for recombination

test/test_borg_moea.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,11 @@
1414
@test BlackBoxOptim.IGD(BlackBoxOptim.CEC09_Unconstrained_Set[8].opt_value, pareto_frontier(res),
1515
fitness_scheme(res), Val{length(best_candidate(res))}) < 0.13
1616
end
17+
@testset "MaxRestarts option" begin
18+
res = bboptimize(BlackBoxOptim.Schaffer1Family; Method=:borg_moea,
19+
FitnessScheme=ParetoFitnessScheme{2}(is_minimizing=true),
20+
SearchRange=(-10.0, 10.0), NumDimensions=2, ϵ=0.01,
21+
MaxRestarts=3, MaxSteps=100000, TraceMode=:silent)
22+
@test BlackBoxOptim.general_stop_reason(res) == "Max number of restarts (3) reached"
23+
end
1724
end

0 commit comments

Comments
 (0)