saealib.SPEA2Comparator#
- class saealib.SPEA2Comparator(direction=None, *, eps_cv=1e-06, eps_obj=1e-06, dominator=None)[source]#
Bases:
ComparatorComparator implementing SPEA2 fitness-based ranking (Zitzler et al., 2001).
SPEA2 fitness
F(i) = R(i) + D(i)is computed over the entire feasible set and used as the ranking criterion — lower is better. Because the fitness depends on the whole population, pairwise comparison of two isolated points is undefined.Ordering rules:
Feasible block: the non-dominated subset (
F(i) < 1) is ordered by the iterative nearest-neighbour truncation procedure – seespea2_truncation_order()– instead of a one-shot sort, so that boundary/extreme solutions are preferentially retained under truncation. The dominated subset (F(i) >= 1) follows, sorted by ascending SPEA2 fitness (lower = better), matching the paper’s “fill with the best dominated individuals” branch. Seespea2_fitness()for thek = √Ndensity reduction note.Infeasible block: always placed after feasible individuals, ordered by ascending constraint violation (Deb 2000 feasibility rule).
Note
compare()raisesNotImplementedErrorbecause SPEA2 fitness is population-relative. Components that require pairwise comparison (e.g. PSO pbest update,PairwiseComparisonSet) should use aParetoComparatorinstead. Tournament selection should callcompare_population(), which IS defined and safe to use.- Parameters:
direction (np.ndarray or None) – Per-objective optimization directions (+1 = maximize, -1 = minimize). None defaults to minimization for all objectives.
eps_cv (float) – Feasibility threshold for constraint violation.
eps_obj (float) – Epsilon for objective-value equality (stored for interface compatibility).
dominator (Dominator or None) – Dominance predicate.
Nonedefaults toParetoDominator.
References
[4]: Zitzler, E., Laumanns, M., & Thiele, L. (2001). SPEA2: Improving the Strength Pareto Evolutionary Algorithm. TIK-Report 103, ETH Zurich.
[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
Raise NotImplementedError — SPEA2 fitness is population-relative. |
|
Compare two individuals using constraint-domination then SPEA2 fitness. |
|
Declare persistent SPEA2 fitness storage. |
|
Recompute and store SPEA2 fitness for the current population. |
|
Prepare population-relative ranking state, then sort. |
|
Sort feasible individuals via SPEA2 environmental selection. |
Method Details
- SPEA2Comparator.__init__(direction=None, *, eps_cv=1e-06, eps_obj=1e-06, dominator=None)[source]#
- Parameters:
direction (ndarray | None)
eps_cv (float)
eps_obj (float)
dominator (Dominator | None)
- SPEA2Comparator.compare(fa, cv_a, fb, cv_b)[source]#
Raise NotImplementedError — SPEA2 fitness is population-relative.
- Parameters:
fa (ndarray)
cv_a (float)
fb (ndarray)
cv_b (float)
- Return type:
int
- SPEA2Comparator.compare_population(population, idx_a, idx_b)[source]#
Compare two individuals using constraint-domination then SPEA2 fitness.
Returns
-1ifais better,1ifbis better,0if equal. The feasibility rule (Deb 2000) is applied first: feasible individuals always beat infeasible ones. Among both-infeasible pairs, lower constraint violation wins. Among both-feasible pairs, lower SPEA2 fitness wins.- Parameters:
population (Population) – The population containing both individuals.
idx_a (int) – Index of the first individual.
idx_b (int) – Index of the second individual.
- Returns:
-1,0, or1.- Return type:
int
- SPEA2Comparator.get_required_attrs(problem)[source]#
Declare persistent SPEA2 fitness storage.
- Parameters:
problem (Problem)
- Return type:
list[PopulationAttribute]
- SPEA2Comparator.prepare_population(population)[source]#
Recompute and store SPEA2 fitness for the current population.
- Parameters:
population (Population)
- Return type:
None
- SPEA2Comparator.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
- SPEA2Comparator.sort_population(population)[source]#
Sort feasible individuals via SPEA2 environmental selection.
Within the feasible block, the non-dominated subset (
F(i) < 1) is ordered byspea2_truncation_order()(Zitzler et al. 2001), and the dominated subset (F(i) >= 1) follows, ordered by ascending SPEA2 fitness. Infeasible individuals come last, ordered by ascending constraint violation.- Parameters:
population (Population) – The population to sort.
- Returns:
Sorted population indices (int).
- Return type:
np.ndarray