ああああああああああああああああああああああああああああああああああああああああああああああああああああああああああ
test 3
import numpy as np import neal def tsp_qubo(distances): n = distances.shape[0] Q = np.zeros((n, n)) # Set diagonal elements to 0 for i in range(n): Q[i][i] = 0 # Set off-diagonal elements for i in range(n): for j in range(i+1, n): Q[i][j] = distances[i][j] Q[j][i] = distances[i][j] # Set quadratic bias q = np.ones(n) * -1 return Q, q # Example distances matrix distances = np.array([[0, 10, 20, 30], [10, 0, 25, 35], [20, 25, 0, 15], [30, 35, 15, 0]]) Q, q = tsp_qubo(distances) # Solve the problem using the D-Wave system solver = neal.SimulatedAnnealingSampler() response = solver.sample_qubo(Q, q) # Print the solution for sample in response.samples(): print(sample)
Comments