culebra.solution.abc.Ant
class¶
- class Ant(species: Species, fitness_cls: Type[Fitness])¶
Construct a default solution.
- Parameters:
species (
species_cls
) – The species the solution will belong tofitness (Any subclass of
Fitness
) – The solutions’s fitness class
- Raises:
Class attributes¶
Class methods¶
- classmethod Ant.load_pickle(filename: str) Base ¶
Load a pickled object from a file.
- Parameters:
filename (
str
) – The file name.- Raises:
TypeError – If filename is not a valid file name
ValueError – If the filename extension is not
PICKLE_FILE_EXTENSION
Properties¶
- property Ant.fitness: Fitness¶
Get and set the solution’s fitness.
- Getter:
Return the current fitness
- Setter:
Set a new Fitness
- Type:
- abstract property Ant.path: Sequence[int]¶
Path traveled by the ant.
This property must be overridden by subclasses to return a correct value.
- Raises:
NotImplementedError – if has not been overridden
- Type:
- abstract property Ant.discarded: Sequence[int]¶
Nodes discarded by the ant.
This property must be overridden by subclasses to return a correct value.
- Raises:
NotImplementedError – if has not been overridden
- Type:
Methods¶
- Ant.save_pickle(filename: str) None ¶
Pickle this object and save it to a file.
- Parameters:
filename (
str
) – The file name.- Raises:
TypeError – If filename is not a valid file name
ValueError – If the filename extension is not
PICKLE_FILE_EXTENSION
- abstract Ant.append(node: int) None ¶
Append a new node to the ant’s path.
This method must be overridden by subclasses to return a correct value.
- Parameters:
node (
int
) – The node- Raises:
NotImplementedError – if has not been overridden
- abstract Ant.discard(node: int) None ¶
Discard a node.
The discarded node is not appended to the ant’s path.
This method must be overridden by subclasses to return a correct value.
- Parameters:
node (
int
) – The node- Raises:
NotImplementedError – if has not been overridden
Dunder methods¶
Intended to compare (lexicographically) two Ants according to their fitness.
- Ant.__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.