def test_pareto_front_attrs():
amax = 1.0
amin = 0.7
bmax = 1.3
bmin = 1.0
front_fitness = [(1, 1), (0.9, 1.1), (0.8, 1.2), (0.7, 1.3)]
models = [Model(a, b) for a, b in front_fitness]
models.extend([Model(a + 0.01 * abs(random.random()) + 0.01, b + 0.01 *
abs(random.random()) + 0.01) for a, b in random.choices(front_fitness, k=50)])
models = list(filter(lambda m: m.b <= bmax, models))
front = pareto_front(models, "a", "b")
for m in front:
assert amin <= m.a <= amax
assert bmin <= m.b <= bmax
评论列表
文章目录