!pip install dwave-ocean-sdk networkx import networkx as nx from dwave.graphs import traveling_salesperson from dwave.samplers import SimulatedAnnealingSampler # “sŽs–¼‚Æ‹——£�s—ñ cities = ["A", "B", "C", "D", "E"] distance = [ \ [0, 20, 20, 50, 40], \ [30, 0, 10, 30, 20], \ [20, 10, 0, 30, 20], \ [50, 30, 20, 0, 10], \ [40, 20, 20, 10, 0] \ ] # Š®‘SƒOƒ‰ƒt‚ð�ì�¬‚·‚é G = nx.Graph() for i in range(len(cities)): for j in range(i + 1, len(cities)): G.add_edge(i, j, weight=distance[i][j]) for i in range(50) : # PC�ã‚Å“®‚­‹^Ž—ƒAƒj�[ƒŠƒ“ƒOƒTƒ“ƒvƒ‰�[ sampler = SimulatedAnnealingSampler() route_index = traveling_salesperson( \ G, \ sampler, \ num_reads=500, \ num_sweeps=5000 \ ) # “sŽs–¼‚ɕϊ·‚µ�A�ÅŒã‚É�o”­’n‚Ö–ß‚· route = [cities[i] for i in route_index] cycle = route + [route[0]] # ‘�‹——£‚ðŒvŽZ‚·‚é length = sum( \ distance[route_index[i]][route_index[(i + 1) % len(route_index)]] \ for i in range(len(route_index)) \ ) print("�„‰ñ�‡:", " �¨ ".join(cycle)) print("‘�‹——£:", length)