culebra.abc.Fitness class

class Fitness(values: Tuple[float, ...] = ())

Construct a default fitness object.

Parameters:

values (tuple, optional) – Initial values for the fitness, defaults to ()

Class attributes

Fitness.weights = None

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. This attribute is inherited from deap.base.Fitness.

Note

If weights is not defined during subclassing, the following error will occur at instantiation of a subclass fitness object:

TypeError: Can't instantiate abstract <class Fitness[...]> with abstract attribute weights.

Fitness.names = None

Names of the objectives.

If not defined, generic names will be used.

Fitness.thresholds = None

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). If not defined, 0 will be used for each objective.

Class methods

classmethod Fitness.load_pickle(filename: str) Base

Load a pickled object from a file.

Parameters:

filename (str) – The file name.

Raises:
classmethod Fitness.get_objective_threshold(obj_name: str) float

Get the similarity threshold for the given objective.

Parameters:

obj_name (str) – Objective name whose threshold is returned

Raises:
  • TypeError – If obj_name isn’t a string

  • ValueError – If obj_name isn’t a valid objective name

classmethod Fitness.set_objective_threshold(obj_name: str, value: float) None

Set a similarity threshold for the given objective.

Parameters:
  • obj_name (str) – Objective name whose threshold is modified

  • value (float) – New value for the similarity threshold.

Raises:
  • TypeError – If obj_name isn’t a string or value isn’t a real number

  • ValueError – If obj_name isn’t a valid objective name or value is lower than 0

Properties

property Fitness.num_obj: int

Get the number of objectives.

Type:

int

property Fitness.pheromone_amount: Tuple[float, ...]

Return the amount of pheromone to be deposited.

This property is intended for ACO-based approaches. By default, the reciprocal of an objective fitness will be used for minimization objectives, while the objective’s value will be used for maximization problems. Fitness classes pretending a different behavior should override this property.

Returns:

The amount of pheromone to be deposited for each objective

Return type:

tuple of py:class:float

Methods

Fitness.save_pickle(filename: str) None

Pickle this object and save it to a file.

Parameters:

filename (str) – The file name.

Raises:
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

Dunder methods

Intended to compare (lexicographically) two individuals according to their fitness.

Fitness.__hash__() int

Return the hash number for this fitness.

Fitness.__eq__(other: Fitness) bool

Lexicographic equal to operator.

Parameters:

other (Fitness) – The other fitness

Fitness.__ne__(other: Fitness) bool

Lexicographic not equal to operator.

Parameters:

other (Fitness) – The other fitness

Fitness.__lt__(other: Fitness) bool

Lexicographic less than operator.

Parameters:

other (Fitness) – The other fitness

Fitness.__gt__(other: Fitness) bool

Lexicographic greater than operator.

Parameters:

other (Fitness) – The other fitness

Fitness.__le__(other: Fitness) bool

Lexicographic less than or equal to operator.

Parameters:

other (Fitness) – The other fitness

Fitness.__ge__(other: Fitness) bool

Lexicographic greater than or equal to operator.

Parameters:

other (Fitness) – The other fitness