-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom_task.py
More file actions
43 lines (32 loc) · 1.41 KB
/
custom_task.py
File metadata and controls
43 lines (32 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from qboard import Solver
import numpy as np
from QUBO import *
import json
def solve_case(start, finish, stations):
PARAMS = {
"remote_addr": "https://remote.qboard.tech",
"access_key": "8a9c6702-ee8c-4cdc-a857-801f06cbd886"
}
s = Solver(mode="remote:simcim", params=PARAMS)
with open("./test_stations.json", 'r', encoding='utf-8') as file:
data = json.load(file)
names = dict(zip([data['stations'][i]['name'] for i in range(len(data['stations']))],
[i for i in range(len(data['stations']))]))
print(names)
n = len(names)
G = Graph(n)
for i in range(n):
for item in data['stations'][i]['able_to_get_to']:
G.add_edge(names[data['stations'][i]['name']], names[item['to']], item['time'])
if 'transfer' in data['stations'][i].keys():
for item in data['stations'][i]['transfer']:
G.add_edge(names[data['stations'][i]['name']], names[item['to']], item['time'])
for i in range(n):
print(G.edges[i])
points = [names[name] for name in stations]
QUBO_obj = QUBOMatrixFromGraph(n, G, start=names[start], finish=names[finish], points=points)
Q = QUBO_obj.get_matrix()
# Getting results
spins, energy = s.solve_qubo(Q, timeout=1)
for i in range(QUBO_obj.get_path_size()):
QUBO_obj.print_option(spins[i * QUBO_obj.get_row_size():(i + 1) * QUBO_obj.get_row_size()])