@@ -184,6 +184,10 @@ def run_iteration(self, task, population, population_fitness, best_x, best_fitne
184
184
best_fitness = new_solution .f
185
185
else :
186
186
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
187
191
probabilities , t , s = self .calculate_probabilities (population ), 0 , 0
188
192
while t < self .food_number :
189
193
if self .random () < probabilities [s ]:
@@ -204,12 +208,11 @@ def run_iteration(self, task, population, population_fitness, best_x, best_fitne
204
208
best_fitness = solution .f
205
209
else :
206
210
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
207
215
s += 1
208
216
if s == self .food_number :
209
217
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
215
218
return population , np .asarray ([f .f for f in population ]), best_x , best_fitness , {'trials' : trials }
0 commit comments