Skip to content

Commit

Permalink
add test_g3pcx.py
Browse files Browse the repository at this point in the history
  • Loading branch information
TaroKingCN committed Jul 4, 2024
1 parent bc0d144 commit 2458549
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pypop7/optimizers/ga/test_g3pcx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def test_optimize():
import numpy # engine for numerical computing
from pypop7.benchmarks.base_functions import rosenbrock # function to be minimized
from pypop7.optimizers.ga.g3pcx import G3PCX
problem = {'fitness_function': rosenbrock, # to define problem arguments
'ndim_problem': 2,
'lower_boundary': -5.0 * numpy.ones((2,)),
'upper_boundary': 5.0 * numpy.ones((2,))}
options = {'max_function_evaluations': 5000, # to set optimizer options
'seed_rng': 2022}
g3pcx = G3PCX(problem, options) # to initialize the black-box optimizer class
results = g3pcx.optimize() # to run the optimization/evolution process
assert results['n_function_evaluations'] == 5000
assert results['best_so_far_y'] < 1.0

0 comments on commit 2458549

Please sign in to comment.