@@ -112,7 +112,6 @@ def generate_population(tune_params, max_idx, popsize, searchspace, constraint_a
112
112
for key in tune_params :
113
113
ind .append (random .choice (tune_params [key ]))
114
114
population .append (ind )
115
- population = population
116
115
return population
117
116
118
117
@@ -225,9 +224,8 @@ def differential_evolution(searchspace, cost_func, bounds, popsize, maxiter, F,
225
224
if trial_cost <= population_cost [i ]:
226
225
227
226
# check if trial_vector is not already in population
228
- idxs = [idx for idx in range (popsize ) if idx != i ]
229
- if trial_vector not in population [idxs ]:
230
- population [i ] = np .array (trial_vector )
227
+ if population .count (trial_vector ) == 0 :
228
+ population [i ] = trial_vector
231
229
population_cost [i ] = trial_cost
232
230
no_change = False
233
231
@@ -352,7 +350,7 @@ def binomial_crossover(donor_vector, target, CR):
352
350
crossover_points [np .random .randint (0 , dimensions )] = True
353
351
354
352
# Apply crossover
355
- trial_vector [crossover_points ] = donor_vector [crossover_points ]
353
+ trial_vector [crossover_points ] = np . array ( donor_vector ) [crossover_points ]
356
354
357
355
return list (trial_vector )
358
356
@@ -376,7 +374,7 @@ def exponential_crossover(donor_vector, target, CR):
376
374
l = 0
377
375
while np .random .rand () < CR and l < dimensions :
378
376
crossover_point = (start_point + l ) % dimensions
379
- trial_idx [crossover_point ] = donor_vector [crossover_point ]
377
+ trial_idx [crossover_point ] = np . array ( donor_vector ) [crossover_point ]
380
378
l += 1
381
379
382
380
return list (trial_idx )
0 commit comments