Class: Selection::RoundRobin

Inherits:
Object
  • Object
show all
Defined in:
../lib/round_robin.rb

Overview

Select members of the population one by one, when reaching the last individual, start again from the first one (use wrapping).

Instance Method Summary (collapse)

Constructor Details

- (RoundRobin) initialize(population)

Set the population for the selection.



10
11
12
13
# File '../lib/round_robin.rb', line 10

def initialize population
  @index = 0
  @population = population
end

Instance Method Details

- (Object) select(how_much)

Select more individuals (how_much of them is the argument).



23
24
25
26
27
# File '../lib/round_robin.rb', line 23

def select how_much
  res = []
  how_much.times { res << select_one }
  res
end

- (Object) select_one

Select one individual.



16
17
18
19
20
# File '../lib/round_robin.rb', line 16

def select_one
  res = @population[ @index ]
  @index = (@index+1).divmod( @population.size ).last
  res
end