Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using matrix distance in input ? #68

Open
alemat13 opened this issue Mar 2, 2024 · 3 comments
Open

Using matrix distance in input ? #68

alemat13 opened this issue Mar 2, 2024 · 3 comments

Comments

@alemat13
Copy link

alemat13 commented Mar 2, 2024

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
Copy link

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
Copy link
Author

alemat13 commented May 7, 2024

Hi,

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

@SomyaNIGAM
Copy link

Hi, have you found the solution for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants