MCPcopy Create free account
hub / github.com/anyoptimization/pymoo / test_restricted_mating_selection

Function test_restricted_mating_selection

tests/algorithms/test_ctaea.py:227–256  ·  view source on GitHub ↗
(ref_dirs, evaluator)

Source from the content-addressed store, hash-verified

225
226
227def test_restricted_mating_selection(ref_dirs, evaluator):
228 np.random.seed(200)
229 selection = RestrictedMating(func_comp=comp_by_cv_dom_then_random)
230
231 problem = C3DTLZ4(n_var=12, n_obj=3)
232 ca_x = np.loadtxt(load_to_test_resource('ctaea', 'c3dtlz4', 'case2', 'preCA.x'))
233 CA = Population.new(X=ca_x)
234 evaluator.eval(problem, CA)
235
236 da_x = np.loadtxt(load_to_test_resource('ctaea', 'c3dtlz4', 'case2', 'preDA.x'))
237 DA = Population.new(X=da_x)
238 evaluator.eval(problem, DA)
239
240 Hm = Population.merge(CA, DA)
241 n_pop = len(CA)
242
243 _, rank = NonDominatedSorting().do(Hm.get('F'), return_rank=True)
244
245 Pc = (rank[:n_pop] == 0).sum() / len(Hm)
246 Pd = (rank[n_pop:] == 0).sum() / len(Hm)
247
248 P = selection.do(None, Hm, len(CA), 2, to_pop=False)
249
250 assert P.shape == (91, 2)
251 if Pc > Pd:
252 assert (P[:, 0] < n_pop).all()
253 else:
254 assert (P[:, 0] >= n_pop).all()
255 assert (P[:, 1] >= n_pop).any()
256 assert (P[:, 1] < n_pop).any()

Callers

nothing calls this directly

Calls 9

RestrictedMatingClass · 0.90
C3DTLZ4Class · 0.90
load_to_test_resourceFunction · 0.90
NonDominatedSortingClass · 0.90
mergeMethod · 0.80
newMethod · 0.45
evalMethod · 0.45
doMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…