We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 28f4472 commit 310069eCopy full SHA for 310069e
algorithm/GeneticAlgorithm.py
@@ -70,9 +70,8 @@ def addToBest(self, chromosomeIndex):
70
return
71
72
# find place for new chromosome
73
- j = self._currentBestSize
74
- for i in range(j, -1, -1):
75
- j = i
+ i = self._currentBestSize
+ while i > 0:
76
pos = bestChromosomes[i - 1]
77
# group is not full?
78
if i < length_best:
@@ -85,9 +84,10 @@ def addToBest(self, chromosomeIndex):
85
84
else:
86
# group is full remove worst chromosomes in the group
87
bestFlags[pos] = False
+ i -= 1
88
89
# store chromosome in best chromosome group
90
- bestChromosomes[j] = chromosomeIndex
+ bestChromosomes[i] = chromosomeIndex
91
bestFlags[chromosomeIndex] = True
92
93
# increase current size if it has not reached the limit yet
0 commit comments