There are several O((n+k)*log(n)) sweep line algorithms to determine k intersections, eg. this one:Once you know there are crossings, how do you efficiently find them?
https://link.springer.com/content/pdf/1 ... 0-3_21.pdf
I spoke with Gerhard and we discussed generating example TSPs where we know the optimal solution and watch how R&R does. New file sq.cpp generates NxN cities on a grid with 10 distance by default for horizontal/vertical:
https://github.com/Hermann-SW/RR/blob/main/tsp/sq.cpp
R&R as is is not too bad, but has difficulties to deal with some crossings originating from initial RR_all().
If not for general recreates, then at least RR_all() should eliminate crossings, or not even generate them.
I realized that unlike my example, your example for non-simple polygon optimal TSP has integer coordinates.
Before trying a proof that with minimal distance of 28 between cities that cannot happen, I just want to get insight.
Like in your example with diagonal vector (4,5) I fixated that in new test code.
Later that will be varied from shorter to longer as well.
The code assumes that the vector is the longer diagonal.
It determines all possible integer coordinate points with at most ceil(sqrt(4^2+5^2))=7 euclidean distance:
https://github.com/Hermann-SW/RR/blob/main/tsp/tst.cppNext I will determine all pairs of such point, with
- one above and one below the vector
- with distance at most vector length (7 here)
- with line between both points intersecting the fixed vector
Statistics: Posted by HermannSW — Thu Sep 04, 2025 8:32 pm