saealib.DecompositionComparator#
- class saealib.DecompositionComparator(decomposition, weights, ideal_point=None, direction=None, *, eps_cv=1e-06, eps_obj=1e-06)[source]#
Bases:
ComparatorComparator that ranks solutions by a scalarization (decomposition) score.
Implements MOEA/D-style decomposition: each sub-problem is defined by a weight vector
weightsand an ideal pointideal_point. The ordering follows the library convention (feasibility first, then score).Ordering rules:
Infeasible individuals (
cv > eps_cv) are always placed after feasible ones, sorted by ascending constraint violation (Deb 2000).Among feasible individuals, the individual with the lower aggregate score (as returned by
decomposition.aggregate) is ranked first.Two individuals with scores within
eps_objare considered equal.
Direction handling:
weightscontains non-negative magnitudes only. Sign conventions (minimize vs. maximize) are expressed viadirection. Before callingdecomposition.aggregate, objectives are transformed asf_min = f * (-direction)so that all objectives are in the minimization frame.Ideal-point tracking: when
ideal_point=None,sort_populationcomputes the per-objective minimum of the feasible set at each call (dynamic tracking). Forcompare, 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.Nonemeans 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
Compare two solutions directly without a Population object. |
|
Compare two individuals using feasibility rule then aggregate score. |
|
Return population attributes this comparator needs to persist. |
|
Freshly recompute and materialize population-relative ranking state. |
|
Prepare population-relative ranking state, then sort. |
|
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_pointwas not provided at construction time, the pair-wise minimummin(fa_min, fb_min)is used as a local approximation of the ideal point. This is consistent for pairwise comparison but may differ fromsort_populationresults (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:
-1ifais better,1ifbis better,0if equal.- Return type:
int
- DecompositionComparator.compare_population(population, idx_a, idx_b)[source]#
Compare two individuals using feasibility rule then aggregate score.
Returns
-1ifais better,1ifbis better,0if equal (withineps_obj).- Parameters:
population (Population)
idx_a (int)
idx_b (int)
- 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/cvdo not need this. Comparators that declare attributes viaget_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 bysort_population(). Callers performing environmental selection on a freshly assembled pool (e.g. survivor selection merging population and offspring) should call this instead ofsort_population()directly, so any population-relative state declared viaget_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