QDpy
Loading...
Searching...
No Matches
multitask_map_elites.py
Go to the documentation of this file.
1# SPDX-License-Identifier: LGPL-3.0-or-later
2
4
5"""Search four related quadratic tasks with a separate repertoire per task."""
6
7from qdpy.algorithms import mtmb_search
8from qdpy.containers import Grid
9
10TASKS = (0.20, 0.35, 0.50, 0.65)
11
12
13def make_archives():
14 """Build a reporting grid with eight cells for each task."""
15 return {
16 task: Grid(shape=8, fitness_domain=((0, 1),), features_domain=((0, 1),))
17 for task in TASKS
18 }
19
20
21def evaluate(task, genome):
22 """Return a task-specific cost and a shifted descriptor."""
23 x, y = genome
24 cost = (x - task) ** 2 + 0.02 * (y - 0.5) ** 2
25 return (cost,), ((y + task) % 1.0,)
26
27
28if __name__ == "__main__":
29 result = mtmb_search(make_archives(), evaluate, dimension=2, budget=64, seed=42)
30 print(f"Attempts: {sum(result.attempts_by_task.values())}")
31 for task, archive in result.archives.items():
32 print(f"Task {task:.2f}: {result.attempts_by_task[task]} attempts, "
33 f"{archive.filled_bins}/8 cells, QD score {archive.qd_score():.3f}")