saealib.SingleObjectiveComparator#

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

Bases: Comparator

Comparator for single-objective optimization.

Parameters:
  • direction (float | None)

  • eps_cv (float)

  • eps_obj (float)

Methods

__init__

compare

Compare two solutions directly without a Population object.

compare_population

Compare individuals a and b; returns -1/0/1.

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 population based on their fitness and constraint violations.

Method Details

SingleObjectiveComparator.__init__(direction=None, *, eps_cv=1e-06, eps_obj=1e-06)[source]#
Parameters:
  • direction (float | None)

  • eps_cv (float)

  • eps_obj (float)

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

Compare two solutions directly without a Population object.

Parameters:
  • fa (ndarray)

  • cv_a (float)

  • fb (ndarray)

  • cv_b (float)

Return type:

int

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

Compare individuals a and b; returns -1/0/1.

Parameters:
Return type:

int

SingleObjectiveComparator.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]

SingleObjectiveComparator.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

SingleObjectiveComparator.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

SingleObjectiveComparator.sort_population(population)[source]#

Sort population based on their fitness and constraint violations.

Parameters:

population (Population) – The population to sort.

Returns:

Sorted population indices.

Return type:

np.ndarray