qlauncher.problems.optimization.tsp#
Summary#
Classes:
Traveling Salesman Problem (TSP) definition. |
Reference#
- class qlauncher.problems.optimization.tsp.TSP(instance: Graph, instance_name: str = 'unnamed')[source]#
Bases:
ProblemTraveling Salesman Problem (TSP) definition.
- property setup: dict#
- static from_preset(instance_name: Literal['default'] = 'default', **kwargs) TSP[source]#
Generate TSP instance from a preset name.
- Parameters:
instance_name (str) – Name of the preset instance
quadratic (bool, optional) – Whether to use quadratic constraints. Defaults to False
- Returns:
TSP instance
- Return type:
- static generate_tsp_instance(num_vertices: int, min_distance: float = 1.0, max_distance: float = 10.0, **kwargs) TSP[source]#
Generate a random TSP instance.
- Parameters:
num_vertices (int) – Number of vertices in the graph
min_distance (float, optional) – Minimum distance between vertices. Defaults to 1.0
max_distance (float, optional) – Maximum distance between vertices. Defaults to 10.0
quadratic (bool, optional) – Whether to use quadratic constraints. Defaults to False
- Returns:
TSP instance
- Return type:
- to_hamiltonian(constraints_weight: int = 5, costs_weight: int = 1, return_to_start: bool = True, onehot: Literal['exact', 'quadratic'] = 'exact') Hamiltonian[source]#
Creates a Hamiltonian for the TSP problem.
- Parameters:
problem – TSP problem instance
quadratic – Whether to encode as a quadratic Hamiltonian
constraints_weight (int) – Weight of the constraints in the Hamiltonian
costs_weight (int) – Weight of the costs in the Hamiltonian
- Returns:
Hamiltonian representing the TSP problem
- Return type:
np.ndarray