Module: Selection::SelectMore

Included in:
RankRoulette, Roulette, Tournament
Defined in:
../lib/select_more.rb

Overview

Helper module for various Selection methods. It provides unique_winners atribute support and the “select” method.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (Object) unique_winners

Set the unique_winners attribute (see).



13
14
15
16
# File '../lib/select_more.rb', line 13

def unique_winners
  @unique_winners = false unless defined? @unique_winners
  @unique_winners
end

Instance Method Details

- (Object) select(how_much, population = self.population)

Select more individuals from the population, assuming the user class provides select_one and select_one_internal methods. It can be specified how_much individuals will be selected.



21
22
23
24
25
26
27
28
29
30
31
# File '../lib/select_more.rb', line 21

def select( how_much, population=self.population )
  winners = [ select_one( population ) ]
  ids = [ winners.first.object_id ]
  while winners.size < how_much
    w = select_one_internal
    next if self.unique_winners and ids.include? w.object_id
    winners.push w
    ids.push w.object_id
  end
  winners
end