Skip to content

Commit

Permalink
fix proportional to ranking slecter
Browse files Browse the repository at this point in the history
  • Loading branch information
khezen committed Mar 11, 2020
1 parent 075d9cb commit 9749db0
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion selecter.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,21 +190,24 @@ func (s proportionalToRankSelecter) Select(pop Population, survivorsSize int) (P
score float64
popLen int
n float64
penalty int
)
pop.Sort()
for newPop.Len() < survivorsSize {
popLen = pop.Len()
leftovers = pop.New(popLen)
penalty = 0
benchmark = float64(popLen*(popLen+1)) / 2
for i := 0; i < popLen; i++ {
if newPop.Len() >= survivorsSize {
break
}
indiv := pop.Get(i)
n = float64(popLen - i)
n = float64(popLen - i - penalty)
score = n * (n + 1) / 2
if rand.Float64() <= 0.25+0.5*score/benchmark {
newPop.Add(indiv)
penalty++
} else {
leftovers.Add(indiv)
}
Expand Down

0 comments on commit 9749db0

Please sign in to comment.