← 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
02137
#0 · dist=2137 · mass=0.127
12039
#1 · dist=2039 · mass=0.168
22312
#2 · dist=2312 · mass=0.056
32038
#3 · dist=2038 · mass=0.168
41890
#4 · dist=1890 · mass=0.228
52319
#5 · dist=2319 · mass=0.053
61961
#6 · dist=1961 · mass=0.200
72449
#7 · dist=2449 · mass=0.000
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
1890.4
avg dist
2143
Balanced swarm size
cities: 12agents: 8G₀: 20α: 1kbest: ⌈8/2⌉=4