Distortion Wizard

TSP Solver

I've always been fascinated with maps. Not the math kind or the programming kind, but the "map" map kind – карта in Russian, 地図 in Japanese. Consequently, when Google Earth first came out well over a decade ago (eventually integrated to Google Maps and influencing several other map software), I started thinking about building my own.

I've always wanted to know just how easy or difficult it would be to basically write the same thing myself from scratch.

Of course, way back when I was drooling over Google Earth, I was but a child, so I lacked any programming chops to pull it off. Times have since changed radically and now most software can be written (or produced, let's say) by a single person of almost any age in a matter of weeks. Maintaining it is a separate issue. Licensing is a separate issue.

Nowadays, in this apocalyptic, insane age, I do have the required chops, so I thought it would be a fun miniproject to pay my dues to my younger self and do just that. To some extent anyway. I just wasn't all sure what else that software should be about besides what Google Earth used to do for me. After all, it was just a globey thing with map tiles laid over it.

Contemplating this, I started researching the classic Traveling Salesman Problem (TSP). It’s a fascinating problem because it sits right at the core of what truly separates computer science from mathematics: math gets to play with infinities and smooth, continuous lines, while computer science is bound by finite memory and raw bits: you can't take half a road. It's the gap between P != NP and Valiant’s algebraic VP != VNP.

TSP is of course NP-hard and O(n!)†, which is a curious thing because, practically, turns out this does not mean much: known approximations and heuristics do a good-enough job most of the time for those "real map maps" and there's hardly that many nodes so the time complexity is kept in check rather nicely.

Researching it, I learned about a couple approaches to solving TSP. Things like the Held-Karp exact TSP solver in O(n^2 2^n), Lin-Kernighan, Lin-Kernighan with improvements attributed to Helsgaun, 2-opt, 3-opt, variable-depth k-opt, alpha-nearness, and simulated annealing.

I tested a few of those out. A couple observations stood out. First of all, pure, deterministic approximations are not nearly as good as probabilistic approaches for this problem. And second, I really thought the TSP seems like the perfect analogy for the contemporary intelligence craze, as well: subsequent improvements to the shortest path start to matter less and less, not to mention the real world is already rather constrained anyway. So it all really just comes down to policy. And morals.

Anyways, I made a neat little app out of this. Maybe later I might further extend it. It sort of depends. I mean, we're all using Apple Maps or Google Maps all the time anyway, right? Bah, nevermind.

†Brute-forced.