Java Swing + Ant Colony Optimization

ACO TSP Solver

A desktop project with a browser demo for exploring how ant colony search builds and improves tours for the Traveling Salesman Problem.

Browser demo

Run the TSP solver here

This canvas demo mirrors the Java solver logic so the project can be shown directly on GitHub Pages.

Ready

What it shows

Interactive ACO exploration

Live tours

Each iteration draws the current ant tours and keeps the best route visible on top.

Two datasets

Use random generated cities or the built-in NYC landmark set with a map background.

Tunable parameters

Change ants, iterations, alpha, beta, evaporation, pheromone deposit, and animation delay.

Road block demo

Toggle a blocked NYC edge and compare how the solver adapts its possible tours.

Code layout

Small packages with clear jobs

The app is split so the Swing UI, solver, city data, and model code can be read and tested independently.

uiSwing frame and cached drawing panel
solverAnt Colony Optimization implementation
modelCity record and distance matrix creation
dataRandom and NYC sample datasets

JFR profile

CPU-bound in candidate selection

Java Flight Recorder showed the main cost in ACO.pickNext(...), which is expected because each ant scans candidate cities while constructing a tour.

82%

sampled method time in candidate selection

3

young GC collections in the profiling run

2.4 ms

longest observed GC pause

Try it

Run the desktop app locally

mvn compile
java -cp target/classes tsp_aco_gui.AntColonyTSP

Requires Java 21+ and Maven 3.9+.