A rubber band of neurons wriggles through a map of cities until it becomes a tour.
Durbin and Willshaw's elastic net (1987) is a closed ring with 2.5 neurons per city. Each city pulls on the ring through a Gaussian of width K, normalized so every city spends the same total pull, while tension keeps neighboring neurons together, and K shrinks by one percent every 25 iterations. The glowing field underneath is the landscape the band descends, the sum of every city's Gaussian at the current K: broad at first, so the band only feels the shape of the cloud, then sharpening until each city has a neuron sitting on it and the order of the neurons around the ring is a tour. A nearest neighbor tour improved by 2-opt and Or-opt runs alongside as a baseline, and the chart compares the two lengths, which usually land within a few percent of each other.
Try it. Click to add a city and drag a city to move it, even mid-solve, and the band reheats a little to adapt; right-click removes one. The buttons or keys pick new cities (R), cycle layouts such as clusters, spiral arms and rings (L), overlay the 2-opt tour (B) and pause (Space).
Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.
Build an elastic net traveling salesman solver with JavaScript and the HTML canvas element. Put everything in a single index.html file with no libraries or build step, so I can open it directly in a browser.
Start simple:
- Make a canvas that fills the window, stays sharp on high-DPI screens (scale by devicePixelRatio), and has a dark background.
- Place about 100 random cities in a unit square, scaled to the screen.
- Make a closed ring of 2.5 times as many neurons, starting as a small circle at the center of the cities.
- Each iteration, for every city compute a weight for every neuron, exp(-d^2 / (2 K^2)) where d is their distance, and divide by the sum over neurons so each city's weights add up to 1. Move each neuron by 0.2 times the weighted sum of (city - neuron) over all cities, plus 2 K times (next neuron - 2 times this neuron + previous neuron) for the ring's tension.
- Start K at 0.2 and multiply it by 0.99 every 25 iterations. Run about 15 iterations per frame with requestAnimationFrame.
- Draw the ring as a closed line through the neurons and the cities as small bright dots.
Once that works, make it beautiful:
- Draw the ring as a glowing band whose color slowly shifts along its length, with a faint thread from each city to its nearest neuron.
- When K is small, read off the tour by sorting the cities by the index of their nearest neuron, and show its length.
- Let me click to add a city and drag cities while it solves.
Explain the key ideas in short code comments. When you're done, tell me how to open it and suggest three directions I could take it next, such as comparing against a 2-opt tour, drawing the summed Gaussian field under the band, or trying clustered and spiral city layouts.