jvkersch / pyconcorde

Python wrapper around the Concorde TSP solver
BSD 3-Clause "New" or "Revised" License
342 stars 95 forks source link

Using matrix distance in input ? #68

Open alemat13 opened 6 months ago

alemat13 commented 6 months ago

Hi, I'm trying to use a matrix distance obtained from openrouteservice.org as an input for TSPSolver, but I couldn't find an example of a matrix usage. Could you please give me an exemple? All I tried so far failed :-(

abhaysobhanan commented 4 months ago

Matrix input is supported, but note that numerical issues may arise if your distances are small. See #64.

dist_matrix = [[0, 5, 1, 8, 2],
               [5, 0, 4, 2, 9],
               [1, 4, 0, 3, 5],
               [8, 2, 3, 0, 1],
               [2, 9, 5, 1, 0]] 

create_tsp_file("tsp_data", dist_matrix)
solver = TSPSolver.from_tspfile("tsp_data.tsp")
solution = solver.solve()
print(solution.optimal_value)
print(solution.tour)
alemat13 commented 4 months ago

Hi,

Thank you for your reply. Indeed after converting my floats to int's it seems to be working 🙂

SomyaNIGAM commented 3 weeks ago

Hi, have you found the solution for this?