(ref_dirs, evaluator)
| 225 | |
| 226 | |
| 227 | def 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() |
nothing calls this directly
no test coverage detected
searching dependent graphs…