saealib.NSGA2Comparator#
- class saealib.NSGA2Comparator(direction=None, *, eps_cv=1e-06, eps_obj=1e-06, sorter=<function non_dominated_sort>, dominator=None)[source]#
Bases:
ParetoComparatorComparator for multi-objective optimization via NSGA-II style ranking.
Extends ParetoComparator with crowding-distance-based secondary ordering:
sort_population: non-dominated sorting + crowding distance
compare_population: overrides ParetoComparator with Deb et al. (2002)’s crowded-comparison operator (prec_n): lower rank wins, ties broken by higher crowding distance – see
compare_population()
Infeasible individuals (cv > eps) are always ranked after feasible ones, ordered by ascending constraint violation.
The sort result is cached in the Population cache and automatically invalidated when the population is modified.
- Parameters:
direction (np.ndarray or None) – Per-objective optimization directions (+1 = maximize, -1 = minimize). None means all objectives are minimized.
eps_cv (float)
eps_obj (float)
sorter (NonDominatedSorter)
dominator (Dominator | None)
Methods
Compare two solutions directly without a Population object. |
|
Compare via the NSGA-II crowded comparison operator. |
|
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 Pareto front rank then crowding distance (NSGA-II style). |
Method Details
- NSGA2Comparator.__init__(direction=None, *, eps_cv=1e-06, eps_obj=1e-06, sorter=<function non_dominated_sort>, dominator=None)[source]#
- Parameters:
direction (ndarray | None)
eps_cv (float)
eps_obj (float)
sorter (NonDominatedSorter)
dominator (Dominator | None)
- NSGA2Comparator.compare(fa, cv_a, fb, cv_b)#
Compare two solutions directly without a Population object.
- Parameters:
fa (ndarray)
cv_a (float)
fb (ndarray)
cv_b (float)
- Return type:
int
- NSGA2Comparator.compare_population(population, idx_a, idx_b)[source]#
Compare via the NSGA-II crowded comparison operator.
Implements the partial order defined by Deb et al. (2002) (Section III-B.2, “Crowded-Comparison Operator”, operator prec_n): prefer the lower (better) nondomination rank; if ranks are equal, prefer the individual with the larger crowding distance.
References
[3]: Deb, K., Pratap, A., Agarwal, S., & Meyarivan, T. (2002). A fast and elitist multiobjective genetic algorithm: NSGA-II. IEEE Transactions on Evolutionary Computation, 6(2), 182-197.
- Parameters:
population (Population)
idx_a (int)
idx_b (int)
- Return type:
int
- NSGA2Comparator.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]
- NSGA2Comparator.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
- NSGA2Comparator.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
- NSGA2Comparator.sort_population(population)[source]#
Sort by Pareto front rank then crowding distance (NSGA-II style).
- Parameters:
population (Population)
- Return type:
np.ndarray