Skip to content

Commit 17a1d72

Browse files
committed
test(OptimizationBBO): avoid deepcopy in callback
#899 (comment)
1 parent fa88f0a commit 17a1d72

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/OptimizationBBO/test/runtests.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,23 @@ using Test
8787
end
8888

8989
fitness_progress_history = []
90+
fitness_progress_history_orig = []
9091
function cb(state, fitness)
91-
push!(fitness_progress_history, deepcopy(state))
92+
push!(fitness_progress_history, state.objective)
93+
push!(fitness_progress_history, BlackBoxOptim.best_fitness(state.original))
9294
return false
9395
end
9496

9597
mof_1 = MultiObjectiveOptimizationFunction(multi_obj_func_1)
9698
prob_1 = Optimization.OptimizationProblem(mof_1, u0; lb = lb, ub = ub)
9799
sol_1 = solve(prob_1, opt, NumDimensions = 2,
98-
FitnessScheme = ParetoFitnessScheme{2}(is_minimizing = true), callback=cb)
100+
FitnessScheme = ParetoFitnessScheme{2}(is_minimizing = true),
101+
callback=cb)
99102

100103
fp1 = fitness_progress_history[1]
101-
@test BlackBoxOptim.best_fitness(fp1.original).orig == fp1.objective
102-
@test length(fp1.objective) == 2
104+
fp2 = fitness_progress_history[2]
105+
@test fp2.orig == fp1
106+
@test length(fp1) == 2
103107

104108
@test sol_1 nothing
105109
println("Solution for Sphere and Rastrigin: ", sol_1)

0 commit comments

Comments
 (0)