culebra.abc.Fitness class

class Fitness(values: Sequence[float, ...] | None = None)

Bases: Base

Construct a default fitness object.

Parameters:

values (Sequence[float]) – Initial values for the fitness, optional

Class attributes

Fitness.names = ()

Names of the objectives.

Fitness.thresholds = ()

A list with the similarity thresholds defined for all the objectives. Fitness objects are compared lexicographically. The comparison applies a similarity threshold to assume that two fitness values are similar (if their difference is lower than or equal to the similarity threshold)

Fitness.weights = ()

A tuple containing an integer value for each objective being optimized. The weights are used in the fitness comparison. They are shared among all fitnesses of the same type. When subclassing Fitness, the weights must be defined as a tuple where each element is associated to an objective. A negative weight element corresponds to the minimization of the associated objective and positive weight to the maximization.

Class methods

classmethod Fitness.load(filename: str) Base

Load a serialized object from a file.

Parameters:

filename (str) – The file name.

Returns:

The loaded object

Raises:

Properties

property Fitness.is_valid: bool

Validness of the fitness.

Returns:

True if the fitness is valid

Return type:

bool

property Fitness.num_obj: int

Number of objectives.

Return type:

int

property Fitness.values: tuple[float | None]

Fitness values.

Return type:

tuple[float | None]

Setter:

Set the new fitness values

Parameters:

fit_values (tuple[float]) – The new values

Raises:

TypeError – If any element in fit_values is not a real number

property Fitness.wvalues: tuple[float]

Fitness weighted values.

Return type:

tuple[float | None]

Methods

Fitness.dominates(other: Fitness, which: slice = slice(None, None, None)) bool

Check if this fitness dominates another one.

Parameters:
  • other (Fitness) – The other fitness

  • which (slice) – Slice indicating on which objectives the domination is tested. The default value is slice (None), representing every objective

Returns:

True if each objective of this fitness is not strictly worse than the corresponding objective of the other and at least one objective is strictly better

Return type:

bool

Fitness.dump(filename: str) None

Serialize this object and save it to a file.

Parameters:

filename (str) – The file name.

Raises:
Fitness.update_value(value: float, obj_index: int) None

Update the value of a fitnes objective.

Parameters:
  • value (float) – The new value

  • obj_index (int) – Index of the objective

Raises:
  • TypeError – If value is not a real number or index is not an integer number

  • ValueError – If index is negative or greatuer to or equal than the number of objectives

Dunder methods

Intended to compare (lexicographically) two fitnesses.

Fitness.__eq__(other: Fitness) bool

Lexicographic equal to operator.

Parameters:

other (Fitness) – The other fitness

Return type:

bool

Fitness.__ge__(other: Fitness) bool

Lexicographic greater than or equal to operator.

Parameters:

other (Fitness) – The other fitness

Return type:

bool

Fitness.__gt__(other: Fitness) bool

Lexicographic greater than operator.

Parameters:

other (Fitness) – The other fitness

Return type:

bool

Fitness.__hash__() int

Return the hash number for this fitness.

Return type:

int

Fitness.__le__(other: Fitness) bool

Lexicographic less than or equal to operator.

Parameters:

other (Fitness) – The other fitness

Return type:

bool

Fitness.__lt__(other: Fitness) bool

Lexicographic less than operator.

Parameters:

other (Fitness) – The other fitness

Return type:

bool

Fitness.__ne__(other: Fitness) bool

Lexicographic not equal to operator.

Parameters:

other (Fitness) – The other fitness

Return type:

bool