-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
51 lines (40 loc) · 1.59 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
import time
import importlib
from tsp_utilities import *
##############################################
## ADD HERE YOUR NEW SOLVERS CLASSES #########
##############################################
active_solvers = ["Bruteforce",
"Dwave",
"Dwave_hybrid",
"Admm",
"Annealing",
"Nearest",
"TSP_genetico",
"Numpyeigensolver",
"Vqe"]
active_solvers = ["TSP_genetico", "Annealing", "Dwave_hybrid", "Bruteforce", "Nearest"]
##############################################
##############################################
def main():
# Initial Parameters
# Don't use more than 30 for Bruteforce or Classical Eigensolvers.
# VQE and other gate based can only do with 4 nodes
# Dwave hybrid, annealer simulator and TSP genetic can go up to 150
nodes = 40
starting_node = 0
G = get_graph(nodes)
cost_matrix = get_cost_matrix(G, nodes)
for solver_ in active_solvers:
ClassName = getattr(importlib.import_module("solvers."+solver_.lower()), solver_)
instance = ClassName()
#print("Route for %s:" % solver_)
start_time = time.time()
route = instance.calculate(G, cost_matrix, starting_node)
end_time = time.time()
calculation_time = end_time - start_time
#print(route)
print("%s Solution - Cost: %s - Calculation Time: %s" % (solver_, calculate_cost(cost_matrix, route), calculation_time))
#draw_tsp_solution(G, route, solver_, end_time)
if __name__ == '__main__':
main()