Skip to content

Commit bd4a5c9

Browse files
author
tranhuyhung1998
committed
fix roulette wheel
1 parent 4b41575 commit bd4a5c9

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

geneticpython/core/operators/replacement/roulette_wheel_replacement.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ def replace(self, size: int, population: List[Individual],
2222
selection = RouletteWheelSelection()
2323
best_indv = min(population, key=lambda indv: indv._objective)
2424

25-
bad_pop = list()
26-
for indv in population:
27-
if not abs(indv._objective - best_indv._objective) < self.__EPS:
28-
bad_pop.append(indv)
25+
bad_pop = population.copy()
26+
# for indv in population:
27+
# if not abs(indv._objective - best_indv._objective) < self.__EPS:
28+
# bad_pop.append(indv)
2929

3030
new_population = [best_indv]
3131
new_population.extend(selection.select(

geneticpython/core/operators/selection/roulette_wheel_selection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def select(self, size: int,
3939
idx -= 1
4040

4141
if idx == -len(selected):
42-
idx = random_state.randint(0, len(selected)-1)
42+
idx = random_state.randint(0, len(selected))
4343

4444
selected_indvs.append(population[idx])
4545
selected[idx] = False

0 commit comments

Comments
 (0)