@@ -26,13 +26,20 @@ using Test
2626 @test 10 * sol. objective < l1
2727
2828 fitness_progress_history = []
29+ fitness_progress_history_orig = []
30+ loss_history = []
2931 function cb (state, fitness)
30- push! (fitness_progress_history, [state. u, fitness])
32+ push! (fitness_progress_history, state. objective)
33+ push! (fitness_progress_history_orig, BlackBoxOptim. best_fitness (state. original))
34+ push! (loss_history, fitness)
3135 return false
3236 end
3337 sol = solve (prob, BBO_adaptive_de_rand_1_bin_radiuslimited (), callback = cb)
3438 # println(fitness_progress_history)
3539 @test ! isempty (fitness_progress_history)
40+ fp1 = fitness_progress_history[1 ]
41+ fp2 = fitness_progress_history_orig[1 ]
42+ @test fp2 == fp1 == loss_history[1 ]
3643
3744 @test_logs begin
3845 (Base. LogLevel (- 1 ), " loss: 0.0" )
@@ -77,6 +84,39 @@ using Test
7784 @test sol_1. objective[2 ]≈ 1.7763568e-15 atol= 1e-3
7885 end
7986
87+ @testset " Sphere and Rastrigin Functions with callback" begin
88+ function multi_obj_func_1 (x, p)
89+ f1 = sum (x .^ 2 ) # Sphere function
90+ f2 = sum (x .^ 2 .- 10 .* cos .(2 π .* x) .+ 10 ) # Rastrigin function
91+ return (f1, f2)
92+ end
93+
94+ fitness_progress_history = []
95+ fitness_progress_history_orig = []
96+ function cb (state, fitness)
97+ push! (fitness_progress_history, state. objective)
98+ push! (fitness_progress_history_orig,
99+ BlackBoxOptim. best_fitness (state. original))
100+ return false
101+ end
102+
103+ mof_1 = MultiObjectiveOptimizationFunction (multi_obj_func_1)
104+ prob_1 = Optimization. OptimizationProblem (mof_1, u0; lb = lb, ub = ub)
105+ sol_1 = solve (prob_1, opt, NumDimensions = 2 ,
106+ FitnessScheme = ParetoFitnessScheme {2} (is_minimizing = true ),
107+ callback = cb)
108+
109+ fp1 = fitness_progress_history[1 ]
110+ fp2 = fitness_progress_history_orig[1 ]
111+ @test fp2. orig == fp1
112+ @test length (fp1) == 2
113+
114+ @test sol_1 ≠ nothing
115+ println (" Solution for Sphere and Rastrigin: " , sol_1)
116+ @test sol_1. objective[1 ]≈ 6.9905986e-18 atol= 1e-3
117+ @test sol_1. objective[2 ]≈ 1.7763568e-15 atol= 1e-3
118+ end
119+
80120 # Test 2: Rosenbrock and Ackley Functions
81121 @testset " Rosenbrock and Ackley Functions" begin
82122 function multi_obj_func_2 (x, p)
0 commit comments