saealib.DecompositionComparator#

class saealib.DecompositionComparator(decomposition, weights, ideal_point=None, direction=None, *, eps_cv=1e-06, eps_obj=1e-06)[source]#

Bases: Comparator

Comparator that ranks solutions by a scalarization (decomposition) score.

Implements MOEA/D-style decomposition: each sub-problem is defined by a weight vector weights and an ideal point ideal_point. The ordering follows the library convention (feasibility first, then score).

Ordering rules:

  1. Infeasible individuals (cv > eps_cv) are always placed after feasible ones, sorted by ascending constraint violation (Deb 2000).

  2. Among feasible individuals, the individual with the lower aggregate score (as returned by decomposition.aggregate) is ranked first.

  3. Two individuals with scores within eps_obj are considered equal.

Direction handling: weights contains non-negative magnitudes only. Sign conventions (minimize vs. maximize) are expressed via direction. Before calling decomposition.aggregate, objectives are transformed as f_min = f * (-direction) so that all objectives are in the minimization frame.

Ideal-point tracking: when ideal_point=None, sort_population computes the per-objective minimum of the feasible set at each call (dynamic tracking). For compare, the pair-wise minimum is used as a local approximation — consistent but not globally optimal.

Parameters:
  • decomposition (Decomposition) – Scalarization function (e.g. TchebycheffDecomposition).

  • weights (np.ndarray) – Non-negative weight vector, shape (n_obj,).

  • ideal_point (np.ndarray or None) – Reference minimum per objective, shape (n_obj,). None (the default) activates dynamic computation from the population.

  • direction (np.ndarray or None) – Per-objective optimization direction: +1 = maximize, -1 = minimize. None means minimize all objectives.

  • eps_cv (float) – Feasibility threshold for constraint violation.

  • eps_obj (float) – Score tolerance: differences smaller than this are treated as equal.

References

[9]: Zhang, Q., & Li, H. (2007). MOEA/D: A multiobjective evolutionary algorithm based on decomposition. IEEE Transactions on Evolutionary Computation, 11(6), 712-731.

[10]: Deb, K. (2000). An efficient constraint handling method for genetic algorithms. Computer Methods in Applied Mechanics and Engineering, 186(2-4), 311-338.

Methods

__init__

compare

Compare two solutions directly without a Population object.

compare_population

Compare two individuals using feasibility rule then aggregate score.

get_required_attrs

Return population attributes this comparator needs to persist.

prepare_population

Freshly recompute and materialize population-relative ranking state.

rank_population

Prepare population-relative ranking state, then sort.

sort_population

Sort by aggregate score; infeasible individuals come last.

Method Details

DecompositionComparator.__init__(decomposition, weights, ideal_point=None, direction=None, *, eps_cv=1e-06, eps_obj=1e-06)[source]#
Parameters:
  • decomposition (Decomposition)

  • weights (ndarray)

  • ideal_point (ndarray | None)

  • direction (ndarray | None)

  • eps_cv (float)

  • eps_obj (float)

Return type:

None

DecompositionComparator.compare(fa, cv_a, fb, cv_b)[source]#

Compare two solutions directly without a Population object.

When ideal_point was not provided at construction time, the pair-wise minimum min(fa_min, fb_min) is used as a local approximation of the ideal point. This is consistent for pairwise comparison but may differ from sort_population results (which use the population-wide minimum).

Parameters:
  • fa (np.ndarray) – Objective vectors, shape (n_obj,).

  • fb (np.ndarray) – Objective vectors, shape (n_obj,).

  • cv_a (float) – Constraint violations.

  • cv_b (float) – Constraint violations.

Returns:

-1 if a is better, 1 if b is better, 0 if equal.

Return type:

int

DecompositionComparator.compare_population(population, idx_a, idx_b)[source]#

Compare two individuals using feasibility rule then aggregate score.

Returns -1 if a is better, 1 if b is better, 0 if equal (within eps_obj).

Parameters:
Return type:

int

DecompositionComparator.get_required_attrs(problem)#

Return population attributes this comparator needs to persist.

Population-relative ranking state (e.g. SPEA2 fitness) that must survive across selections belongs here as a named, typed attribute rather than in the population’s transient cache. Default: no additional attributes.

Parameters:

problem (Problem) – The optimization problem.

Returns:

Empty by default.

Return type:

list[PopulationAttribute]

DecompositionComparator.prepare_population(population)#

Freshly recompute and materialize population-relative ranking state.

Default is a no-op — comparators whose ranking depends only on per-individual values already stored in f/cv do not need this. Comparators that declare attributes via get_required_attrs() should override this to recompute and write those attributes for the given population, unconditionally (not reusing any prior cached value).

Parameters:

population (Population) – The population to prepare ranking state for.

Return type:

None

DecompositionComparator.rank_population(population)#

Prepare population-relative ranking state, then sort.

Equivalent to calling prepare_population() followed by sort_population(). Callers performing environmental selection on a freshly assembled pool (e.g. survivor selection merging population and offspring) should call this instead of sort_population() directly, so any population-relative state declared via get_required_attrs() is recomputed for the new set before ranking.

Parameters:

population (Population) – The population to rank.

Returns:

Sorted population indices, as returned by sort_population().

Return type:

np.ndarray

DecompositionComparator.sort_population(population)[source]#

Sort by aggregate score; infeasible individuals come last.

Parameters:

population (Population) – The population to sort.

Returns:

Sorted population indices (int).

Return type:

np.ndarray