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

solve_tsp_record_to_record reachers Infinite loop with a simple example #53

Closed
yang-tsao opened this issue Apr 2, 2024 · 3 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@yang-tsao
Copy link

When I try to run the following code, it just keeps running and won't give me a result.

from python_tsp.heuristics import solve_tsp_record_to_record
import numpy as np

dis = np.array([[0, 1], [1, 0]])
[order, dist] = solve_tsp_record_to_record(dis)
print(order)
print(dist)
@fillipe-gsm fillipe-gsm added the bug Something isn't working label Apr 5, 2024
@fillipe-gsm
Copy link
Owner

Hey, @yang-tsao , thanks for reporting it.

The bug actually happens in the solve_tsp_lin_kernighan solver, which the Record to Record uses as internal solver.

I opened a draft pull request with a test replicating the problem, and I'll leave the fix for @luanleonardo.

Since this is a veeery corner case (a TSP with only two nodes), if he cannot take it I'll just put an early return.

@luanleonardo
Copy link
Collaborator

@yang-tsao @fillipe-gsm, the Lin-Kernighan heuristic assumes the existence of at least 4 nodes (named a, b, c, d) that play important roles in defining the neighborhood of a solution. If the problem is small, with less than 4 nodes, the heuristic does not apply.

fillipe-gsm added a commit that referenced this issue Apr 8, 2024
* Setup test that should be satisfied when bug is solved

* fixup! Fix wrong usage of parametrize and skip test

* fix: Lin-Kernighan solver handles problems with few nodes

* fix: type hint

* feat: verbose flag when solving with brute force

---------

Co-authored-by: Luan <luan.moraes@loggi.com>
@fillipe-gsm
Copy link
Owner

Sorry for the long delay, but the issue should be fixed now in version 0.4.2.

Thanks for reporting it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants