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