Skip to content

Commit 15e50b1

Browse files
authored
Merge pull request #601 from peacemo/fix-abc
fix: scout bee phrase of ABC
2 parents 0c50a77 + 81a4fd9 commit 15e50b1

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

niapy/algorithms/basic/abc.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ def run_iteration(self, task, population, population_fitness, best_x, best_fitne
184184
best_fitness = new_solution.f
185185
else:
186186
trials[i] += 1
187+
if trials[i] >= self.limit:
188+
population[i], trials[i] = SolutionABC(task=task, rng=self.rng), 0
189+
if population[i].f < best_fitness:
190+
best_x, best_fitness = population[i].x.copy(), population[i].f
187191
probabilities, t, s = self.calculate_probabilities(population), 0, 0
188192
while t < self.food_number:
189193
if self.random() < probabilities[s]:
@@ -204,12 +208,11 @@ def run_iteration(self, task, population, population_fitness, best_x, best_fitne
204208
best_fitness = solution.f
205209
else:
206210
trials[s] += 1
211+
if trials[i] >= self.limit:
212+
population[i], trials[i] = SolutionABC(task=task, rng=self.rng), 0
213+
if population[i].f < best_fitness:
214+
best_x, best_fitness = population[i].x.copy(), population[i].f
207215
s += 1
208216
if s == self.food_number:
209217
s = 0
210-
mi = np.argmax(trials)
211-
if trials[mi] >= self.limit:
212-
population[mi], trials[mi] = SolutionABC(task=task, rng=self.rng), 0
213-
if population[mi].f < best_fitness:
214-
best_x, best_fitness = population[mi].x.copy(), population[mi].f
215218
return population, np.asarray([f.f for f in population]), best_x, best_fitness, {'trials': trials}

0 commit comments

Comments
 (0)