diff --git a/docs/algorithms/nsgaiii.md b/docs/algorithms/nsgaiii.md index 01b08f0da..2aaae3064 100644 --- a/docs/algorithms/nsgaiii.md +++ b/docs/algorithms/nsgaiii.md @@ -29,7 +29,7 @@ config = ( .pop_size(pop_size) .crossover("sbx", prob=1.0, eta=30.0) .mutation("pm", prob="1/n", eta=20.0) - .selection("tournament") + .selection("random") .reference_directions(divisions=divisions) .result_mode("population") .build() @@ -57,7 +57,7 @@ python examples/journeys/nsgaiii_dtlz2.py ![NSGA-III final population on three-objective DTLZ2, with a wireframe of the analytical positive unit-sphere Pareto surface.](../assets/algorithms/nsgaiii-dtlz2.svg) -*Actual run: VAMOS 1.0.0, NumPy, seed 42, 91 directions and solutions, 10,000 evaluations. The grey wireframe is analytical, not another optimization run.* +*Actual run: VAMOS 1.0.0, NumPy, seed 42, 91 directions and solutions, 10,000 evaluations. The grey wireframe is analytical, not another optimization run. **Development after 1.4.0:** VAMOS 1.0.0 chose the parents by a tournament on rank and crowding distance; the example now draws them at random (see [variants and their effect](#variants-and-their-effect)), so its final population differs from the illustration's.* All three objectives are minimized. DTLZ2's analytical Pareto surface satisfies `f1² + f2² + f3² = 1` in the positive octant. The returned vectors approach this trade-off surface; a completed budget does not prove convergence or uniform coverage. The analytical wireframe is used only for interpretation. @@ -90,9 +90,16 @@ For explicit reference-direction files, each row must be non-negative, sum to on ### Variants and their effect -Parents are chosen by binary tournament on non-dominated rank and crowding distance, with feasible solutions first when constraints are active, as in NSGA-II and in jMetal's NSGA-III example. Deb and Jain choose parents at random [1], and the constrained version compares constraint violation and picks at random among feasible solutions [2], as pymoo does. `selection("tournament", size=k)` sets the tournament size; NSGA-III reads no other selection setting. +**Development after 1.4.0:** parents are chosen as the configuration says, and never by crowding distance, which is not part of NSGA-III: -**VAMOS 1.2.0:** `constraint_handling` replaces the feasibility-first rule by another of jMetal's constraint-handling techniques, such as epsilon-constrained or stochastic ranking: its fronts take the place of the non-dominated ones in the survival and the tournament, and niching cuts the last front that survives. See [choose a constraint-handling technique](../reference/constraints.md#choose-a-constraint-handling-technique). +| Selection | Parents | +| --- | --- | +| `selection("random")` (the default) | Drawn at random, as Deb and Jain do [1]. With constraints and feasibility first, each parent wins a binary tournament on the constraint violation: feasible beats infeasible, the smaller violation wins, and a tie, such as two feasible solutions, is drawn. This is the mating selection of the constrained version [2] and of pymoo's NSGA-III. | +| `selection("tournament", size=k)` | jMetal's NSGA-III tournament: `k` distinct solutions (2 by default) drawn at random, of which the lowest non-dominated rank wins (feasible solutions first, then by violation), with ties drawn at random. jMetal's `NSGAIIIBuilder` compares the rank and then a niche distance that its replacement never writes, so its ties are drawn too. | + +Any other method (`boltzmann`, `ranking`, `sus`, ...) or option raises `ConfigurationError`. VAMOS 1.4.0 and earlier chose parents by a binary tournament on rank and crowding distance, as NSGA-II, whatever the configured selection, `"random"` included. Every NSGA-III run therefore gives other results than with VAMOS 1.4.0 for the same seed. Crowding distance favours the ends of the fronts, a selection pressure that the published algorithm does not have: on ZDT4 with 100 individuals and 25,000 evaluations (seeds 0 to 9, reference point (1.1, 1.1)), the mean hypervolume of the default configuration goes from 0.863 to 0.836. + +**VAMOS 1.2.0:** `constraint_handling` replaces the feasibility-first rule by another of jMetal's constraint-handling techniques, such as epsilon-constrained or stochastic ranking: its fronts take the place of the non-dominated ones in the survival and the tournament, and niching cuts the last front that survives. See [choose a constraint-handling technique](../reference/constraints.md#choose-a-constraint-handling-technique). **Development after 1.4.0:** with a technique, `selection("random")` draws the parents at random, and only `selection("tournament")` compares the technique's fronts. Normalization estimates the nadir point from the hyperplane through the extreme points. When the hyperplane cannot be built, or an intercept lies beyond the worst point found so far in some objective, VAMOS uses the worst point of the first front for every objective, as pymoo up to 0.4 did. pymoo 0.6 replaces only the objectives whose intercept lies beyond the worst point. The paper does not fix this rule, so both are variants, but the normalization differs in those generations. diff --git a/docs/guide/cli.md b/docs/guide/cli.md index 6eadb719a..a398479a7 100644 --- a/docs/guide/cli.md +++ b/docs/guide/cli.md @@ -340,6 +340,12 @@ negative `--seed`, a `--n-var` or `--n-obj` below 1, a different `--n-obj` or population a problem runs with (after its `problems.` overrides), and `--track-genealogy` with an algorithm that records no genealogy. It warns about algorithm-specific flags that the selected algorithm ignores. +**Development after 1.4.0:** NSGA-III selects its parents at random, as +`NSGAIIIConfig.default()` does, and `--selection-pressure` no longer sizes a +tournament for it; a `selection` of `tournament` with its `size` in the +`nsgaiii` block of a config file runs jMetal's NSGA-III tournament (see +[NSGA-III](../algorithms/nsgaiii.md#variants-and-their-effect)). + **VAMOS 1.2.0:** `--track-genealogy` (or `track_genealogy` in a config file) works with NSGA-II, MOEA/D, SMS-EMOA, NSGA-III, SPEA2, IBEA and SMPSO; AGE-MOEA and RVEA record no genealogy, so the CLI rejects it with them diff --git a/docs/reference/algorithms.md b/docs/reference/algorithms.md index c922957e9..fd8472f47 100644 --- a/docs/reference/algorithms.md +++ b/docs/reference/algorithms.md @@ -217,10 +217,15 @@ name of Evolver's parameter (`agemoeaII` in Evolver). These are declared VAMOS choices, not defects; report them when comparing with published results or with another framework. -- **NSGA-III parents** are chosen by binary tournament on non-dominated rank - and crowding distance (feasibility first under constraints), as in NSGA-II - and in jMetal's NSGA-III example. Deb and Jain (2014) choose parents at - random. See [NSGA-III](../algorithms/nsgaiii.md#variants-and-their-effect). +- **NSGA-III parents:** **Development after 1.4.0:** no longer a departure. + They are drawn at random by default, as Deb and Jain (2014) and pymoo do + (under constraints, by a binary tournament on the violation, as Jain and + Deb's constrained NSGA-III), and `selection("tournament")` is jMetal's + NSGA-III tournament on rank. VAMOS 1.4.0 and earlier always chose them by a + binary tournament on non-dominated rank and crowding distance, as NSGA-II, + whatever the configured selection, so NSGA-III results of those versions + are not results of the published algorithm. See + [NSGA-III](../algorithms/nsgaiii.md#variants-and-their-effect). - **NSGA-III nadir estimate:** when an intercept of the extreme-point hyperplane lies beyond the worst point found so far, VAMOS uses the worst point of the first front for every objective, as pymoo up to 0.4 did; pymoo @@ -504,7 +509,7 @@ never compiles problem evaluation. | Algorithm | Compiled with `engine="numba"` | Stays in NumPy/Python | | --- | --- | --- | | NSGA-II | Non-dominated ranking and crowding, survival, tournament selection, SBX, polynomial mutation; the whole one-offspring steady-state step in its supported configuration (below) | Feasibility ordering, archives, steady-state front maintenance outside that configuration | -| NSGA-III | Ranking and crowding, tournament selection, SBX, polynomial mutation | Normalization, association to reference directions, niching (it shuffles with the run generator inside the loop) | +| NSGA-III | Ranking and crowding, tournament selection (**Development after 1.4.0:** where configured, and the violation tournament of random parents under constraints), SBX, polynomial mutation | Random parent draws, normalization, association to reference directions, niching (it shuffles with the run generator inside the loop) | | MOEA/D | Differential-evolution children, SBX, polynomial mutation, neighbourhood replacement; the whole one-offspring step (see below) | Weight geometry; parent sampling and repair outside the compiled one-offspring step | | SMS-EMOA | The steady-state step (VAMOS 1.2.0, see below): child variation and clipping, front insertion, two-objective hypervolume contributions, crowding, feasibility-first removal; tournament selection where configured | Parent sampling draws, hypervolume contributions for three or more objectives (MooCore when installed), archives | | SPEA2 | SBX, polynomial mutation, lexicographic archive truncation | Strength/raw fitness and density (vectorized NumPy) | diff --git a/docs/reference/api/algorithms/nsgaiii.md b/docs/reference/api/algorithms/nsgaiii.md index 0d8fb7bfd..15517280a 100644 --- a/docs/reference/api/algorithms/nsgaiii.md +++ b/docs/reference/api/algorithms/nsgaiii.md @@ -19,6 +19,12 @@ emits a `FutureWarning`; both fields are planned for removal in 2.0 (see `NSGAIIIConfig.default()` does not warn. `mutation_prob_factor` now sets the mutation probability to `factor / n_var`, as in NSGA-II. +**Development after 1.4.0:** `selection` is `("random", {})`, the default, or +`("tournament", {"size": k})`, and any other method or option raises +`ConfigurationError`; NSGA-III used to run a binary tournament on rank and +crowding distance whatever its selection. See +[variants and their effect](../../../algorithms/nsgaiii.md#variants-and-their-effect). + **Development after 1.4.0:** the file of `reference_directions(path=...)` is read as MOEA/D's weight files: one direction per line, the components separated by whitespace or by commas (VAMOS 1.4.0 read commas only, so jMetal's diff --git a/docs/topics/tuning.md b/docs/topics/tuning.md index 96371a1a9..6b211b8c5 100644 --- a/docs/topics/tuning.md +++ b/docs/topics/tuning.md @@ -415,6 +415,18 @@ offset of 0.1, so no assignment reproduced the default configuration; an assignment without the new parameters still builds that tournament configuration. +**Development after 1.4.0:** the NSGA-III spaces choose the mating selection, +`random` (the default, Deb and Jain's) or `tournament` (jMetal's NSGA-III +tournament on rank), with `tournament_size` in [2, 10] only for a tournament, +as Evolver's `NSGAIIIDouble` space does. Evolver's space also offers Boltzmann, +ranking and stochastic universal sampling selection, which VAMOS's NSGA-III does +not run. The spaces of VAMOS 1.4.0 offered only `tournament_size`, and NSGA-III +then ran a binary tournament on rank and crowding distance whatever its +selection, so no assignment ran the published algorithm; an assignment with +`tournament_size` and without `selection` still builds a tournament of that +size, which now compares ranks only (see +[NSGA-III](../algorithms/nsgaiii.md#variants-and-their-effect)). + **VAMOS 1.3.0:** the MOEA/D and SMS-EMOA spaces offer what Evolver's `MOEADDouble` and `SMSEMOADouble` spaces offer, so that a configuration tuned or published with Evolver is a point of them: diff --git a/examples/journeys/nsgaiii_dtlz2.py b/examples/journeys/nsgaiii_dtlz2.py index ffeb078e8..04cadcfe9 100644 --- a/examples/journeys/nsgaiii_dtlz2.py +++ b/examples/journeys/nsgaiii_dtlz2.py @@ -28,7 +28,7 @@ def solve(*, divisions: int = 12, max_evaluations: int = 10_000, seed: int = 42) .pop_size(pop_size) .crossover("sbx", prob=1.0, eta=30.0) .mutation("pm", prob="1/n", eta=20.0) - .selection("tournament") + .selection("random") .reference_directions(divisions=divisions) .result_mode("population") .build() diff --git a/src/vamos/engine/algorithm/_builder_decomposition.py b/src/vamos/engine/algorithm/_builder_decomposition.py index 5279a3d7c..1c2deccbd 100644 --- a/src/vamos/engine/algorithm/_builder_decomposition.py +++ b/src/vamos/engine/algorithm/_builder_decomposition.py @@ -86,7 +86,6 @@ def build_nsgaiii_algorithm( problem: ProblemProtocol, pop_size: int, nsgaiii_variation: dict[str, Any] | None, - selection_pressure: int, track_genealogy: bool = False, ) -> tuple[NSGAIII, AlgorithmConfigProtocol]: encoding = resolve_problem_encoding(problem) @@ -100,10 +99,12 @@ def build_nsgaiii_algorithm( builder.pop_size(pop_size) apply_operator_config(builder, method_name="crossover", operator_cfg=var_cfg["crossover"], key="crossover") apply_operator_config(builder, method_name="mutation", operator_cfg=var_cfg["mutation"], key="mutation") + # Development after 1.4.0: random parents, as NSGAIIIConfig.default(); --selection-pressure sized a + # tournament on rank and crowding distance, which is not NSGA-III's selection. apply_operator_config( builder, method_name="selection", - operator_cfg=var_cfg.get("selection", ("tournament", {"size": selection_pressure})), + operator_cfg=var_cfg.get("selection", ("random", {})), key="selection", ) apply_optional_operator_config( diff --git a/src/vamos/engine/algorithm/config/nsgaiii.py b/src/vamos/engine/algorithm/config/nsgaiii.py index d9573bd5b..f251119d1 100644 --- a/src/vamos/engine/algorithm/config/nsgaiii.py +++ b/src/vamos/engine/algorithm/config/nsgaiii.py @@ -3,11 +3,12 @@ from __future__ import annotations from dataclasses import dataclass -from typing import Any +from typing import Any, Self from vamos.engine.archive import ExternalArchiveConfig from vamos.engine.reference_directions import lattice_size from vamos.foundation.encoding import EncodingLike +from vamos.foundation.exceptions import ConfigurationError from .base import ( ConstraintModeStr, @@ -36,6 +37,43 @@ _REFERENCE_LATTICE_RULE = "since VAMOS 1.2.0, NSGA-III uses the largest reference-direction lattice that fits in pop_size and runs N >= H" +# Development after 1.4.0: NSGA-III's parent selections. "random" is Deb and Jain's (2014), the +# default; "tournament" is jMetal's NSGA-III tournament on rank, with ties decided at random. +NSGAIII_SELECTIONS = ("random", "tournament") + + +def nsgaiii_selection(selection: object) -> tuple[str, int]: + """The method of NSGA-III's parent selection and its tournament size (2 for ``"random"``). + + Development after 1.4.0: NSGA-III runs ``"random"`` and ``"tournament"`` (with an optional + ``size``), and rejects any other method or option instead of running a tournament. + + Raises + ------ + ConfigurationError + For a method other than ``"random"`` and ``"tournament"``, an option of ``"random"``, or an + option of ``"tournament"`` other than ``size``. + """ + if not (isinstance(selection, (tuple, list)) and len(selection) == 2 and isinstance(selection[0], str)): + raise ConfigurationError(f"NSGA-III selection must be a (method, options) pair; got {selection!r}.") + method, options = str(selection[0]).strip().lower(), selection[1] + if not isinstance(options, dict): + raise ConfigurationError(f"NSGA-III selection options must be a mapping; got {options!r}.") + if method not in NSGAIII_SELECTIONS: + raise ConfigurationError( + f"NSGA-III does not support selection {selection[0]!r}: its parent selection is 'random' " + "(Deb and Jain, 2014; the default) or 'tournament' (on rank, as jMetal's NSGA-III)." + ) + allowed = {"size"} if method == "tournament" else set() + unexpected = sorted(set(options) - allowed) + if unexpected: + detail = "only 'size'" if allowed else "no options" + raise ConfigurationError(f"NSGA-III's {method} selection takes {detail}; got {', '.join(map(repr, unexpected))}.") + size = options.get("size", 2) + if isinstance(size, bool) or not isinstance(size, int) or size < 1: + raise ConfigurationError(f"NSGA-III's tournament size must be a positive integer; got {size!r}.") + return method, size + @dataclass(frozen=True) class NSGAIIIConfig(_SerializableConfig): @@ -59,6 +97,7 @@ class NSGAIIIConfig(_SerializableConfig): def __post_init__(self) -> None: super().__post_init__() + nsgaiii_selection(self.selection) # ``enforce_ref_dirs`` is true in every default, so ``False`` warns wherever it comes from. # ``pop_size_auto`` is true in ``default()`` and false otherwise: only the builder method can # tell that a user set it. @@ -76,6 +115,9 @@ def default( """ Create a default NSGA-III configuration. + Development after 1.4.0: parents are selected at random, as Deb and Jain (2014); the + default used to be a binary tournament on rank and crowding distance. + Parameters ---------- pop_size @@ -106,7 +148,7 @@ def default( .pop_size(pop_size) .crossover(crossover[0], **crossover[1]) .mutation(mutation[0], **mutation[1]) - .selection("tournament") + .selection("random") .reference_directions(divisions=divisions) ) # The stable default keeps ``pop_size_auto=True`` without the warning of the builder method. @@ -140,6 +182,25 @@ class _NSGAIIIConfigBuilder( cfg = NSGAIIIConfig.builder().pop_size(92).crossover("sbx", prob=1.0).build() """ + def selection(self, method: str, **kwargs: Any) -> Self: + """Parent selection: ``"random"`` or ``"tournament"`` (with an optional ``size``, 2 by default). + + ``"random"`` draws the parents at random, as Deb and Jain (2014). With constraint values and + feasibility first (``constraint_mode="feasibility"`` without ``constraint_handling``), each + parent wins a binary tournament on the constraint violation that is decided at random between + two feasible solutions, as the constrained NSGA-III of Jain and Deb (2014) and pymoo's NSGA-III. + + ``"tournament"`` takes ``size`` solutions at random and keeps the one of the lowest + non-dominated rank (feasible solutions first, then by violation, or the fronts of + ``constraint_handling``), with ties decided at random: jMetal's NSGA-III tournament. It does not + use crowding distance. + + Development after 1.4.0: other methods and options raise ``ConfigurationError``; before, + every method ran a binary tournament on rank and crowding distance. + """ + nsgaiii_selection((method, kwargs)) + return super().selection(method, **kwargs) + def reference_directions( self, *, diff --git a/src/vamos/engine/algorithm/factory.py b/src/vamos/engine/algorithm/factory.py index 3c209bf66..c9c727789 100644 --- a/src/vamos/engine/algorithm/factory.py +++ b/src/vamos/engine/algorithm/factory.py @@ -109,7 +109,6 @@ def build_algorithm( pop_size=pop_size, nsgaiii_variation=variations.get("nsgaiii"), track_genealogy=track_genealogy, - selection_pressure=selection_pressure, ), "spea2": lambda: build_spea2_algorithm( kernel=kernel, diff --git a/src/vamos/engine/algorithm/nsgaii/constrained_survival.py b/src/vamos/engine/algorithm/nsgaii/constrained_survival.py index 0337b3e5e..6a593b9b3 100644 --- a/src/vamos/engine/algorithm/nsgaii/constrained_survival.py +++ b/src/vamos/engine/algorithm/nsgaii/constrained_survival.py @@ -5,7 +5,8 @@ replacement the technique adapts to that union at the run's progress, the evaluations before the offspring's over the budget, as jMetal's ``ConstraintHandlingReplacement`` does. VAMOS ranks the population again for the tournaments, as it does with cdp; jMetal reuses the ranks of the replacement. -NSGA-III ranks its tournaments with :func:`technique_selection_metrics` too. +Development after 1.4.0: NSGA-III's tournament compares the technique's ranks only, without crowding +distance (``nsgaiii.helpers.nsgaiii_parents``). """ from __future__ import annotations diff --git a/src/vamos/engine/algorithm/nsgaiii/helpers.py b/src/vamos/engine/algorithm/nsgaiii/helpers.py index f3ce08771..ceab4a367 100644 --- a/src/vamos/engine/algorithm/nsgaiii/helpers.py +++ b/src/vamos/engine/algorithm/nsgaiii/helpers.py @@ -29,7 +29,7 @@ "associate", "niche_selection", "nsgaiii_survival", - "nsgaiii_selection_metrics", + "nsgaiii_parents", "evaluate_population_with_constraints", ] @@ -432,27 +432,56 @@ def _reference_direction_survival( return np.asarray(survivor_indices, dtype=int), ideal_point, extreme_points, worst_point -def nsgaiii_selection_metrics( +def nsgaiii_parents( + method: str, + pressure: int, kernel: KernelBackend, F: np.ndarray[Any, Any], G: np.ndarray[Any, Any] | None, constraint_mode: str, technique: ConstraintHandlingTechnique | None, rng: np.random.Generator, -) -> tuple[np.ndarray[Any, Any], np.ndarray[Any, Any]]: - """Ranks and crowding of the mating tournament. - - The fronts are the technique's, when there is one other than cdp, and the feasibility-first - ones otherwise. As in NSGA-II, VAMOS ranks the population again for the tournament. + n_parents: int, +) -> np.ndarray[Any, Any]: + """Indices of the ``n_parents`` parents that NSGA-III mates, in pairs. + + Development after 1.4.0: NSGA-III selects its parents as configured, and never by crowding + distance, which is not part of NSGA-III. VAMOS 1.4.0 and earlier ran a binary tournament on rank + and crowding distance, as NSGA-II, whatever the configured selection. + + ``"random"`` draws them at random, as Deb and Jain (2014). With constraint values and feasibility + first (no constraint-handling ``technique``), each parent is the winner of a binary tournament on + the constraint violation, decided at random between two feasible or equally violated solutions, + as the constrained NSGA-III of Jain and Deb (2014) and pymoo's NSGA-III (``comp_by_cv_then_random``). + + ``"tournament"`` takes ``pressure`` distinct solutions at random and keeps the one of the lowest + rank, the ties decided at random, as jMetal's NSGA-III: the default selection of its + ``NSGAIIIBuilder`` compares the ranks and then a niche distance that its replacement does not + write, so its ties are decided at random too. The ranks are the technique's fronts when there is + one, and otherwise the non-dominated fronts with feasible solutions first, the infeasible ones + compared by their violation. """ - from vamos.engine.algorithm.nsgaii.constrained_survival import technique_selection_metrics from vamos.engine.algorithm.nsgaii.state import compute_selection_metrics - if technique is not None and G is not None and constraint_mode != "none": - ranks, crowding = technique_selection_metrics(technique, kernel, F, G, rng) + n = F.shape[0] + constrained = G is not None and constraint_mode != "none" + if method == "random": + if not constrained or technique is not None: + return rng.integers(0, n, size=n_parents, dtype=int) + # Equal ranks: the tournament compares the second key, minus the violation, and then draws. + violation = compute_violation(G) + return np.asarray(kernel.tournament_selection(np.zeros(n, dtype=int), -violation, 2, rng, n_parents=n_parents), dtype=int) + if method != "tournament": + raise ValueError(f"Unsupported NSGA-III selection method '{method}'.") + if constrained and technique is not None: + assert G is not None + ranks = np.asarray(technique.ranks(kernel, F, G, rng), dtype=int) + second_key = np.zeros(n, dtype=float) else: - ranks, crowding = compute_selection_metrics(kernel, F, G, constraint_mode) - return np.asarray(ranks, dtype=int), np.asarray(crowding, dtype=float) + ranks = np.asarray(compute_selection_metrics(kernel, F, G, constraint_mode)[0], dtype=int) + # Feasible rows tie on 0; an infeasible row has minus its violation (its rank follows the feasible ones). + second_key = -compute_violation(G) if constrained else np.zeros(n, dtype=float) + return np.asarray(kernel.tournament_selection(ranks, second_key, pressure, rng, n_parents=n_parents), dtype=int) def evaluate_population_with_constraints( diff --git a/src/vamos/engine/algorithm/nsgaiii/initialization.py b/src/vamos/engine/algorithm/nsgaiii/initialization.py index 57f8f4261..c0a29db4d 100644 --- a/src/vamos/engine/algorithm/nsgaiii/initialization.py +++ b/src/vamos/engine/algorithm/nsgaiii/initialization.py @@ -23,12 +23,12 @@ from vamos.engine.algorithm.components.utils import resolve_bounds_array from vamos.engine.algorithm.components.weight_vectors import load_or_generate_weight_vectors, read_weight_vectors from vamos.engine.algorithm.config.base import normalize_constraint_mode +from vamos.engine.algorithm.config.nsgaiii import nsgaiii_selection from vamos.engine.archive.factory import resolve_external_archive, setup_archive from vamos.engine.operators.policies.nsgaiii import build_variation_operators from vamos.engine.reference_directions import lattice_size from vamos.foundation.encoding import EncodingLike, normalize_encoding -from .helpers import nsgaiii_selection_metrics from .state import NSGAIIIState if TYPE_CHECKING: @@ -107,15 +107,8 @@ def initialize_nsgaiii_run( variation_kernels=kernel.variation_kernels(), ) - # Tournament size - sel_method, sel_params = config["selection"] - if sel_method == "tournament": - unexpected = sorted(set(sel_params) - {"size"}) - if unexpected: - raise ValueError(f"Unsupported tournament selection options: {', '.join(unexpected)}") - pressure = int(sel_params.get("size", 2)) - else: - pressure = 2 + # Development after 1.4.0: "random" or "tournament" (and its size); any other selection raises. + selection_method, pressure = nsgaiii_selection(config["selection"]) # Reference directions: a file, the complete lattice for the configured divisions, or, without # either, the complete Das-Dennis lattice with the most directions that fit in pop_size. The @@ -179,7 +172,6 @@ def initialize_nsgaiii_run( # Setup external archive ext_cfg = resolve_external_archive(config, seed=seed) archive_X, archive_F, archive_manager = setup_archive(kernel, X, F, n_var, n_obj, X.dtype, ext_cfg, G) - selection_ranks, selection_crowding = nsgaiii_selection_metrics(kernel, F, G, constraint_mode, constraint_handling, rng) # Create state state = NSGAIIIState( @@ -196,14 +188,13 @@ def initialize_nsgaiii_run( # NSGA-III specific ref_dirs=ref_dirs, ref_dirs_norm=ref_dirs_norm, + selection_method=selection_method, pressure=pressure, crossover_fn=crossover_fn, mutation_fn=mutation_fn, ideal_point=np.full(n_obj, np.inf), worst_point=np.full(n_obj, -np.inf), extreme_points=None, - selection_ranks=np.asarray(selection_ranks, dtype=int), - selection_crowding=np.asarray(selection_crowding, dtype=float), # Archive archive_size=ext_cfg.capacity if ext_cfg else None, archive_X=archive_X, diff --git a/src/vamos/engine/algorithm/nsgaiii/nsgaiii.py b/src/vamos/engine/algorithm/nsgaiii/nsgaiii.py index 3ab13b87a..426f57953 100644 --- a/src/vamos/engine/algorithm/nsgaiii/nsgaiii.py +++ b/src/vamos/engine/algorithm/nsgaiii/nsgaiii.py @@ -29,7 +29,7 @@ from vamos.foundation.kernel import default_kernel from vamos.foundation.kernel.backend import DecisionArray, FloatArray -from .helpers import nsgaiii_selection_metrics, nsgaiii_survival +from .helpers import nsgaiii_parents, nsgaiii_survival from .initialization import initialize_nsgaiii_run from .state import NSGAIIIState, build_nsgaiii_result @@ -88,11 +88,6 @@ def __init__(self, config: dict[str, Any], kernel: KernelBackend | None = None) self._hv_tracker: HVTracker | None = None self._problem: ProblemProtocol | None = None - def _refresh_selection_metrics(self, st: NSGAIIIState) -> None: - st.selection_ranks, st.selection_crowding = nsgaiii_selection_metrics( - self.kernel, st.F, st.G, st.constraint_mode, st.constraint_handling, st.rng - ) - # ------------------------------------------------------------------------- # Main run method (batch mode) # ------------------------------------------------------------------------- @@ -166,7 +161,6 @@ def run( technique=st.constraint_handling, progress=progress, ) - self._refresh_selection_metrics(st) if ids_combined is not None: st.ids = ids_combined[survivor_indices] @@ -190,21 +184,21 @@ def run( # ------------------------------------------------------------------------- def _generate_offspring(self, st: NSGAIIIState) -> DecisionArray: - """Generate offspring using tournament selection and variation.""" + """Generate offspring using the configured parent selection and variation.""" n_var = st.X.shape[1] request_size = capped_offspring_size(st.n_eval, self._max_eval, st.pop_size, "NSGA-III") n_parents = 2 * int(np.ceil(request_size / 2)) - if st.selection_ranks is None or st.selection_crowding is None or st.selection_ranks.shape[0] != st.F.shape[0]: - self._refresh_selection_metrics(st) - assert st.selection_ranks is not None - assert st.selection_crowding is not None - parents_idx = self.kernel.tournament_selection( - st.selection_ranks, - st.selection_crowding, + parents_idx = nsgaiii_parents( + st.selection_method, st.pressure, + self.kernel, + st.F, + st.G, + st.constraint_mode, + st.constraint_handling, st.rng, - n_parents=n_parents, + n_parents, ) X_parents = st.X[parents_idx].reshape(-1, 2, n_var) @@ -335,7 +329,6 @@ def tell(self, eval_result: Any, problem: ProblemProtocol | None = None) -> bool technique=st.constraint_handling, progress=run_progress(st.n_eval, st.max_evals), ) - self._refresh_selection_metrics(st) if ids_combined is not None: st.ids = ids_combined[survivor_indices] diff --git a/src/vamos/engine/algorithm/nsgaiii/state.py b/src/vamos/engine/algorithm/nsgaiii/state.py index 203cd2bf9..f340bf38d 100644 --- a/src/vamos/engine/algorithm/nsgaiii/state.py +++ b/src/vamos/engine/algorithm/nsgaiii/state.py @@ -34,8 +34,10 @@ class NSGAIIIState(AlgorithmState): Reference directions for diversity maintenance. ref_dirs_norm : np.ndarray[Any, Any] Normalized reference directions. + selection_method : str + Parent selection, ``"random"`` or ``"tournament"``. pressure : int - Tournament selection pressure. + Tournament size of ``"tournament"``. crossover_fn : Callable Crossover operator function. mutation_fn : Callable @@ -44,6 +46,7 @@ class NSGAIIIState(AlgorithmState): ref_dirs: np.ndarray[Any, Any] = field(default_factory=lambda: np.array([])) ref_dirs_norm: np.ndarray[Any, Any] = field(default_factory=lambda: np.array([])) + selection_method: str = "random" pressure: int = 2 crossover_fn: Callable[[np.ndarray[Any, Any]], np.ndarray[Any, Any]] | None = None mutation_fn: Callable[[np.ndarray[Any, Any]], np.ndarray[Any, Any]] | None = None @@ -51,8 +54,6 @@ class NSGAIIIState(AlgorithmState): ideal_point: np.ndarray[Any, Any] = field(default_factory=lambda: np.array([])) worst_point: np.ndarray[Any, Any] = field(default_factory=lambda: np.array([])) extreme_points: np.ndarray[Any, Any] | None = None - selection_ranks: np.ndarray[Any, Any] | None = field(default=None, repr=False, compare=False) - selection_crowding: np.ndarray[Any, Any] | None = field(default=None, repr=False, compare=False) def build_nsgaiii_result( diff --git a/src/vamos/engine/tuning/racing/_bridge_assignment_builders.py b/src/vamos/engine/tuning/racing/_bridge_assignment_builders.py index 19c54e8c1..b3bfc9d75 100644 --- a/src/vamos/engine/tuning/racing/_bridge_assignment_builders.py +++ b/src/vamos/engine/tuning/racing/_bridge_assignment_builders.py @@ -216,7 +216,13 @@ def build_nsgaiii_config(assignment: dict[str, Any], *, mixed: bool = False) -> apply_mutation_prob_factor(builder, assignment, mut_params, factor_field=True) extend_mutation_params(mut, assignment, mut_params, mixed=mixed) builder.mutation(mut, **mut_params) - builder.selection("tournament", size=int(assignment["selection_pressure"])) + # Development after 1.4.0: the spaces choose random parents (the default) or a tournament. An assignment + # of an earlier space names only the tournament size, and still builds that tournament. + selection = str(assignment.get("selection", "tournament" if "selection_pressure" in assignment else "random")) + if selection == "tournament": + builder.selection(selection, size=int(assignment.get("selection_pressure", 2))) + else: + builder.selection(selection) apply_optional_repair(builder, assignment) apply_optional_external_archive(builder, assignment, pop_size) apply_constraint_handling(builder, assignment) diff --git a/src/vamos/experiment/cli/args_core.py b/src/vamos/experiment/cli/args_core.py index 4bd271a13..d8a71e1eb 100644 --- a/src/vamos/experiment/cli/args_core.py +++ b/src/vamos/experiment/cli/args_core.py @@ -128,7 +128,10 @@ def add_core_arguments( "--selection-pressure", type=int, default=spec_default(experiment_defaults, "selection_pressure", 2), - help=("Tournament size for selection operators (default: %(default)s). Applies to NSGA-II/III and SMS-EMOA."), + help=( + "Tournament size for selection operators (default: %(default)s). Applies to the default tournaments of NSGA-II and IBEA; " + "NSGA-III and SMS-EMOA select parents at random unless their config block sets a tournament and its size." + ), ) add_spec_argument( parser, diff --git a/src/vamos/experiment/cli/orchestration.py b/src/vamos/experiment/cli/orchestration.py index c4e0b7c77..59c4d9672 100644 --- a/src/vamos/experiment/cli/orchestration.py +++ b/src/vamos/experiment/cli/orchestration.py @@ -26,8 +26,9 @@ from vamos.foundation.problem.registry import ProblemSelection, make_problem_selection from vamos.foundation.problem.resolver import resolve_problem_selections -# Algorithms whose tournament reads the selection pressure ("both" runs them too). -_TOURNAMENT_ALGORITHMS = ("nsgaii", "nsgaiii", "spea2", "ibea", "both") +# Algorithms whose tournament reads the selection pressure ("both" runs them too). Development after +# 1.4.0: NSGA-III is not one of them; it selects its parents at random unless its block sets a tournament. +_TOURNAMENT_ALGORITHMS = ("nsgaii", "spea2", "ibea", "both") # Algorithms with CLI variation options, and their flag spelling when it differs from the name. _VARIATION_ALGORITHMS = ("nsgaii", "moead", "smsemoa", "nsgaiii", "agemoea", "rvea") _VARIATION_FLAGS = {"nsgaiii": "nsga3"} diff --git a/src/vamos/resources/parameter_spaces/nsgaiii.yaml b/src/vamos/resources/parameter_spaces/nsgaiii.yaml index 0ff118a67..2e50e067f 100644 --- a/src/vamos/resources/parameter_spaces/nsgaiii.yaml +++ b/src/vamos/resources/parameter_spaces/nsgaiii.yaml @@ -7,7 +7,17 @@ algorithm: nsgaiii encoding: real description: The real-coded tuning space of NSGA-III. parameters: - tournament_size: {type: int, default: 2, range: [2, 10], role: structural} + # Development after 1.4.0: the parent selection, as Evolver's: random (Deb and Jain's, the default) + # or a tournament on rank (jMetal's). The spaces of VAMOS 1.4.0 only sized a tournament on rank and crowding. + selection: + type: categorical + default: random + role: structural + values: + random: {} + tournament: + conditional_parameters: + tournament_size: {type: int, default: 2, range: [2, 10], role: structural} external_archive: type: categorical default: none diff --git a/src/vamos/resources/parameter_spaces/nsgaiii_binary.yaml b/src/vamos/resources/parameter_spaces/nsgaiii_binary.yaml index 2ff1e4a50..d053cb993 100644 --- a/src/vamos/resources/parameter_spaces/nsgaiii_binary.yaml +++ b/src/vamos/resources/parameter_spaces/nsgaiii_binary.yaml @@ -7,7 +7,17 @@ algorithm: nsgaiii encoding: binary description: The binary tuning space of NSGA-III. parameters: - tournament_size: {type: int, default: 2, range: [2, 10], role: structural} + # Development after 1.4.0: the parent selection, as Evolver's: random (Deb and Jain's, the default) + # or a tournament on rank (jMetal's). The spaces of VAMOS 1.4.0 only sized a tournament on rank and crowding. + selection: + type: categorical + default: random + role: structural + values: + random: {} + tournament: + conditional_parameters: + tournament_size: {type: int, default: 2, range: [2, 10], role: structural} external_archive: type: categorical default: none diff --git a/src/vamos/resources/parameter_spaces/nsgaiii_constrained.yaml b/src/vamos/resources/parameter_spaces/nsgaiii_constrained.yaml index e3f2ae51b..29ab9be8f 100644 --- a/src/vamos/resources/parameter_spaces/nsgaiii_constrained.yaml +++ b/src/vamos/resources/parameter_spaces/nsgaiii_constrained.yaml @@ -7,7 +7,17 @@ algorithm: nsgaiii encoding: real description: The real-coded tuning space of NSGA-III, with the constraint-handling technique. parameters: - tournament_size: {type: int, default: 2, range: [2, 10], role: structural} + # Development after 1.4.0: the parent selection, as Evolver's: random (Deb and Jain's, the default) + # or a tournament on rank (jMetal's). The spaces of VAMOS 1.4.0 only sized a tournament on rank and crowding. + selection: + type: categorical + default: random + role: structural + values: + random: {} + tournament: + conditional_parameters: + tournament_size: {type: int, default: 2, range: [2, 10], role: structural} external_archive: type: categorical default: none diff --git a/src/vamos/resources/parameter_spaces/nsgaiii_integer.yaml b/src/vamos/resources/parameter_spaces/nsgaiii_integer.yaml index 46277e6e5..6aed0d684 100644 --- a/src/vamos/resources/parameter_spaces/nsgaiii_integer.yaml +++ b/src/vamos/resources/parameter_spaces/nsgaiii_integer.yaml @@ -7,7 +7,17 @@ algorithm: nsgaiii encoding: integer description: The integer tuning space of NSGA-III. parameters: - tournament_size: {type: int, default: 2, range: [2, 10], role: structural} + # Development after 1.4.0: the parent selection, as Evolver's: random (Deb and Jain's, the default) + # or a tournament on rank (jMetal's). The spaces of VAMOS 1.4.0 only sized a tournament on rank and crowding. + selection: + type: categorical + default: random + role: structural + values: + random: {} + tournament: + conditional_parameters: + tournament_size: {type: int, default: 2, range: [2, 10], role: structural} external_archive: type: categorical default: none diff --git a/src/vamos/resources/parameter_spaces/nsgaiii_mixed.yaml b/src/vamos/resources/parameter_spaces/nsgaiii_mixed.yaml index 5d1924719..c86f877ac 100644 --- a/src/vamos/resources/parameter_spaces/nsgaiii_mixed.yaml +++ b/src/vamos/resources/parameter_spaces/nsgaiii_mixed.yaml @@ -7,7 +7,17 @@ algorithm: nsgaiii encoding: mixed description: The mixed tuning space of NSGA-III. parameters: - tournament_size: {type: int, default: 2, range: [2, 10], role: structural} + # Development after 1.4.0: the parent selection, as Evolver's: random (Deb and Jain's, the default) + # or a tournament on rank (jMetal's). The spaces of VAMOS 1.4.0 only sized a tournament on rank and crowding. + selection: + type: categorical + default: random + role: structural + values: + random: {} + tournament: + conditional_parameters: + tournament_size: {type: int, default: 2, range: [2, 10], role: structural} external_archive: type: categorical default: none diff --git a/src/vamos/resources/parameter_spaces/nsgaiii_permutation.yaml b/src/vamos/resources/parameter_spaces/nsgaiii_permutation.yaml index 2e93083fb..666034733 100644 --- a/src/vamos/resources/parameter_spaces/nsgaiii_permutation.yaml +++ b/src/vamos/resources/parameter_spaces/nsgaiii_permutation.yaml @@ -7,7 +7,17 @@ algorithm: nsgaiii encoding: permutation description: The permutation tuning space of NSGA-III. parameters: - tournament_size: {type: int, default: 2, range: [2, 10], role: structural} + # Development after 1.4.0: the parent selection, as Evolver's: random (Deb and Jain's, the default) + # or a tournament on rank (jMetal's). The spaces of VAMOS 1.4.0 only sized a tournament on rank and crowding. + selection: + type: categorical + default: random + role: structural + values: + random: {} + tournament: + conditional_parameters: + tournament_size: {type: int, default: 2, range: [2, 10], role: structural} external_archive: type: categorical default: none diff --git a/tests/compatibility/v1_0_0/stable_algorithm_configs.json b/tests/compatibility/v1_0_0/stable_algorithm_configs.json index b8c8c9889..ff9f32a24 100644 --- a/tests/compatibility/v1_0_0/stable_algorithm_configs.json +++ b/tests/compatibility/v1_0_0/stable_algorithm_configs.json @@ -413,7 +413,7 @@ "repair": "auto", "result_mode": "population", "selection": [ - "tournament", + "random", {} ], "track_genealogy": false diff --git a/tests/engine/data/parameter_space_snapshot.json b/tests/engine/data/parameter_space_snapshot.json index daecf191f..bc75029b0 100644 --- a/tests/engine/data/parameter_space_snapshot.json +++ b/tests/engine/data/parameter_space_snapshot.json @@ -27,12 +27,12 @@ "nsgaii_integer": {"sha256":"4d392452a910570866f3169ea45f6d773c5334b987d513c4aa57a82e82cccbe2","configurations":[{"pop_size":100,"crossover":["sbx",{"prob":0.9,"eta":20.0}],"mutation":["polynomial",{"eta":20.0}],"selection":["tournament",{"size":2}],"offspring_size":100,"steady_state":false,"replacement_size":null,"repair":"auto","external_archive":null,"initializer":{"type":"random"},"mutation_prob_factor":1.0,"result_mode":"non_dominated","constraint_mode":"feasibility","track_genealogy":false,"immigration":null,"parent_selection_filter":null,"live_callback_mode":"nd_only","generation_callback":null,"generation_callback_copy":true,"constraint_handling":null},{"pop_size":100,"crossover":["uniform",{"prob":0.6163894095744779}],"mutation":["reset",{}],"selection":["ranking",{}],"offspring_size":100,"steady_state":false,"replacement_size":null,"repair":"auto","external_archive":{"capacity":null,"hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"initializer":{"type":"random"},"mutation_prob_factor":2.486493157800749,"result_mode":"non_dominated","constraint_mode":"feasibility","track_genealogy":false,"immigration":null,"parent_selection_filter":null,"live_callback_mode":"nd_only","generation_callback":null,"generation_callback_copy":true,"constraint_handling":null},{"pop_size":100,"crossover":["arithmetic",{"prob":0.8917986243935994}],"mutation":["gaussian",{"sigma":4.097682415195508}],"selection":["ranking",{}],"offspring_size":1,"steady_state":false,"replacement_size":null,"repair":"auto","external_archive":{"capacity":100,"pruning":"knn","hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"initializer":{"type":"random"},"mutation_prob_factor":2.8214491654163627,"result_mode":"non_dominated","constraint_mode":"feasibility","track_genealogy":false,"immigration":null,"parent_selection_filter":null,"live_callback_mode":"nd_only","generation_callback":null,"generation_callback_copy":true,"constraint_handling":null},{"pop_size":100,"crossover":["arithmetic",{"prob":0.6134342301221857}],"mutation":["boundary",{}],"selection":["ranking",{}],"offspring_size":50,"steady_state":false,"replacement_size":null,"repair":"auto","external_archive":null,"initializer":{"type":"random"},"mutation_prob_factor":2.2565524776823462,"result_mode":"non_dominated","constraint_mode":"feasibility","track_genealogy":false,"immigration":null,"parent_selection_filter":null,"live_callback_mode":"nd_only","generation_callback":null,"generation_callback_copy":true,"constraint_handling":null}]}, "nsgaii_mixed": {"sha256":"579452feaf813c0bc096293f017188c145371cbe16c8266907097c3d078abdc7","configurations":[{"pop_size":100,"crossover":["mixed",{"prob":0.9}],"mutation":["mixed",{}],"selection":["tournament",{"size":2}],"offspring_size":100,"steady_state":false,"replacement_size":null,"repair":"auto","external_archive":null,"initializer":{"type":"random"},"mutation_prob_factor":1.0,"result_mode":"non_dominated","constraint_mode":"feasibility","track_genealogy":false,"immigration":null,"parent_selection_filter":null,"live_callback_mode":"nd_only","generation_callback":null,"generation_callback_copy":true,"constraint_handling":null},{"pop_size":100,"crossover":["mixed",{"prob":0.6163894095744779}],"mutation":["mixed",{}],"selection":["ranking",{}],"offspring_size":100,"steady_state":false,"replacement_size":null,"repair":"auto","external_archive":{"capacity":null,"hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"initializer":{"type":"random"},"mutation_prob_factor":2.486493157800749,"result_mode":"non_dominated","constraint_mode":"feasibility","track_genealogy":false,"immigration":null,"parent_selection_filter":null,"live_callback_mode":"nd_only","generation_callback":null,"generation_callback_copy":true,"constraint_handling":null},{"pop_size":100,"crossover":["mixed",{"perm_crossover":"aex","perm_crossover_prob":0.8174499965861691,"real_crossover":"mean","real_crossover_prob":0.9740289695151073,"int_crossover":"uniform","int_crossover_prob":0.6010954000680592,"cat_crossover":"uniform","cat_crossover_prob":0.9429617106350278}],"mutation":["mixed",{"perm_mutation":"inversion","perm_mutation_prob":0.3675311687506726,"real_mutation":"gaussian","real_mutation_prob":0.09607125409525391,"real_mutation_sigma_factor":0.4329576719514444,"int_mutation":"reset","int_mutation_prob":0.15685882636331855,"cat_mutation":"reset","cat_mutation_prob":0.21711673838685264}],"selection":["ranking",{}],"offspring_size":1,"steady_state":false,"replacement_size":null,"repair":"auto","external_archive":{"capacity":100,"pruning":"knn","hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"initializer":{"type":"random"},"mutation_prob_factor":null,"result_mode":"non_dominated","constraint_mode":"feasibility","track_genealogy":false,"immigration":null,"parent_selection_filter":null,"live_callback_mode":"nd_only","generation_callback":null,"generation_callback_copy":true,"constraint_handling":null},{"pop_size":100,"crossover":["mixed",{"prob":0.8682497658774522}],"mutation":["mixed",{}],"selection":["boltzmann",{}],"offspring_size":50,"steady_state":false,"replacement_size":null,"repair":"auto","external_archive":null,"initializer":{"type":"random"},"mutation_prob_factor":2.0297711568291876,"result_mode":"non_dominated","constraint_mode":"feasibility","track_genealogy":false,"immigration":null,"parent_selection_filter":null,"live_callback_mode":"nd_only","generation_callback":null,"generation_callback_copy":true,"constraint_handling":null}]}, "nsgaii_permutation": {"sha256":"c02bcfb590abd8e460074b8a75883cc0e23574720b26f72e4929047a0fe61cb2","configurations":[{"pop_size":100,"crossover":["ox",{"prob":1.0}],"mutation":["swap",{}],"selection":["tournament",{"size":2}],"offspring_size":100,"steady_state":false,"replacement_size":null,"repair":"auto","external_archive":null,"initializer":{"type":"random"},"mutation_prob_factor":2.0,"result_mode":"non_dominated","constraint_mode":"feasibility","track_genealogy":false,"immigration":null,"parent_selection_filter":null,"live_callback_mode":"nd_only","generation_callback":null,"generation_callback_copy":true,"constraint_handling":null},{"pop_size":100,"crossover":["pmx",{"prob":0.6163894095744779}],"mutation":["swap",{}],"selection":["ranking",{}],"offspring_size":100,"steady_state":false,"replacement_size":null,"repair":"auto","external_archive":{"capacity":null,"hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"initializer":{"type":"random"},"mutation_prob_factor":2.486493157800749,"result_mode":"non_dominated","constraint_mode":"feasibility","track_genealogy":false,"immigration":null,"parent_selection_filter":null,"live_callback_mode":"nd_only","generation_callback":null,"generation_callback_copy":true,"constraint_handling":null},{"pop_size":100,"crossover":["cycle",{"prob":0.8917986243935994}],"mutation":["inversion",{}],"selection":["ranking",{}],"offspring_size":1,"steady_state":false,"replacement_size":null,"repair":"auto","external_archive":{"capacity":100,"pruning":"knn","hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"initializer":{"type":"random"},"mutation_prob_factor":2.8214491654163627,"result_mode":"non_dominated","constraint_mode":"feasibility","track_genealogy":false,"immigration":null,"parent_selection_filter":null,"live_callback_mode":"nd_only","generation_callback":null,"generation_callback_copy":true,"constraint_handling":null},{"pop_size":100,"crossover":["ox",{"prob":0.9429617106350278}],"mutation":["inversion",{}],"selection":["random",{}],"offspring_size":50,"steady_state":false,"replacement_size":null,"repair":"auto","external_archive":{"capacity":100,"pruning":"maxmin","hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"initializer":{"type":"random"},"mutation_prob_factor":2.2565524776823462,"result_mode":"non_dominated","constraint_mode":"feasibility","track_genealogy":false,"immigration":null,"parent_selection_filter":null,"live_callback_mode":"nd_only","generation_callback":null,"generation_callback_copy":true,"constraint_handling":null}]}, - "nsgaiii": {"sha256":"450cd859a21eba50dac473201e4eb3fd7e6611b8ed41ae1504abf233753d487b","configurations":[{"pop_size":100,"crossover":["sbx",{"prob":0.9,"eta":30.0}],"mutation":["polynomial",{"eta":20.0}],"selection":["tournament",{"size":2}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":null,"mutation_prob_factor":1.0,"track_genealogy":false,"result_mode":"population","external_archive":null,"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"crossover":["sbx",{"prob":0.6163894095744779,"eta":5.578467243498518}],"mutation":["linked_polynomial",{"eta":26.232252151851295}],"selection":["tournament",{"size":9}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":["random",{}],"initializer":{"type":"lhs"},"mutation_prob_factor":2.7600778375137347,"track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":null,"hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"crossover":["blx_alpha",{"prob":0.9263414216486129,"alpha":0.002738500170148095}],"mutation":["non_uniform",{"perturbation":0.5}],"selection":["tournament",{"size":10}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":["reflect",{}],"initializer":{"type":"lhs"},"mutation_prob_factor":0.342360332090027,"track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":100,"pruning":"knn","hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"crossover":["sbx",{"prob":0.8165844880996367,"eta":15.489916168808467}],"mutation":["uniform",{"perturb":0.023876638861276854}],"selection":["tournament",{"size":8}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":null,"mutation_prob_factor":1.4123898582935608,"track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":100,"pruning":"ref_dirs","hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":null,"live_callback_mode":"population"}]}, - "nsgaiii_binary": {"sha256":"073815b820a1d2504c8dce25cf738e57be5fb5630ed574386b443e92a2f124a2","configurations":[{"pop_size":100,"crossover":["uniform",{"prob":0.9}],"mutation":["bitflip",{}],"selection":["tournament",{"size":2}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":1.0,"track_genealogy":false,"result_mode":"population","external_archive":null,"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"crossover":["one_point",{"prob":0.6163894095744779}],"mutation":["bitflip",{}],"selection":["tournament",{"size":9}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":0.295450997703455,"track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":null,"hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"crossover":["two_point",{"prob":0.842654310306872}],"mutation":["segment_inversion",{}],"selection":["tournament",{"size":3}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":1.744968726529913,"track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":100,"pruning":"knn","hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"crossover":["two_point",{"prob":0.9263414216486129}],"mutation":["segment_inversion",{}],"selection":["tournament",{"size":8}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":2.607861760615816,"track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":null,"hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":null,"live_callback_mode":"population"}]}, - "nsgaiii_constrained": {"sha256":"ffe8ca204f62d9e10f05bc157849eb9acc94ac3a38e16e54bd807b8521074871","configurations":[{"pop_size":100,"crossover":["sbx",{"prob":0.9,"eta":30.0}],"mutation":["polynomial",{"eta":20.0}],"selection":["tournament",{"size":2}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":null,"mutation_prob_factor":1.0,"track_genealogy":false,"result_mode":"population","external_archive":null,"constraint_handling":["cdp",{}],"live_callback_mode":"population"},{"pop_size":100,"crossover":["sbx",{"prob":0.6163894095744779,"eta":5.578467243498518}],"mutation":["linked_polynomial",{"eta":26.232252151851295}],"selection":["tournament",{"size":9}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":["random",{}],"initializer":{"type":"lhs"},"mutation_prob_factor":2.7600778375137347,"track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":null,"hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":["self_adaptive_penalty",{}],"live_callback_mode":"population"},{"pop_size":100,"crossover":["blx_alpha",{"prob":0.9263414216486129,"alpha":0.002738500170148095}],"mutation":["non_uniform",{"perturbation":0.5}],"selection":["tournament",{"size":8}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":["reflect",{}],"initializer":{"type":"lhs"},"mutation_prob_factor":0.342360332090027,"track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":null,"hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":["stochastic_ranking",{"probability":0.08782781030127951}],"live_callback_mode":"population"},{"pop_size":100,"crossover":["blx_alpha",{"prob":0.719884756214954,"alpha":0.42268722119765845}],"mutation":["polynomial",{"eta":28.471854514277062}],"selection":["tournament",{"size":8}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":["random",{}],"initializer":{"type":"scatter","base_size":10},"mutation_prob_factor":0.5917790103738009,"track_genealogy":false,"result_mode":"population","external_archive":null,"constraint_handling":["push_pull",{"change_threshold":0.030807717062914568,"window_fraction":0.044530979883569514,"decay_fraction":0.9476284454208294,"exponent":9.827518048986072,"feasibility_threshold":0.8427709922403473,"reduction_rate":0.32872504537123}],"live_callback_mode":"population"}]}, - "nsgaiii_integer": {"sha256":"c2b8d92fc99102e6e30da9fd5dbcf8141d72908faf43b67a837489523209149c","configurations":[{"pop_size":100,"crossover":["sbx",{"prob":0.9,"eta":20.0}],"mutation":["polynomial",{"eta":20.0}],"selection":["tournament",{"size":2}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":1.0,"track_genealogy":false,"result_mode":"population","external_archive":null,"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"crossover":["arithmetic",{"prob":0.6163894095744779}],"mutation":["creep",{"step":1}],"selection":["tournament",{"size":9}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":0.295450997703455,"track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":null,"hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"crossover":["sbx",{"prob":0.842654310306872,"eta":30.532379634439945}],"mutation":["gaussian",{"sigma":4.097682415195508}],"selection":["tournament",{"size":9}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":2.8214491654163627,"track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":null,"hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"crossover":["arithmetic",{"prob":0.6134342301221857}],"mutation":["boundary",{}],"selection":["tournament",{"size":6}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":2.2565524776823462,"track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":100,"pruning":"crowding","hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":null,"live_callback_mode":"population"}]}, - "nsgaiii_mixed": {"sha256":"96bb2c0b2d7d60eb119132733b22bc7095d63e7c891e38d9b89e5d9bb51c5cbc","configurations":[{"pop_size":100,"crossover":["mixed",{"prob":0.9}],"mutation":["mixed",{}],"selection":["tournament",{"size":2}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":1.0,"track_genealogy":false,"result_mode":"population","external_archive":null,"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"crossover":["mixed",{"perm_crossover":"pmx","perm_crossover_prob":0.6163894095744779,"real_crossover":"arithmetic","real_crossover_prob":0.925308095680109,"int_crossover":"uniform","int_crossover_prob":0.9651022309110887,"cat_crossover":"uniform","cat_crossover_prob":0.842654310306872}],"mutation":["mixed",{"perm_mutation":"displacement","perm_mutation_prob":0.2763762458180572,"real_mutation":"uniform_reset","real_mutation_prob":0.40976824151955077,"int_mutation":"polynomial","int_mutation_prob":0.011341865083372567,"int_mutation_eta":35.00914968056493,"cat_mutation":"reset","cat_mutation_prob":0.026456931899677537}],"selection":["tournament",{"size":9}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":null,"track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":null,"hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"crossover":["mixed",{"prob":0.9452715689399547}],"mutation":["mixed",{}],"selection":["tournament",{"size":8}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":1.0742076989778082,"track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":100,"pruning":"ref_dirs","hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"crossover":["mixed",{"prob":0.6113278684581852}],"mutation":["mixed",{}],"selection":["tournament",{"size":6}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":2.0942171404074834,"track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":null,"hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":null,"live_callback_mode":"population"}]}, - "nsgaiii_permutation": {"sha256":"df65e93e72350d54be78d24310754b34fd8472b0c94cf1c36625edb6d67233d5","configurations":[{"pop_size":100,"crossover":["ox",{"prob":0.9}],"mutation":["swap",{"prob":0.1}],"selection":["tournament",{"size":2}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":null,"track_genealogy":false,"result_mode":"population","external_archive":null,"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"crossover":["cycle",{"prob":0.6163894095744779}],"mutation":["insert",{"prob":0.018098541408979256}],"selection":["tournament",{"size":9}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":null,"track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":null,"hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"crossover":["aex",{"prob":0.842654310306872}],"mutation":["two_opt",{"prob":0.2763762458180572}],"selection":["tournament",{"size":3}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":null,"track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":100,"pruning":"knn","hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"crossover":["aex",{"prob":0.9263414216486129}],"mutation":["displacement",{"prob":0.430128095527909}],"selection":["tournament",{"size":8}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":null,"track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":null,"hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":null,"live_callback_mode":"population"}]}, + "nsgaiii": {"sha256":"c57f63962aa06d1225e7e3462e399a0f679f1033403f0e184835af39ce6486dd","configurations":[{"pop_size":100,"crossover":["sbx",{"prob":0.9,"eta":30.0}],"mutation":["polynomial",{"eta":20.0}],"selection":["random",{}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":null,"mutation_prob_factor":1.0,"track_genealogy":false,"result_mode":"population","external_archive":null,"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"crossover":["sbx",{"prob":0.6066110542114116,"eta":33.46445837200953}],"mutation":["polynomial",{"eta":26.232252151851295}],"selection":["tournament",{"size":7}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":["random",{}],"initializer":{"type":"random"},"mutation_prob_factor":2.7600778375137347,"track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":null,"hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"crossover":["arithmetic",{"prob":0.9263414216486129}],"mutation":["uniform_reset",{}],"selection":["tournament",{"size":7}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":{"type":"lhs"},"mutation_prob_factor":2.607861760615816,"track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":null,"hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"crossover":["sbx",{"prob":0.8165844880996367,"eta":15.489916168808467}],"mutation":["uniform",{"perturb":0.023876638861276854}],"selection":["tournament",{"size":2}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":{"type":"scatter","base_size":20},"mutation_prob_factor":1.4123898582935608,"track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":100,"pruning":"maxmin","hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":null,"live_callback_mode":"population"}]}, + "nsgaiii_binary": {"sha256":"985c2aea329fd2d66f095c09a2f7c14b460e39701cc20087c80d6b3288ae486a","configurations":[{"pop_size":100,"crossover":["uniform",{"prob":0.9}],"mutation":["bitflip",{}],"selection":["random",{}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":1.0,"track_genealogy":false,"result_mode":"population","external_archive":null,"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"crossover":["uniform",{"prob":0.6163894095744779}],"mutation":["bitflip",{}],"selection":["tournament",{"size":7}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":2.486493157800749,"track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":null,"hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"crossover":["two_point",{"prob":0.842654310306872}],"mutation":["segment_inversion",{}],"selection":["random",{}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":1.744968726529913,"track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":null,"hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"crossover":["two_point",{"prob":0.6010954000680592}],"mutation":["bitflip",{}],"selection":["tournament",{"size":7}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":0.342360332090027,"track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":100,"pruning":"hv","hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":null,"live_callback_mode":"population"}]}, + "nsgaiii_constrained": {"sha256":"3f9b998e15980e26dd525c521e6c2ee18687beba186cd0f5517fbda0ca67276a","configurations":[{"pop_size":100,"crossover":["sbx",{"prob":0.9,"eta":30.0}],"mutation":["polynomial",{"eta":20.0}],"selection":["random",{}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":null,"mutation_prob_factor":1.0,"track_genealogy":false,"result_mode":"population","external_archive":null,"constraint_handling":["cdp",{}],"live_callback_mode":"population"},{"pop_size":100,"crossover":["sbx",{"prob":0.6066110542114116,"eta":33.46445837200953}],"mutation":["polynomial",{"eta":26.232252151851295}],"selection":["tournament",{"size":7}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":["random",{}],"initializer":{"type":"random"},"mutation_prob_factor":2.7600778375137347,"track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":null,"hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":["stochastic_ranking",{"probability":0.27181249573271143}],"live_callback_mode":"population"},{"pop_size":100,"crossover":["sbx",{"prob":0.9429617106350278,"eta":6.175495135691253}],"mutation":["cauchy",{"gamma":0.4317262822525934}],"selection":["tournament",{"size":10}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":["reflect",{}],"initializer":{"type":"scatter","base_size":75},"mutation_prob_factor":0.7330529566570373,"track_genealogy":false,"result_mode":"population","external_archive":null,"constraint_handling":["cdp",{}],"live_callback_mode":"population"},{"pop_size":100,"crossover":["blx_alpha",{"prob":0.6113278684581852,"alpha":0.12428327649956394}],"mutation":["uniform_reset",{}],"selection":["tournament",{"size":2}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":["clip",{}],"initializer":{"type":"random"},"mutation_prob_factor":2.0297711568291876,"track_genealogy":false,"result_mode":"population","external_archive":null,"constraint_handling":["push_pull",{"change_threshold":0.019245509957667984,"window_fraction":0.09974889422102899,"decay_fraction":0.9337100379597956,"exponent":7.1698778603262525,"feasibility_threshold":0.8252296381339081,"reduction_rate":0.34733889797976064}],"live_callback_mode":"population"}]}, + "nsgaiii_integer": {"sha256":"c66295fc24851e90efc80a476322a965efdb0967c259db6ac29a2ebe2a07b898","configurations":[{"pop_size":100,"crossover":["sbx",{"prob":0.9,"eta":20.0}],"mutation":["polynomial",{"eta":20.0}],"selection":["random",{}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":1.0,"track_genealogy":false,"result_mode":"population","external_archive":null,"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"crossover":["uniform",{"prob":0.6163894095744779}],"mutation":["reset",{}],"selection":["tournament",{"size":7}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":2.486493157800749,"track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":null,"hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"crossover":["sbx",{"prob":0.842654310306872,"eta":30.532379634439945}],"mutation":["gaussian",{"sigma":4.097682415195508}],"selection":["random",{}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":2.8214491654163627,"track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":null,"hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"crossover":["arithmetic",{"prob":0.6134342301221857}],"mutation":["boundary",{}],"selection":["tournament",{"size":8}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":2.2565524776823462,"track_genealogy":false,"result_mode":"population","external_archive":null,"constraint_handling":null,"live_callback_mode":"population"}]}, + "nsgaiii_mixed": {"sha256":"55b11f5a7a299faf90644c10d1ab99da6389e265552f88ce4b3a7127021b2f0f","configurations":[{"pop_size":100,"crossover":["mixed",{"prob":0.9}],"mutation":["mixed",{}],"selection":["random",{}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":1.0,"track_genealogy":false,"result_mode":"population","external_archive":null,"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"crossover":["mixed",{"prob":0.6163894095744779}],"mutation":["mixed",{}],"selection":["tournament",{"size":7}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":2.486493157800749,"track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":null,"hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"crossover":["mixed",{"perm_crossover":"cycle","perm_crossover_prob":0.8917986243935994,"real_crossover":"mean","real_crossover_prob":0.8174499965861691,"int_crossover":"arithmetic","int_crossover_prob":0.9263414216486129,"cat_crossover":"uniform","cat_crossover_prob":0.6010954000680592}],"mutation":["mixed",{"perm_mutation":"scramble","perm_mutation_prob":0.026456931899677537,"real_mutation":"polynomial","real_mutation_prob":0.3675311687506726,"real_mutation_eta":11.147946721089566,"int_mutation":"reset","int_mutation_prob":0.27531599792205497,"cat_mutation":"reset","cat_mutation_prob":0.15685882636331855}],"selection":["random",{}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":null,"track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":null,"hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"crossover":["mixed",{"prob":0.6497133105998255}],"mutation":["mixed",{}],"selection":["tournament",{"size":6}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":2.0942171404074834,"track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":null,"hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":null,"live_callback_mode":"population"}]}, + "nsgaiii_permutation": {"sha256":"22a1cb820ea153bc3bfea040e17873996d0ce149bd83320004d3a2db718c5671","configurations":[{"pop_size":100,"crossover":["ox",{"prob":0.9}],"mutation":["swap",{"prob":0.1}],"selection":["random",{}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":null,"track_genealogy":false,"result_mode":"population","external_archive":null,"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"crossover":["pmx",{"prob":0.6163894095744779}],"mutation":["swap",{"prob":0.40850241720813346}],"selection":["tournament",{"size":7}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":null,"track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":null,"hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"crossover":["aex",{"prob":0.842654310306872}],"mutation":["two_opt",{"prob":0.2763762458180572}],"selection":["random",{}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":null,"track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":null,"hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"crossover":["position",{"prob":0.6010954000680592}],"mutation":["scramble",{"prob":0.026456931899677537}],"selection":["tournament",{"size":7}],"reference_directions":{},"enforce_ref_dirs":true,"pop_size_auto":false,"constraint_mode":"feasibility","repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":null,"track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":100,"pruning":"hv","hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":null,"live_callback_mode":"population"}]}, "rvea": {"sha256":"25e9eddecb7a230ef23bf62887aafab027554ec6e47fa69aa61ec516e2bf8800","configurations":[{"pop_size":100,"n_partitions":99,"alpha":2.0,"adapt_freq":0.1,"crossover":["sbx",{"prob":0.9,"eta":30.0}],"mutation":["polynomial",{"eta":20.0}],"repair":"auto","initializer":null,"mutation_prob_factor":1.0,"constraint_mode":"feasibility","track_genealogy":false,"result_mode":"non_dominated","external_archive":null,"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"n_partitions":99,"alpha":2.910885061964363,"adapt_freq":0.11744667844096758,"crossover":["sbx",{"prob":0.925308095680109,"eta":36.94644520472026}],"mutation":["polynomial",{"eta":30.532379634439945}],"repair":["reflect",{}],"initializer":null,"mutation_prob_factor":1.9182483833597446,"constraint_mode":"feasibility","track_genealogy":false,"result_mode":"non_dominated","external_archive":null,"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"n_partitions":99,"alpha":3.8052172713633046,"adapt_freq":0.253963388530383,"crossover":["sbx",{"prob":0.9429617106350278,"eta":6.175495135691253}],"mutation":["cauchy",{"gamma":0.4317262822525934}],"repair":["reflect",{}],"initializer":{"type":"lhs"},"mutation_prob_factor":0.7330529566570373,"constraint_mode":"feasibility","track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":null,"hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"n_partitions":99,"alpha":2.624383660747275,"adapt_freq":0.1249279726343462,"crossover":["arithmetic",{"prob":0.6497133105998255}],"mutation":["polynomial",{"eta":27.651632905098754}],"repair":["clip",{}],"initializer":{"type":"random"},"mutation_prob_factor":2.0942171404074834,"constraint_mode":"feasibility","track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":null,"hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":null,"live_callback_mode":"population"}]}, "rvea_binary": {"sha256":"184d63126f5c45deafde5a1b33966f9c872f25639d6b5a0e24d88934acee5765","configurations":[{"pop_size":100,"n_partitions":99,"alpha":2.0,"adapt_freq":0.1,"crossover":["uniform",{"prob":0.9}],"mutation":["bitflip",{}],"repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":1.0,"constraint_mode":"feasibility","track_genealogy":false,"result_mode":"non_dominated","external_archive":null,"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"n_partitions":99,"alpha":2.910885061964363,"adapt_freq":0.11744667844096758,"crossover":["hux",{"prob":0.6066110542114116}],"mutation":["bitflip",{}],"repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":2.7600778375137347,"constraint_mode":"feasibility","track_genealogy":false,"result_mode":"non_dominated","external_archive":null,"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"n_partitions":99,"alpha":2.8199073273015394,"adapt_freq":0.23237414024599962,"crossover":["one_point",{"prob":0.9740289695151073}],"mutation":["bitflip",{}],"repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":0.25753087546790726,"constraint_mode":"feasibility","track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":100,"pruning":"knn","hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":null,"live_callback_mode":"population"},{"pop_size":100,"n_partitions":99,"alpha":3.572212829762708,"adapt_freq":0.05839639382636609,"crossover":["one_point",{"prob":0.6702622482410235}],"mutation":["bitflip",{}],"repair":"auto","initializer":{"type":"random"},"mutation_prob_factor":1.7390183556850023,"constraint_mode":"feasibility","track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":100,"pruning":"maxmin","hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":null,"live_callback_mode":"population"}]}, "rvea_constrained": {"sha256":"25fc244a3b2c8404e3ba5b565c0e2b3a7969d242da246d04f456e8dc9de543c7","configurations":[{"pop_size":100,"n_partitions":99,"alpha":2.0,"adapt_freq":0.1,"crossover":["sbx",{"prob":0.9,"eta":30.0}],"mutation":["polynomial",{"eta":20.0}],"repair":"auto","initializer":null,"mutation_prob_factor":1.0,"constraint_mode":"feasibility","track_genealogy":false,"result_mode":"non_dominated","external_archive":null,"constraint_handling":["cdp",{}],"live_callback_mode":"population"},{"pop_size":100,"n_partitions":99,"alpha":2.910885061964363,"adapt_freq":0.11744667844096758,"crossover":["sbx",{"prob":0.925308095680109,"eta":36.94644520472026}],"mutation":["polynomial",{"eta":30.532379634439945}],"repair":["reflect",{}],"initializer":null,"mutation_prob_factor":1.9182483833597446,"constraint_mode":"feasibility","track_genealogy":false,"result_mode":"non_dominated","external_archive":null,"constraint_handling":["epsilon_constrained",{"initial_quantile":0.8915651814089913,"exponent":8.34268198709379,"decay_fraction":0.10232772514462589}],"live_callback_mode":"population"},{"pop_size":100,"n_partitions":99,"alpha":3.572212829762708,"adapt_freq":0.05839639382636609,"crossover":["sbx",{"prob":0.8165844880996367,"eta":15.489916168808467}],"mutation":["uniform",{"perturb":0.023876638861276854}],"repair":"auto","initializer":{"type":"scatter","base_size":20},"mutation_prob_factor":1.4123898582935608,"constraint_mode":"feasibility","track_genealogy":false,"result_mode":"non_dominated","external_archive":{"capacity":100,"pruning":"maxmin","hv_ref_point":null,"rng_seed":null,"objective_tolerance":0.0,"truncate_size":null,"deduplicate_in":"objective","decision_tolerance":1e-32},"constraint_handling":["cdp",{}],"live_callback_mode":"population"},{"pop_size":100,"n_partitions":99,"alpha":3.011873244080891,"adapt_freq":0.2117973778935625,"crossover":["undx",{"prob":0.9988839743156844,"zeta":0.982751804898607,"eta":0.7169877860326253}],"mutation":["non_uniform",{"perturbation":0.5}],"repair":["random",{}],"initializer":{"type":"lhs"},"mutation_prob_factor":2.0387630097364946,"constraint_mode":"feasibility","track_genealogy":false,"result_mode":"non_dominated","external_archive":null,"constraint_handling":["epsilon_constrained",{"initial_quantile":0.4000292815811934,"exponent":2.215868545201701,"decay_fraction":0.7132650891649694}],"live_callback_mode":"population"}]}, diff --git a/tests/engine/test_algorithm_encodings.py b/tests/engine/test_algorithm_encodings.py index 18d1c057c..f55844815 100644 --- a/tests/engine/test_algorithm_encodings.py +++ b/tests/engine/test_algorithm_encodings.py @@ -73,7 +73,6 @@ def test_nsgaiii_permutation_encoding_defaults(mock_kernel): problem=problem, pop_size=100, nsgaiii_variation=None, - selection_pressure=2, ) cfg_dict = config.to_dict() @@ -97,14 +96,12 @@ def test_nsgaiii_real_encoding_uses_the_reference_sbx(mock_kernel): problem=MockRealProblem(), pop_size=92, nsgaiii_variation=None, - selection_pressure=2, ) _, tuned = build_nsgaiii_algorithm( kernel=mock_kernel, problem=MockRealProblem(), pop_size=92, nsgaiii_variation={"crossover": {"method": "sbx", "eta": 15.0}}, - selection_pressure=2, ) assert config.to_dict()["crossover"] == ("sbx", {"prob": 0.9, "eta": 30.0}) diff --git a/tests/engine/test_nsgaiii_selection.py b/tests/engine/test_nsgaiii_selection.py new file mode 100644 index 000000000..f05d8feb2 --- /dev/null +++ b/tests/engine/test_nsgaiii_selection.py @@ -0,0 +1,276 @@ +"""NSGA-III's parent selection: random parents (Deb and Jain, 2014) or jMetal's tournament on rank. + +Development after 1.4.0: VAMOS 1.4.0 and earlier ran a binary tournament on rank and crowding +distance, as NSGA-II, whatever the configured selection. These tests use a front where crowding +distance would pick the two extremes (their distance is infinite) whenever they enter a tournament. +""" + +from __future__ import annotations + +import numpy as np +import pytest + +from vamos import optimize +from vamos.algorithms import NSGAIIIConfig +from vamos.engine.algorithm.components.constraint_handling import ConstraintHandlingTechnique, run_technique +from vamos.engine.algorithm.config.nsgaiii import nsgaiii_selection +from vamos.engine.algorithm.factory import build_algorithm +from vamos.engine.algorithm.nsgaiii import NSGAIII +from vamos.engine.algorithm.nsgaiii.helpers import nsgaiii_parents +from vamos.engine.tuning import config_from_assignment +from vamos.engine.tuning.grammar import builtin_parameter_space, builtin_parameter_space_names +from vamos.engine.tuning.racing.parameter_names import from_evolver, to_evolver +from vamos.foundation.core.experiment_config import ExperimentConfig +from vamos.foundation.exceptions import ConfigurationError +from vamos.foundation.kernel.backend import KernelBackend +from vamos.foundation.kernel.numba_backend import NumbaKernel +from vamos.foundation.kernel.numpy_backend import NumPyKernel +from vamos.foundation.problem.dtlz import DTLZ2Problem + +DRAWS = 20_000 + + +def _line_front(n: int) -> np.ndarray: + """``n`` mutually non-dominated points on f1 + f2 = 1: crowding distance favours the two ends.""" + f1 = np.linspace(0.0, 1.0, n) + return np.column_stack([f1, 1.0 - f1]) + + +def _frequencies(parents: np.ndarray, n: int) -> np.ndarray: + return np.bincount(parents, minlength=n) / parents.size + + +def _parents( + method: str, + F: np.ndarray, + *, + G: np.ndarray | None = None, + seed: int = 0, + pressure: int = 2, + kernel: KernelBackend | None = None, + constraint_mode: str = "feasibility", + technique: ConstraintHandlingTechnique | None = None, +) -> np.ndarray: + rng = np.random.default_rng(seed) + return nsgaiii_parents(method, pressure, kernel or NumPyKernel(), F, G, constraint_mode, technique, rng, DRAWS) + + +def _config(**selection: object) -> NSGAIIIConfig: + method = str(selection.pop("method", "random")) + return ( + NSGAIIIConfig.builder() + .pop_size(10) + .crossover("sbx", prob=0.9, eta=30.0) + .mutation("pm", prob="1/n", eta=20.0) + .selection(method, **selection) + .reference_directions(divisions=3) + .build() + ) + + +class _NoTournamentKernel(NumPyKernel): + def tournament_selection(self, *args: object, **kwargs: object) -> np.ndarray: + raise AssertionError("random selection of an unconstrained run ran a tournament") + + +# ---- random ------------------------------------------------------------------- + + +def test_random_parents_do_not_depend_on_ranks_or_crowding() -> None: + n = 10 + front = _line_front(n) + # The same rows dominated in a chain: ranks 0 to 9, and crowding distance 0 inside each front. + chain = np.column_stack([np.arange(n, dtype=float), np.arange(n, dtype=float)]) + + parents = _parents("random", front, seed=3) + + assert np.array_equal(parents, _parents("random", chain, seed=3)) + assert np.array_equal(parents, np.random.default_rng(3).integers(0, n, size=DRAWS, dtype=int)) + + +def test_random_parents_are_uniform_where_crowding_would_pick_the_extremes() -> None: + n = 10 + frequencies = _frequencies(_parents("random", _line_front(n)), n) + + # Each individual 1/n (the standard error is 0.002); crowding gave each extreme about twice that. + assert np.allclose(frequencies, 1.0 / n, atol=0.01) + + +def test_a_random_run_never_runs_a_tournament() -> None: + problem = DTLZ2Problem(n_var=12, n_obj=3) + + result = NSGAIII(_config().to_dict(), kernel=_NoTournamentKernel()).run(problem, termination=("max_evaluations", 60), seed=1) + + assert result["evaluations"] == 60 + + +def test_random_parents_with_constraints_win_a_tournament_on_the_violation() -> None: + # Jain and Deb (2014) and pymoo: feasible beats infeasible, the smaller violation wins, and a tie is drawn. + n = 10 + G = np.array([[-1.0]] * 5 + [[0.5], [1.0], [2.0], [3.0], [4.0]]) + + frequencies = _frequencies(_parents("random", _line_front(n), G=G), n) + + assert frequencies[9] == 0.0 # the most violated row loses every tournament it enters + # A feasible row wins unless it meets a feasible one and loses the draw: 2/n - 4/(n (n - 1)) each. + assert np.allclose(frequencies[:5], 2 / n - 4 / (n * (n - 1)), atol=0.01) + assert np.all(np.diff(frequencies[5:]) < 0) + + +def test_random_parents_ignore_the_constraints_without_feasibility_first() -> None: + n = 10 + G = np.array([[-1.0]] * 5 + [[0.5], [1.0], [2.0], [3.0], [4.0]]) + technique = run_technique(("violated_constraints", {}), "feasibility") + assert technique is not None + + ignored = _frequencies(_parents("random", _line_front(n), G=G, constraint_mode="none"), n) + with_technique = _frequencies(_parents("random", _line_front(n), G=G, technique=technique), n) + + assert np.allclose(ignored, 1.0 / n, atol=0.01) + assert np.allclose(with_technique, 1.0 / n, atol=0.01) + + +# ---- tournament --------------------------------------------------------------- + + +@pytest.mark.parametrize("kernel", [NumPyKernel(), NumbaKernel()], ids=["numpy", "numba"]) +def test_the_tournament_compares_ranks_and_not_crowding(kernel: KernelBackend) -> None: + n = 10 + # A front of five on the line, where crowding would pick rows 0 and 4, and five dominated rows. + F = np.vstack([_line_front(5), _line_front(5) + 1.0]) + + frequencies = _frequencies(_parents("tournament", F, kernel=kernel), n) + + # A dominated row wins only against another dominated row: (5/n) (4/(n - 1)) of the tournaments. + assert frequencies[5:].sum() == pytest.approx(20 / (n * (n - 1)), abs=0.01) + # The ties are drawn, so the extremes of each front are not preferred. + assert np.allclose(frequencies[:5], frequencies[:5].mean(), atol=0.01) + assert np.allclose(frequencies[5:], frequencies[5:].mean(), atol=0.01) + + +def test_the_numpy_and_numba_tournaments_select_the_same_parents() -> None: + F = np.vstack([_line_front(5), _line_front(5) + 1.0]) + + for pressure in (2, 3): + numpy_parents = _parents("tournament", F, kernel=NumPyKernel(), pressure=pressure, seed=5) + numba_parents = _parents("tournament", F, kernel=NumbaKernel(), pressure=pressure, seed=5) + assert np.array_equal(numpy_parents, numba_parents) + + +def test_the_tournament_puts_feasible_solutions_first() -> None: + n = 10 + G = np.array([[-1.0]] * 5 + [[0.5], [1.0], [2.0], [3.0], [4.0]]) + + frequencies = _frequencies(_parents("tournament", _line_front(n), G=G, pressure=3), n) + + # With three candidates, the most violated row and the second most violated never win. + assert frequencies[8] == 0.0 and frequencies[9] == 0.0 + assert frequencies[:5].min() > frequencies[5:].max() + + +def test_the_tournament_size_sets_the_pressure() -> None: + n = 10 + F = np.vstack([_line_front(5), _line_front(5) + 1.0]) + + binary = _frequencies(_parents("tournament", F), n)[5:].sum() + larger = _frequencies(_parents("tournament", F, pressure=4), n)[5:].sum() + + # Four distinct candidates are all dominated in (5/10)(4/9)(3/8)(2/7) of the tournaments. + assert larger == pytest.approx(120 / 5040, abs=0.01) + assert larger < binary + + +# ---- configuration -------------------------------------------------------------- + + +def test_defaults_resolve_to_random_parents() -> None: + resolved = optimize(DTLZ2Problem(n_var=12, n_obj=3), algorithm="nsgaiii", pop_size=10, max_evaluations=30, seed=0, engine="numpy") + + assert NSGAIIIConfig.default().selection == ("random", {}) + assert NSGAIIIConfig.default(pop_size=100, n_obj=5).selection == ("random", {}) + assert resolved.explain_defaults()["resolved_spec"]["operators"]["selection"]["component_id"].startswith("vamos.operator:random@") + + +def test_the_command_line_builder_selects_random_parents_unless_its_block_sets_a_tournament() -> None: + problem = DTLZ2Problem(n_var=12, n_obj=3) + tournament = {"nsgaiii": {"selection": {"method": "tournament", "size": 3}}} + + _, default = build_algorithm("nsgaiii", "numpy", problem, ExperimentConfig(population_size=10), selection_pressure=4) + _, configured = build_algorithm("nsgaiii", "numpy", problem, ExperimentConfig(population_size=10), variations=tournament) + + assert default.to_dict()["selection"] == ("random", {}) + assert configured.to_dict()["selection"] == ("tournament", {"size": 3}) + + +@pytest.mark.parametrize("method", ["boltzmann", "ranking", "sus", "roulette"]) +def test_an_unsupported_selection_is_rejected(method: str) -> None: + with pytest.raises(ConfigurationError, match="NSGA-III does not support selection"): + NSGAIIIConfig.builder().selection(method) + valid = _config().to_dict() + with pytest.raises(ConfigurationError, match="NSGA-III does not support selection"): + NSGAIIIConfig.from_dict({**valid, "selection": [method, {}]}) + # A configuration mapping that bypasses NSGAIIIConfig fails before the first evaluation. + with pytest.raises(ConfigurationError, match="NSGA-III does not support selection"): + NSGAIII({**valid, "selection": (method, {})}, kernel=NumPyKernel()).run( + DTLZ2Problem(n_var=12, n_obj=3), termination=("max_evaluations", 30), seed=0 + ) + + +@pytest.mark.parametrize( + ("selection", "message"), + [ + (("random", {"size": 2}), "random selection takes no options"), + (("tournament", {"pressure": 2}), "tournament selection takes only 'size'"), + (("tournament", {"size": 0}), "positive integer"), + (("tournament", {"size": True}), "positive integer"), + ("random", "pair"), + ], +) +def test_invalid_selection_options_are_rejected(selection: object, message: str) -> None: + with pytest.raises(ConfigurationError, match=message): + nsgaiii_selection(selection) + + +def test_the_supported_selections_build() -> None: + assert nsgaiii_selection(("random", {})) == ("random", 2) + assert nsgaiii_selection(("tournament", {})) == ("tournament", 2) + assert nsgaiii_selection(["Tournament", {"size": 4}]) == ("tournament", 4) + assert _config(method="tournament", size=3).selection == ("tournament", {"size": 3}) + + +# ---- tuning spaces ---------------------------------------------------------------- + + +NSGAIII_SPACES = sorted(name for name in builtin_parameter_space_names() if builtin_parameter_space(name).algorithm == "nsgaiii") + + +@pytest.mark.parametrize("name", NSGAIII_SPACES) +def test_the_spaces_choose_random_parents_or_a_tournament(name: str) -> None: + space = builtin_parameter_space(name) + selection = space.parameter("selection") + + assert selection.default == "random" and selection.values == ("random", "tournament") + assert selection.production("random") == () + assert [parameter.name for parameter in selection.production("tournament")] == ["tournament_size"] + assert config_from_assignment(name, {**space.default_values(), "pop_size": 100}).to_dict()["selection"] == ("random", {}) + + +@pytest.mark.parametrize("name", ["nsgaiii", "nsgaiii_constrained"]) +def test_the_bridge_builds_the_chosen_selection(name: str) -> None: + base = {"pop_size": 100, "crossover": "sbx", "mutation": "polynomial"} + + def selection(**assignment: object) -> object: + return config_from_assignment(name, {**base, **assignment}).to_dict()["selection"] + + assert selection(selection="random") == ("random", {}) + assert selection(selection="tournament", tournament_size=4) == ("tournament", {"size": 4}) + # An assignment saved from an earlier space names only the tournament size, and keeps its tournament. + assert selection(tournament_size=5) == ("tournament", {"size": 5}) + assert selection() == ("random", {}) + + +def test_the_selection_is_exchanged_with_evolver() -> None: + assignment = {"selection": "tournament", "tournament_size": 3} + + assert to_evolver(assignment) == {"selection": "tournament", "selectionTournamentSize": 3} + assert from_evolver({"selection": "random"}) == {"selection": "random"} diff --git a/tests/engine/test_operator_combo_validation.py b/tests/engine/test_operator_combo_validation.py index 6b7b94d64..ce5a31f13 100644 --- a/tests/engine/test_operator_combo_validation.py +++ b/tests/engine/test_operator_combo_validation.py @@ -358,6 +358,8 @@ def _inject_special_params(algo_name: str, assignment: dict[str, Any]) -> None: "moead_mixed_mixed", # Development after 1.4.0: AGE-MOEA's replacement (AGE-MOEA-II) doubles its constrained space. "agemoea_constrained_real", + # Development after 1.4.0: NSGA-III's selection (random or a tournament) doubles its constrained space. + "nsgaiii_constrained_real", } # A prime stride over the base product reaches every value of every base parameter. _SAMPLE_BASE_STRIDE = 211 diff --git a/tests/experiment/test_cli_config_validation.py b/tests/experiment/test_cli_config_validation.py index 4fa69d26d..bf392d260 100644 --- a/tests/experiment/test_cli_config_validation.py +++ b/tests/experiment/test_cli_config_validation.py @@ -325,6 +325,21 @@ def test_selection_pressure_above_a_problems_population_stops_before_any_run(mon assert not output_root.exists() +def test_selection_pressure_does_not_size_the_parents_of_nsgaiii(monkeypatch, tmp_path): + # Development after 1.4.0: NSGA-III draws its parents at random, so the pressure is neither used nor checked. + from vamos.experiment.cli.main import main + + defaults = {"algorithm": "nsgaiii", "engine": "numpy", "population_size": 20, "selection_pressure": 50, "max_evaluations": 40} + spec = {"defaults": {**defaults, "output_root": str(tmp_path / "results")}} + monkeypatch.setattr(sys, "argv", ["prog", "--config", str(_write_spec(tmp_path, spec)), "--problem", "zdt1"]) + + main() + + (manifest,) = (tmp_path / "results").rglob("manifest.json") + selection = json.loads(manifest.read_text(encoding="utf-8"))["resolved_spec"]["operators"]["selection"] + assert selection["component_id"].startswith("vamos.operator:random@") + + def test_problem_operator_named_with_name_key_completes_an_unnamed_cli_operator(monkeypatch, tmp_path): spec = {"problems": {"zdt1": {"nsgaii": {"crossover": {"name": "sbx", "prob": 0.8}}}}} config = tmp_path / "spec.json" diff --git a/tests/reference/baselines.md b/tests/reference/baselines.md index d96ac6d06..e4d1c2532 100644 --- a/tests/reference/baselines.md +++ b/tests/reference/baselines.md @@ -22,11 +22,11 @@ These tests verify **scientific correctness** by running algorithms on standard * **Budget**: 5,000 evaluations, seed 42 * **Metric**: Hypervolume (Ref Point: [1.1, 1.1, 1.1]; the front's maximum is 0.8074) * **Baselines**: - * **NSGA-III** (12 divisions, 91 individuals): Expected HV > 0.67 (seed 42 reaches 0.7192; seeds 0 to 9, 0.7055 to 0.7205) + * **NSGA-III** (12 divisions, 91 individuals, random parents): Expected HV > 0.67 (seed 42 reaches 0.7122; seeds 0 to 9, 0.7029 to 0.7203). **Development after 1.4.0:** NSGA-III selects its parents at random, as configured; it used to run a tournament on rank and crowding distance (seed 42 reached 0.7192; seeds 0 to 9, 0.7055 to 0.7205). > **Note**: Each threshold is about 93 to 95 % of the hypervolume that its configuration reaches, so a drop of more than about 5 % fails (the thresholds of VAMOS 1.1.0 let drops of 29 to 40 % pass). They catch regressions; they are not a measure of comparative performance. ## Conformance with a reference implementation * **AGE-MOEA on ZDT1**: `ZDT1Problem(n_var=30)`, population 100, 10,000 evaluations, seeds 0 to 9, Hypervolume (Ref Point: [1.1, 1.1]) * **Baseline**: jMetal 7.9 `AGEMOEABuilder` over 30 seeds, HV 0.8545 +- 0.0040. The mean must lie within two standard errors of it. -* **NSGA-II on ZDT1** and **NSGA-III on DTLZ2** (`test_external_conformance.py`): pymoo 0.6.2 with the same configuration over 30 seeds, stored with its configuration in `data/external_conformance.json` by `tools/reference_conformance_baselines.py`. The VAMOS mean over seeds 0 to 9 must lie within 3 % of pymoo's mean. pymoo runs with its mutation applied to every offspring (`PM(prob=1.0, prob_var=1/n)`) and, for NSGA-II, the rank-then-crowding tournament (`comp_by_rank_and_crowding`), as VAMOS does. Measured: NSGA-II 0.8467 against pymoo's 0.8491 (0.3 %); NSGA-III 0.7385 against 0.7378 (0.1 %). pymoo's MOEA/D (no replacement limit), SMS-EMOA (tournament mating) and SPEA2 differ from VAMOS's, so they are not compared with it. +* **NSGA-II on ZDT1** and **NSGA-III on DTLZ2** (`test_external_conformance.py`): pymoo 0.6.2 with the same configuration over 30 seeds, stored with its configuration in `data/external_conformance.json` by `tools/reference_conformance_baselines.py`. The VAMOS mean over seeds 0 to 9 must lie within 3 % of pymoo's mean. pymoo runs with its mutation applied to every offspring (`PM(prob=1.0, prob_var=1/n)`) and, for NSGA-II, the rank-then-crowding tournament (`comp_by_rank_and_crowding`), as VAMOS does; for NSGA-III, pymoo's random parents (`comp_by_cv_then_random`), which VAMOS's `selection("random")` runs since the development after 1.4.0. Measured: NSGA-II 0.8467 against pymoo's 0.8491 (0.3 %); NSGA-III 0.7372 against 0.7378 (0.1 %; 0.7385 with the earlier tournament on rank and crowding distance). pymoo's MOEA/D (no replacement limit), SMS-EMOA (tournament mating) and SPEA2 differ from VAMOS's, so they are not compared with it. diff --git a/tests/reference/test_dtlz_convergence.py b/tests/reference/test_dtlz_convergence.py index 69588ccc3..67e5c6d55 100644 --- a/tests/reference/test_dtlz_convergence.py +++ b/tests/reference/test_dtlz_convergence.py @@ -10,7 +10,7 @@ def test_dtlz2_nsgaii_convergence(): """ Verify NSGA-III solves DTLZ2 (3 objectives). - Baseline: HV > 0.67 (seed 42 reaches 0.7192; the front's maximum is 0.8074) + Baseline: HV > 0.67 (seed 42 reaches 0.7122 with random parents; the front's maximum is 0.8074) Budget: 5,000 evals """ # 3-objective problem diff --git a/tests/reference/test_scientific_defaults.py b/tests/reference/test_scientific_defaults.py index 73c6bc504..2566f0ce6 100644 --- a/tests/reference/test_scientific_defaults.py +++ b/tests/reference/test_scientific_defaults.py @@ -9,8 +9,9 @@ - NSGA-II: Deb, Pratap, Agarwal and Meyarivan (2002), SBX p_c = 0.9, eta_c = 20, polynomial mutation p_m = 1/n, eta_m = 20, binary tournament. -- NSGA-III: Deb and Jain (2014), eta_c = 30, eta_m = 20, p_m = 1/n, and a complete Das-Dennis - lattice of the population's size. The paper uses p_c = 1; VAMOS uses 0.9 in every default. +- NSGA-III: Deb and Jain (2014), eta_c = 30, eta_m = 20, p_m = 1/n, random parents (Development + after 1.4.0; the default was a tournament on rank and crowding distance), and a complete + Das-Dennis lattice of the population's size. The paper uses p_c = 1; VAMOS uses 0.9 in every default. - MOEA/D: MOEA/D-DE of Li and Zhang (2009), CR = 1, F = 0.5, eta_m = 20, p_m = 1/n, T = 20, delta = 0.9, n_r = 2. PBI with theta = 5 (Zhang and Li, 2007) is the VAMOS choice of aggregation (``docs/algorithms/moead.md``). @@ -56,7 +57,7 @@ "nsgaiii": { "crossover": _SBX_30, "mutation": _PM, - "selection": ["tournament", {}], + "selection": ["random", {}], "reference_directions": {"divisions": 99, "path": None}, "enforce_ref_dirs": True, },