// Here sweepNum is optimal number of sweeps from paper, i.e., TotalPopulation for (i = 0; i < sweepNum; i++) { wasSwapped = false; for (j = 0; j < TotalPopulation - 1; j++) { // within bounds or random chance if ((phi(j) == 0 and phi(j + 1) == 0) or UniformRandom(0, 1) < Pf) { // compare objective function values if (Value(j) > Value(j + 1)) { swap(j, j + 1); wasSwapped = true; } } else // phi != 0 { // individual j further outside then j + 1 if (phi(j) > phi(j + 1)) { swap(j, j + 1); wasSwapped = true; } } } // if no swap then break if (wasSwapped == false) break; }