Multi-Objective MAP-Elites

Minimise two costs, x**2 and (1-x)**2, while filling cells along a separate descriptor. Moving x towards zero improves the first cost, and moving it towards one improves the second. In each cell qdpy.algorithms.MOME keeps a set of nondominated alternatives in a qdpy.containers.ParetoGrid.

Run from the repository root after installing the base package.

python examples/mome.py
# SPDX-License-Identifier: LGPL-3.0-or-later
## @file
# @brief Use a separate Pareto front in each descriptor cell.

"""Use a separate Pareto front in each descriptor cell."""

from qdpy.algorithms import MOME
from qdpy.containers import ParetoGrid
from qdpy.simple import run


def evaluate(candidate):
    """Return two conflicting costs and one descriptor."""
    x, descriptor = candidate
    return (x ** 2, (1 - x) ** 2), (descriptor,)


if __name__ == "__main__":
    unit = (0.0, 1.0)
    grid = ParetoGrid(
        shape=4, max_items_per_bin=5, fitness_domain=(unit, unit),
        features_domain=(unit,), fitness_weights=(-1.0, -1.0),
    )
    search = MOME(grid, budget=24, dimension=2, batch_size=4)
    result = run(search, evaluate, seed=42)

    cell = max(grid.solutions, key=lambda index: len(grid.front(index)))
    reference = (1.0, 1.0)
    tradeoffs = sorted(tuple(round(float(cost), 4) for cost in ind.fitness.values)
                       for ind in grid.front(cell))
    print(f"Evaluations: {result.evaluations}")
    print(f"Occupied cells: {grid.filled_bins}/{len(grid.solutions)}")
    print(f"Raw cost pairs in cell {cell}: {tradeoffs}")
    print(f"Cell hypervolume: {grid.cell_hypervolume(cell, reference):.4f}")
    print(f"QD hypervolume: {grid.qd_hypervolume(reference):.4f}")
    print(f"Global hypervolume: {grid.global_hypervolume(reference):.4f}")

The example sets a capacity of five solutions per cell and gives both objectives a negative weight for minimisation. A candidate enters its cell’s front if no member improves on one of its costs without worsening the other. If a front exceeds capacity, the archive samples a uniform subset to keep. Parent selection for Iso+LineDD first draws an occupied cell uniformly and then draws a member of its front.

Inspect grid.front(cell) to read the alternatives in one niche. The sorted cost pairs show how one objective improves as the other worsens. Use a positive weight for a maximisation objective and return its raw value from the evaluator.

For two objectives, pass a reference in raw objective units that is at least as bad in both objectives as every scored solution. Here (1.0, 1.0) is valid because both costs lie in the unit interval. cell_hypervolume measures one front, qd_hypervolume adds the cell volumes, and global_hypervolume measures the union across all cells. Use the same reference point for each run you compare.

The two-method walkthrough saves and reloads a ParetoGrid, checks its hypervolume, and plots its occupancy. See Choose your first QDpy search. Use qdpy.checkpoints.run_checkpointed() to continue a MOME search from a completed batch and restore its Pareto fronts in their original order. See Replay a saved search for the restart example.

See Pierrot et al. (2022).