-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpopulation.rb
51 lines (41 loc) · 1012 Bytes
/
population.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#A Population is defined in this algorithm as a collection of Individuals
#The population is responsible for managing the individuals.
class Population
include PopulationHelper
def initialize config = nil
@config = config if config
@config ||= Configs.new.binary_basic
new_population
end
def new_population
@population = []
@config[:population_size].times do |i|
@population[i] = Individual.new(@config)
end
@population
end
def get_pop
@population
end
def print
puts_pop self
end
def over_write_pop= pop
@population = pop if pop.class == Population
end
def replace_individual old, new
@population[@population.index(old)] = new if new.class == Individual
end
def get_mates
i = self.random_member
j = self.random_member
while i == j
j = self.random_member
end
return [ i, j ]
end
def generation
@generation
end
alias gen generation
end