qlauncher.problems#
All problems together
Submodules:
Subpackages:
Summary#
__all__ Classes:
Class for exact cover problem. |
|
Class for Graph Coloring Problem which is a combinatorial problem involving assigning labels to vertices of the graph such that no two adjacent vertices share the same label. |
|
Class for Job Shop Scheduling Problem. |
|
Class for 0/1 Knapsack Problem. |
|
Class for MaxCut Problem. |
|
Abstract class for defining Problems. |
|
Abstract class for defining Problems. |
|
Traveling Salesman Problem (TSP) definition. |
|
Class for the Vertex Cover problem which is a combinatorial problem involving choosing a subset of graph vertices such that each edge of the graph has at least one vertex in the chosen subset. |
Reference#
- class qlauncher.problems.EC(instance: list[set[int]], instance_name: str = 'unnamed')[source]#
Bases:
ProblemClass for exact cover problem.
The exact cover problem is a combinatorial optimization problem that involves finding a subset of a given set of elements such that the subset covers all elements and the number of elements in the subset is minimized. The class contains an instance of the problem, so it can be passed into QLauncher.
Attributes:
onehot (str): The one-hot encoding used for the problem. instance (any): The instance of the problem. instance_name (str | None): The name of the instance. instance_path (str): The path to the instance file.
- get_mixer_hamiltonian(amount_of_rings: int | None = None) Equation[source]#
generates mixer hamiltonian
- to_hamiltonian(onehot: Literal['exact', 'quadratic'] = 'exact') Hamiltonian[source]#
- class qlauncher.problems.GraphColoring(instance: Graph, num_colors: int, instance_name: str = 'unnamed')[source]#
Bases:
ProblemClass for Graph Coloring Problem which is a combinatorial problem involving assigning labels to vertices of the graph such that no two adjacent vertices share the same label.
- instance#
The graph for which the coloring problem is to be solved.
- Type:
nx.Graph
- static from_preset(instance_name: Literal['default', 'small'], **kwargs) GraphColoring[source]#
- static generate_graph_coloring_instance(num_vertices: int, edge_probability: int, num_colors: int) GraphColoring[source]#
- static randomly_choose_a_graph(num_colors: int) GraphColoring[source]#
- property setup: dict#
- to_hamiltonian(constraints_weight: float = 1, costs_weight: float = 1) Hamiltonian[source]#
- class qlauncher.problems.JSSP(max_time: int, instance: dict[str, list[tuple[str, int]]], instance_name: str = 'unnamed', optimization_problem: bool = False)[source]#
Bases:
ProblemClass for Job Shop Scheduling Problem.
This class represents Job Shop Scheduling Problem (JSSP) which is a combinatorial optimization problem that involves scheduling a set of jobs on a set of machines. Each job consists of a sequence of operations that must be performed on different machines. The objective is to find a schedule that minimizes the makespan, i.e., the total time required to complete all jobs. The class contains an instance of the problem, so it can be passed into QLauncher.
- max_time#
The maximum time for the scheduling problem.
- Type:
int
- onehot#
The one-hot encoding method to be used.
- Type:
str
- optimization_problem#
Flag indicating whether the problem is an optimization problem or a decision problem.
- Type:
bool
- results#
Dictionary to store the results of the problem instance.
- Type:
dict
- property setup: dict#
- to_bqm(lagrange_one_hot: float = 1, lagrange_precedence: float = 2, lagrange_share: float = 5) BQM[source]#
- to_hamiltonian(lagrange_one_hot: float = 1, lagrange_precedence: float = 2, lagrange_share: float = 5, onehot: Literal['exact', 'quadratic'] = 'exact') Hamiltonian[source]#
- class qlauncher.problems.Knapsack(values: Sequence[int], weights: Sequence[int], capacity: int, instance_name: str = 'unnamed')[source]#
Bases:
ProblemClass for 0/1 Knapsack Problem.
This class represents the 0/1 Knapsack problem: maximize the total value of chosen items subject to a capacity constraint on total weight. The class wraps a concrete instance and can be passed into QLauncher.
- class qlauncher.problems.MaxCut(instance: Graph, instance_name: str = 'unnamed')[source]#
Bases:
ProblemClass for MaxCut Problem.
This class represents MaxCut Problem which is a combinatorial optimization problem that involves partitioning the vertices of a graph into two sets such that the number of edges between the two sets is maximized. The class contains an instance of the problem, so it can be passed into QLauncher.
- Parameters:
instance (nx.Graph) – The graph instance representing the problem.
- property setup: dict#
- to_hamiltonian() Hamiltonian[source]#
- class qlauncher.problems.Problem(instance: Any, instance_name: str = 'unnamed')[source]#
Bases:
objectAbstract class for defining Problems.
- variant#
The variant of the problem. The default variant is “Optimization”.
- Type:
str
- path#
The path to the problem.
- Type:
str | None
- name#
The name of the problem.
- Type:
str
- instance_name#
The name of the instance.
- Type:
str
- instance#
An instance of the problem.
- Type:
any
- class qlauncher.problems.QATM(cm: ndarray, aircrafts: DataFrame, onehot: Literal['exact', 'quadratic', 'xor'] = 'exact', optimization: bool = False)[source]#
Bases:
Problem- analyze_result(result: dict) dict[str, ndarray][source]#
Analyzes the result in terms of collisions and violations of onehot constraint.
- Parameters:
result (dict) – A dictionary where keys are bitstrings and values are probabilities.
- Returns:
A dictionary containing collisions, onehot violations, and changes as ndarrays.
- Return type:
dict
- classmethod from_file(path: str, instance_name: str = 'QATM', onehot: Literal['exact', 'quadratic', 'xor'] = 'exact', optimization: bool = False) QATM[source]#
- to_hamiltonian(onehot: Literal['exact', 'quadratic', 'xor'] = None) Hamiltonian[source]#
- class qlauncher.problems.TSP(instance: Graph, instance_name: str = 'unnamed')[source]#
Bases:
ProblemTraveling Salesman Problem (TSP) definition.
- 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:
- property setup: dict#
- 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
- class qlauncher.problems.TabularML(X: ndarray, y: ndarray | None = None, instance_name: str = 'unnamed')[source]#
Bases:
Model
- class qlauncher.problems.VertexCover(instance: Graph, instance_name: str = 'unnamed')[source]#
Bases:
ProblemClass for the Vertex Cover problem which is a combinatorial problem involving choosing a subset of graph vertices such that each edge of the graph has at least one vertex in the chosen subset.
- instance#
The graph for which the coloring problem is to be solved.
- Type:
nx.Graph
- static from_preset(instance_name: Literal['default'], **kwargs) VertexCover[source]#
- static generate_vertex_cover_instance(num_vertices: int, edge_probability: int) VertexCover[source]#