← Back to GSA docs

teeline · algorithms/gsa

Gravitational Search Algorithm

Each candidate TSP tour is an agent with a mass proportional to its fitness — better tours weigh more. Every step, the active agent is pulled toward the k-best (heaviest) neighbours via swap-move velocity. The gravitational constant G decays over epochs, shifting the swarm from broad exploration toward fine-grained exploitation.

01234567891011
Agents
01930
#0 · dist=1930 · mass=0.160
11908
#1 · dist=1908 · mass=0.170
21889
#2 · dist=1889 · mass=0.178
31682
#3 · dist=1682 · mass=0.271
42286
#4 · dist=2286 · mass=0.000
52069
#5 · dist=2069 · mass=0.097
62095
#6 · dist=2095 · mass=0.086
72201
#7 · dist=2201 · mass=0.038
gbest tour active agent swarm city kbest source
Press Step or Run to begin
G (gravitational constant) = 20.00
High — broad exploration
epoch
0
step
0/8
gbest dist
1681.8
avg dist
2008
Balanced swarm size
cities: 12agents: 8G₀: 20α: 1kbest: ⌈8/2⌉=4