culebra.solution.tsp.Ant class¶
- class Ant(species: Species, fitness_cls: type[Fitness], path: Sequence[int] | None = None)¶
-
Construct 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¶
- property Ant.discarded: ndarray[int]¶
Nodes discarded by the ant.
Return an empty array since all nodes must be visited for the TSP problem.
- property Ant.path: ndarray[int]¶
Path.
- Return type:
- Setter:
Set a new path
- Parameters:
- Raises:
ValueError – If value does not meet the species constraints.
Methods¶
- Ant.append(node: int) None¶
Append a new node to the ant’s path.
- Parameters:
node (int) – The node
- Raises:
TypeError – If node is not an integer number
ValueError – If node does not meet the species constraints
ValueError – If node is already in the path.
- Ant.discard(node: int) None¶
Discard a node.
This method raises an exception since nodes can not be discarded for the TSP problem.
- Parameters:
node (int) – The node
- Raises:
RuntimeError – If called
- 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
Private methods¶
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:

