saealib.Comparator#

class saealib.Comparator(weights, eps_cv, eps_obj, direction=None)[ソース]#

ベースクラス: ABC

Base class for comparator.

パラメータ:
  • weights (np.ndarray)

  • eps_cv (float)

  • eps_obj (float)

  • direction (np.ndarray | None)

weights#

Weights for objectives. shape = (n_obj, )

Type:

np.ndarray

eps_cv#

Epsilon for constraint violation feasibility threshold. Under Optimizer execution this value is overwritten every generation from problem.handler.feasibility_threshold; the constructor argument only matters for standalone (non-Optimizer) use.

Type:

float

eps_obj#

Epsilon for objective value equality comparison.

Type:

float

direction#

Per-objective optimization directions (+1 = maximize, -1 = minimize). None means all objectives are minimized.

Type:

np.ndarray or None

Methods

__init__

compare

Compare two solutions directly from raw values.

compare_population

Compare individual a and b in population.

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

Method Details

abstractmethod Comparator.__init__(weights, eps_cv, eps_obj, direction=None)[ソース]#
パラメータ:
  • weights (ndarray)

  • eps_cv (float)

  • eps_obj (float)

  • direction (ndarray | None)

abstractmethod Comparator.compare(fa, cv_a, fb, cv_b)[ソース]#

Compare two solutions directly from raw values.

This is the low-overhead variant of compare_population that avoids constructing or indexing into a Population object.

パラメータ:
  • fa (np.ndarray) -- Objective values of solution a. shape = (n_obj,)

  • cv_a (float) -- Constraint violation of solution a.

  • fb (np.ndarray) -- Objective values of solution b. shape = (n_obj,)

  • cv_b (float) -- Constraint violation of solution b.

戻り値:

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

戻り値の型:

int

abstractmethod Comparator.compare_population(population, idx_a, idx_b)[ソース]#

Compare individual a and b in population.

パラメータ:
  • population (Population) -- The population to compare.

  • idx_a (int) -- Index of the first individual.

  • idx_b (int) -- Index of the second individual.

戻り値:

Comparison result. -1 if the individual a is better than the individual b. 1 if the individual a is worse than the individual b. 0 if the individual a is equal to the individual b.

戻り値の型:

int

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

パラメータ:

problem (Problem) -- The optimization problem.

戻り値:

Empty by default.

戻り値の型:

list[PopulationAttribute]

Comparator.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).

パラメータ:

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

戻り値の型:

None

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

パラメータ:

population (Population) -- The population to rank.

戻り値:

Sorted population indices, as returned by sort_population().

戻り値の型:

np.ndarray

abstractmethod Comparator.sort_population(population)[ソース]#

Sort population based on their attributes.

パラメータ:

population (Population) -- The population to sort.

戻り値:

Sorted population indices.

戻り値の型:

np.ndarray