pyconcorde
pyconcorde copied to clipboard
Using matrix distance in input ?
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 :-(
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)
Hi,
Thank you for your reply. Indeed after converting my floats to int's it seems to be working 🙂
Hi, have you found the solution for this?