Infinite loop in TwoOptHeuristicTSP.
See original GitHub issue * JGraphT version: 1.3.1
* Java version (java -version)/platform: 1.8 but should be any version
In some the cases TwoOptHeuristicTSP fails to produce a tour but enters an infinite loop and consumes 100% CPU
Unable to reproduce reliably
Have a loop guard (max iterations) or detect duplicate attempted solutions
My math knowledge is insufficient to fully grasp this code. I solved it for my purposes by placing an iteration guard around the loop but there exists probably a better solution.
private int[] improve(int[] tour) {
int[] newTour = new int[n + 1];
double minChange;
// WERS: limiter
int iterations = MAX_ITERATIONS;
do {
- - -
if (--iterations < 0) {
/*
WERS it seems that this algoritm can encounter a set of edges
such that same edges are swapped over and over again in an
infite loop.
*/
break;
}
} while (minChange < 0d);
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (3 by maintainers)
Top Results From Across the Web
The Traveling Salesman Problem
For the TSP, there are two different types of heuristics. The first at- tempts to construct a "good" tour from scratch. The second...
Read more >Solving the Large-Scale TSP Problem in 1 h: Santa Claus ...
Multiple tours k-TSP (open loop). The first case is the classical (closed-loop) TSP problem where Santa needs to return home to complete the...
Read more >2-opt - Wikipedia
In optimization, 2-opt is a simple local search algorithm for solving the traveling salesman problem. The 2-opt algorithm was first proposed by Croes...
Read more >Solving Traveling Salesman Problem With a Non-complete ...
After generating the TSP tour, using the same subset of edges that we used to generate the TSP tour, we improve the tour...
Read more >Parallel Heuristics for TSP on MapReduce
In Section 2 we formulate the TSP problem and present some common heuristics used to find close to optimal solutions for the problem....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You could build your random route with a explicit seed value for the
Random
instance you use and then iterate over the seed values until you run into the endless loop. With that you then know a seed value that creates a critical case that is now reproducible.Perfect! Thanks for the effort and good to know I did find a real issue. As it seems that all angles are now covered, closing this issue as “already fixed in next release”.