import numpy as np
import utility

from full_qubo_solver import FullQuboSolver
from average_partition_solver import AveragePartitionSolver
from qiskit_native_solver import QiskitNativeSolver
from route_activation_solver import RouteActivationSolver
from clustered_tsp_solver import ClusteredTspSolver
from solution_partition_solver import SolutionPartitionSolver

n = 5
m = 2
seed = 1543

instance, xc, yc = utility.generate_vrp_instance(n, seed)

fqs = FullQuboSolver(n, m, instance)
fqs.solve(solver='leap')
fqs.visualize(xc, yc)

aps = AveragePartitionSolver(n, m, instance)
aps.solve(solver='leap')
aps.visualize(xc, yc)

ras = RouteActivationSolver(n, m, instance)
ras.solve(solver='leap')
ras.visualize(xc, yc)

qns = QiskitNativeSolver(n, m, instance)
qns.solve(solver='leap')
qns.visualize(xc, yc)

cts = ClusteredTspSolver(n, m, instance)
cts.solve(solver='leap')
cts.visualize(xc, yc)

sps = SolutionPartitionSolver(n, m, instance)
sps.solve(solver='leap')
sps.visualize(xc, yc)

vrp_list = [fqs, aps, ras, qns, cts, sps]
solver_types = ['FQS', 'APS', 'RAS', 'QNS', 'CTS', 'SPS']
for i, vrp in enumerate(vrp_list):
    print(f'{solver_types[i]} - Optimized Cost: {vrp.evaluate_vrp_cost()}')

qubo_time = [vrp.timing['qubo_build_time'] for vrp in vrp_list]
for i in range(len(vrp_list)):
    print(f'{solver_types[i]} - Classical QUBO Build Time: {qubo_time[i]} us')

qpu_time = [vrp.timing['qpu_access_time'] for vrp in vrp_list]
qpu_time[4] += cts.timing['clustering_time']['qpu_access_time']
for i in range(len(vrp_list)):
    print(f'{solver_types[i]} - QPU Access Time: {qpu_time[i]} us')

from solution_partition_solver import CapcSolutionPartitionSolver

cap = 10
dem = [1, 2, 3, 4, 5]
sps = CapcSolutionPartitionSolver(n, m, instance, cap, dem)
sps.solve(solver='leap')
sps.visualize(xc, yc)