culebra.solution.abc.Ant class¶
- class Ant(species: Species, fitness_cls: type[Fitness])¶
Bases:
SolutionConstruct a default solution.
Class attributes¶
Class methods¶
- classmethod Ant.load(filename: str) Base¶
Load a serialized object from a file.
- Parameters:
filename (str) – The file name.
- Returns:
The loaded object
- Raises:
TypeError – If filename is not a valid file name
ValueError – If the filename extension is not
SERIALIZED_FILE_EXTENSION
Properties¶
- abstract property Ant.discarded: ndarray[int]¶
Nodes discarded by the ant.
This property must be overridden by subclasses to return a correct value.
- Return type:
- Raises:
NotImplementedError – If has not been overridden
- abstract property Ant.path: ndarray[int]¶
Path traveled by the ant.
This property must be overridden by subclasses to return a correct value.
- Return type:
- Raises:
NotImplementedError – If has not been overridden
Methods¶
- 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
- Ant.dump(filename: str) None¶
Serialize 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
SERIALIZED_FILE_EXTENSION
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.
- Return type:

