-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
57 lines (40 loc) · 1.26 KB
/
main.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
from EDA import EDA
from TravellingSalesmanProblem import TSP
import pickle
import matplotlib.pyplot as plt
# from qiskit import IBMQ
# from qiskit.providers.aer.noise import NoiseModel
def initial_stats(size):
aux = []
for i in range(size):
aux.append([1/size] * size)
return aux
def relative_list(history):
relative_history = []
best = 999999999999999999
for i in range(len(history_cost)):
if history_cost[i] < best:
relative_history.append(history_cost[i])
best = relative_history[i]
else:
relative_history.append(best)
return relative_history
tsp = TSP("./datasets/datasetcorto_10")
tsp.load_data()
N = tsp.size()
init = initial_stats(N)
# from qiskit.test.mock import FakeJohannesburg
eda = EDA(init, 50, tsp, 0.5, 40, 40, type='quantum')
# eda.backend = FakeJohannesburg()
best_individual, best_cost, history_cost = eda.run()
print(best_cost, best_individual)
rel_list = relative_list(history_cost)
plt.plot(list(range(len(history_cost))), history_cost)
plt.savefig("./images/QEDA_history.png")
plt.figure()
plt.plot(list(range(len(rel_list))), rel_list)
plt.savefig("./images/QEDA_history_rel.png")
'''
with open('eda.class', 'wb') as eda_file:
pickle.dump(eda, eda_file)
'''