# SPDX-License-Identifier: LGPL-3.0-or-later ## @file # @brief Transfer genomes among four tasks while keeping their measurements separate. """Search four related quadratic tasks with a separate repertoire per task.""" from qdpy.algorithms import mtmb_search from qdpy.containers import Grid TASKS = (0.20, 0.35, 0.50, 0.65) def make_archives(): """Build a reporting grid with eight cells for each task.""" return { task: Grid(shape=8, fitness_domain=((0, 1),), features_domain=((0, 1),)) for task in TASKS } def evaluate(task, genome): """Return a task-specific cost and a shifted descriptor.""" x, y = genome cost = (x - task) ** 2 + 0.02 * (y - 0.5) ** 2 return (cost,), ((y + task) % 1.0,) if __name__ == "__main__": result = mtmb_search(make_archives(), evaluate, dimension=2, budget=64, seed=42) print(f"Attempts: {sum(result.attempts_by_task.values())}") for task, archive in result.archives.items(): print(f"Task {task:.2f}: {result.attempts_by_task[task]} attempts, " f"{archive.filled_bins}/8 cells, QD score {archive.qd_score():.3f}")