pyconcorde icon indicating copy to clipboard operation
pyconcorde copied to clipboard

Using matrix distance in input ?

Open alemat13 opened this issue 11 months ago • 3 comments

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 :-(

alemat13 avatar Mar 02 '24 18:03 alemat13

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)

abhaysobhanan avatar May 07 '24 07:05 abhaysobhanan

Hi,

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

alemat13 avatar May 07 '24 07:05 alemat13

Hi, have you found the solution for this?

SomyaNIGAM avatar Aug 21 '24 19:08 SomyaNIGAM