def make_path(X, D):
    tsp = TSP()
    # Using the data matrix
    tsp.read_data(X)

    # Using the distance matrix
    tsp.read_mat(D)

    from tspy.solvers import TwoOpt_solver
    two_opt = TwoOpt_solver(initial_tour='NN', iter_num=10000)
    two_opt_tour = tsp.get_approx_solution(two_opt)

    #tsp.plot_solution('TwoOpt_solver')

    best_tour = tsp.get_best_solution()
    return best_tour
Ejemplo n.º 2
0
from tspy import TSP
import matplotlib.pyplot as plt
from tspy.solvers import TwoOpt_solver
from tspy.lower_bounds import Held_Karp
from tspy.lower_bounds import Connected_LP_bound
import numpy as np

a = TSP()
N = 100
a.read_data(np.random.rand(N, 2))
sol = TwoOpt_solver('NN')
a.get_approx_solution(sol)
plt.figure(figsize=(5, 5))
a.plot_solution('TwoOpt_solver')

a.get_lower_bound(Connected_LP_bound())
a.get_lower_bound(
    Held_Karp(n_iter=1000, batch_size=50, alp_factor=1, start_alp=0.001))