qat.opt.VertexCover
- class qat.opt.VertexCover(graph, A=2, B=1, **kwargs)
Specialization of the
QUBO
class for Vertex Cover.For a right encoding, one should ensure that \(A > B\).
import numpy as np import networkx as nx from qat.opt import VertexCover graph = nx.Graph() graph.add_nodes_from(np.arange(6)) graph.add_edges_from([(0,1), (0,2), (0,3), (0,4), (0,5), (1,5)]) A = 2 B = 1 vertex_cover_problem = VertexCover(graph, A=A, B=B) print("To anneal the problem, the solver would need " + str(len(graph.nodes())) + " spins.")
To anneal the problem, the solver would need 6 spins.
- Parameters
graph (networkx.Graph) – a networkx graph
A (optional, double) – a positive constant by which the terms inside \(H_A\) from \(H = H_A + H_B\) are multiplied, default is 2. This equation comes from the Hamiltonian representation of the problem.
B (optional, double) – similar to \(A\), \(B\) is a positive factor for the \(H_B\) terms, default is 1
- get_best_parameters()
- Returns
6-key dictionary containing
n_monte_carlo_updates (int) - the number of Monte Carlo updates
n_trotters (int) - the number of “classical replicas” or “Trotter replicas”
gamma_max (double) - the starting magnetic field
gamma_min (double) - the final magnetic field
temp_max (double) - the starting temperature
temp_min (double) - the final temperature
- parse_result(result, inverse=False)
Returns the approximated solution of the Vertex Cover problem from a list of samples
- Parameters
result (
BatchResult
) – BatchResult containing a list of samples
- qat.opt.vertex_cover.produce_q_and_offset(graph, A=2, B=1)
Returns the \(Q\) matrix and the offset energy of the problem. The constant \(A\) should be bigger than \(B\) for a right encoding. They are also both positive.
- Parameters
graph (networkx.Graph) – a networkx graph
A (optional, double) – a positive constant by which the terms inside \(H_A\) from \(H = H_A + H_B\) are multiplied, default is 2. This equation comes from the Hamiltonian representation of the problem.
B (optional, double) – similar to \(A\), \(B\) is a positive factor for the \(H_B\) terms, default is 1