Skip to content

Add traveling salesman visualizer at /tsp#168

Merged
ianalloway merged 2 commits into
mainfrom
claude/tsp-visualizer-729tge
Jul 22, 2026
Merged

Add traveling salesman visualizer at /tsp#168
ianalloway merged 2 commits into
mainfrom
claude/tsp-visualizer-729tge

Conversation

@ianalloway

Copy link
Copy Markdown
Owner

Summary

  • Adds /tsp — watch a TSP tour get built greedily, then untangled by 2-opt in real time
  • src/features/tsp/tour.ts: nearest-neighbor construction and 2-opt segment-reversal improvement, both as generators yielding per-step events; tour length; random city scattering
  • src/pages/Tsp.tsx: canvas with cyan cities (yellow ring on start), animated tour, phase status, live tour length, %-saved readout, city presets (20/40/80), speed slider, click-to-add cities
  • src/App.tsx: lazy-loaded /tsp route with SEO metadata

How it works

  • Phase 1 — greedy: nearest-neighbor extends the path one city per event; you can see it paint itself into corners (the long "regret" edges)
  • Phase 2 — 2-opt: any two edges that would be shorter reconnected get their intervening segment reversed; each improving swap yields, so crossings visibly pop open one at a time until a full pass finds no improvement (local optimum)
  • The header tracks live tour length; when done it reports how much 2-opt saved over the greedy tour (typically 10–25% on random instances)
  • Clicking adds cities between runs; solve is disabled while running

Test plan

  • Load /tsp — 40 cities scattered; solve builds the greedy path city by city
  • The greedy tour has visible crossings; 2-opt phase removes them one at a time
  • Finished tour is a closed loop with no crossings; "2-opt saved N%" appears
  • Tour-length number decreases monotonically during improvement
  • 80 cities still animates smoothly; speed slider accelerates both phases
  • Click to add a city — tour clears, solve incorporates it
  • New cities rerolls; start city marked with a yellow ring
  • Resize rescatters cleanly

Generated by Claude Code

Two-stage solve as a single generator pipeline: nearest-neighbor
construction yields the tour one city at a time, then 2-opt repeatedly
reverses segments whose endpoints would reconnect shorter, yielding
after each improving swap until a full pass finds none (a 2-opt local
optimum). Header tracks live tour length and, once done, the percent
saved over the greedy tour. The route closes visually when improvement
begins; crossings visibly untangle. Click adds cities between runs;
city presets 20/40/80; speed slider controls events per tick.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WgEKRuVdor8KhaiPkv38aQ
@netlify

netlify Bot commented Jul 19, 2026

Copy link
Copy Markdown

Deploy Preview for ianalloway ready!

Name Link
🔨 Latest commit 6511b9d
🔍 Latest deploy log https://app.netlify.com/projects/ianalloway/deploys/6a614b7f3ca9ab0008a62332
😎 Deploy Preview https://deploy-preview-168--ianalloway.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@vercel

vercel Bot commented Jul 19, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ian-web-forge Ready Ready Preview, Comment Jul 22, 2026 11:00pm

@ianalloway
ianalloway marked this pull request as ready for review July 19, 2026 04:56
Copilot AI review requested due to automatic review settings July 19, 2026 04:56
@cursor

cursor Bot commented Jul 19, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@ianalloway
ianalloway merged commit f86c1e7 into main Jul 22, 2026
4 of 5 checks passed
@ianalloway
ianalloway deleted the claude/tsp-visualizer-729tge branch July 22, 2026 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants