culebra.fitness_function.tsp.abc.TSPFitnessFunction class¶
- class TSPFitnessFunction¶
Bases:
FitnessFunctionConstruct the fitness function.
Class methods¶
- classmethod TSPFitnessFunction.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 TSPFitnessFunction.heuristic: tuple[ndarray[float], ...]¶
Heuristic matrices.
This property must be overridden by subclasses.
- Returns:
A sequence of heuristic matrices. One for each objective. Arcs from a node to itself have a heuristic value of 0. For the rest of arcs, the reciprocal of their nodes distance is used as heuristic
- Return type:
- Raises:
NotImplementedError – If has not been overridden
- abstract property TSPFitnessFunction.num_nodes: int¶
Number of nodes of the problem graph.
This property must be overridden by subclasses to return the problem graph’s number of nodes.
- Return type:
- Raises:
NotImplementedError – If has not been overridden
- abstract property TSPFitnessFunction.obj_names: tuple[str, ...]¶
Objective names.
This property must be overridden by subclasses to return a correct value.
- property TSPFitnessFunction.obj_thresholds: list[float]¶
Objective similarity thresholds.
- Return type:
- Setter:
Set new thresholds.
- Parameters:
values (float | Sequence[float]) – The new values. If only a single value is provided, the same threshold will be used for all the objectives. Different thresholds can be provided in a
Sequence. If set toNone, all the thresholds are set to_default_similarity_threshold- Raises:
TypeError – If neither a real number nor a
Sequenceof real numbers is providedValueError – If any value is negative
ValueError – If the length of the thresholds sequence does not match the number of objectives
Private properties¶
Methods¶
- TSPFitnessFunction.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
- abstract TSPFitnessFunction.evaluate(sol: Solution, index: int | None = None, representatives: Sequence[Solution] | None = None) Fitness¶
Evaluate a solution.
Parameters representatives and index are used only for cooperative evaluations
This method must be overridden by subclasses to return a correct value.
- Parameters:
- Returns:
The fitness for sol
- Return type:
- Raises:
NotImplementedError – If has not been overridden

