← 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
02025
#0 · dist=2025 · mass=0.124
12356
#1 · dist=2356 · mass=0.000
22051
#2 · dist=2051 · mass=0.114
32209
#3 · dist=2209 · mass=0.055
41732
#4 · dist=1732 · mass=0.234
51812
#5 · dist=1812 · mass=0.204
61959
#6 · dist=1959 · mass=0.149
72038
#7 · dist=2038 · mass=0.119
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
1732.1
avg dist
2023
Balanced swarm size
cities: 12agents: 8G₀: 20α: 1kbest: ⌈8/2⌉=4