culebra.abc.Solution class

class Solution(species: Species, fitness_cls: Type[Fitness])

Construct a default solution.

Parameters:
  • species (species_cls) – The species the solution will belong to

  • fitness (Any subclass of Fitness) – The solutions’s fitness class

Raises:
  • TypeError – If species is not a valid species

  • TypeError – If fitness_cls is not a valid fitness class

Class attributes

Solution.species_cls = <class 'culebra.abc.Species'>

Class for the species used by the Solution class to constrain all its instances.

Class methods

classmethod Solution.load_pickle(filename: str) Base

Load a pickled object from a file.

Parameters:

filename (str) – The file name.

Raises:

Properties

property Solution.species: Species

Get the solution’s species.

Returns:

The species

Return type:

Species

property Solution.fitness: Fitness

Get and set the solution’s fitness.

Getter:

Return the current fitness

Setter:

Set a new Fitness

Type:

Fitness

Methods

Solution.save_pickle(filename: str) None

Pickle this object and save it to a file.

Parameters:

filename (str) – The file name.

Raises:
Solution.dominates(other: Solution) bool

Dominate operator.

Parameters:

other (Solution) – Other solution

Returns:

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

Return type:

bool

Solution.delete_fitness() None

Delete the solution’s fitness.

Dunder methods

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

Solution.__hash__() int

Return the hash number for this solution.

The hash number is used for equality comparisons. Currently is implemented as the hash of the solution’s string representation.

Solution.__eq__(other: Solution) bool

Equality test.

Parameters:

other (Solution) – Other solution

Returns:

True if other codes the same solution, or False otherwise

Return type:

bool

Solution.__ne__(other: Solution) bool

Not equality test.

Parameters:

other (Solution) – Other solution

Returns:

False if other codes the same solutions, or True otherwise

Return type:

bool

Solution.__lt__(other: Solution) bool

Less than operator.

Parameters:

other (Solution) – Other solution

Returns:

True if the solution’s fitness is less than the other’s fitness

Return type:

bool

Solution.__gt__(other: Solution) bool

Greater than operator.

Parameters:

other (Solution) – Other solution

Returns:

True if the solution’s fitness is greater than the other’s fitness

Return type:

bool

Solution.__le__(other: Solution) bool

Less than or equal to operator.

Parameters:

other (Solution) – Other solution

Returns:

True if the solution’s fitness is less than or equal to the other’s fitness

Return type:

bool

Solution.__ge__(other: Solution) bool

Greater than or equal to operator.

Parameters:

other (Solution) – Other solution

Returns:

True if the solution’s fitness is greater than or equal to the other’s fitness

Return type:

bool