The Traveling Salesman problem

Here is a file with a factorial solution of the problem, with 'nump', the number of points, set to just 8. This runs quickly on my phone, but takes rather long with 10 points. Distances are randomized. trav.py.tar.gz

For the full problem, it can be described as a solution of simultaneous inequalities. It is a search for a minimum set of edges ('line' connections between points) which traverse all points, entering and leaving each point just once (two edges per point), without separating into subloops which are disconnected. The two shortest edges for each point would be the solution, except it probably fails by giving instead a set of subloops.

For 4 points only, the solution is almost immediate. There are only three ways to divide this foursome into pairs, and for each of these sets, the pairs can be taken as edges. Two of hese pairs of transverse (separate) edges must be in the solution and the longest is not, as it is the diagonals of the resulting 4 sided figure. This should simplify the solution with a greater number of points, as for each and every 4-some of points we must be keeping the two shortest complete connections between pairs of them (considering all possible arrangements of intervening points) and removing the longest (all diagonals). Therefore, there is a vast number of simultaneous inequalities of the form 'less than or equals' which must be true, giving a huge set with which a looping search could test for failure, speeding itself...

If we could reduce the search conveniently to subpaths, for any connected portion ABCD of points, the transverse edges AB + CD must be shorter than (or tied with) AC + BD, or we would use AC and BD instead. If tied, this also must be an equivalent solution. This must be true independently of the rest of our path. For any connected section ABCDEF, this must be as short as any other connection A to F which uses the intervening points {B,C,D,E}, regardless of the rest of our path.

I am highly tempted to return to my original 'binset' work, done first in C#, then in other languages, including Python, of a recursive structure which ands and or information, 1's and 0's or booleans in abstraction as a recursive tree. Probably NP-complete is how to reduce such a tree to the smallest (or 'tightest') form necessary to represent all the data. My work is posted at github.com/lindasdon/binset and can be cloned from there. I made it in the belief that AI only works, as in chess, if it completely encompasses the whole of what it tests, but info which matches in both halves of a tree can be taken as a single case instead of two. A tree structure like this I have made in binset, short for binary set. I have put off the completing step of how best to simplify such a tree to minimal, but this would probably be an equivalent solution of all NP-hard problems!

binset treats a foursome of data elements as a pair of pairs ((A,B),(C,D)). The direct comparison of A to B or C to D is easy, by comparing the halves of their own binset. A compared with C, or B with D is easy, as they match position in their respective binsets. The diagonals, most complicated, should be sorted to A,D and B,C, outside of easy access, throughout the tree, simplifying, speeding, and reducing storage. That is, the pairs which differ most should be (A,D) and (B,C).

The solution to traveling salesman is a collection of rearrangements between edges AB and CD versus AC and BD versus AD and BC. These pairs can be directly compared. All that is needed is a data structure, similar to a binset tree structure, which retains these results, when calculated once, for the entirety of all possible paths so they need not be recalculated. Local results for a section of points apply equally regardless what the rest of the path is. A full sort of all paths should be possible in polynomial time with such a data structure.