gga4r 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/gga4r/gga4r_main.rb +2 -0
- data/lib/gga4r/version.rb +1 -1
- data/test/gga4r_test.rb +26 -0
- metadata +11 -9
data/lib/gga4r/gga4r_main.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "yaml"
|
2
2
|
require "logger"
|
3
|
+
require "rubygems"
|
3
4
|
require "active_support"
|
4
5
|
|
5
6
|
class GeneticAlgorithm
|
@@ -134,6 +135,7 @@ class GeneticAlgorithm
|
|
134
135
|
@logger.debug "Shuffled!" if @logger
|
135
136
|
new_childs = []
|
136
137
|
new_generation.in_groups_of(2) do |chromosome1, chromosome2|
|
138
|
+
next if chromosome2.nil?
|
137
139
|
if rand > (1 - @p_combination)
|
138
140
|
@logger.debug "Recombining" if @logger
|
139
141
|
new_childs += chromosome1.recombine(chromosome2)
|
data/lib/gga4r/version.rb
CHANGED
data/test/gga4r_test.rb
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
2
|
|
3
|
+
class IndividualStub < Array
|
4
|
+
def recombine(a)
|
5
|
+
self * 2
|
6
|
+
end
|
7
|
+
def self.create_random_population(num_population = 30)
|
8
|
+
population = []
|
9
|
+
num_population.times do
|
10
|
+
population << IndividualStub.new
|
11
|
+
end
|
12
|
+
return population
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
3
16
|
class Gga4rTest < Test::Unit::TestCase
|
4
17
|
|
5
18
|
def setup
|
@@ -8,4 +21,17 @@ class Gga4rTest < Test::Unit::TestCase
|
|
8
21
|
def test_truth
|
9
22
|
assert true
|
10
23
|
end
|
24
|
+
|
25
|
+
def test_recombine
|
26
|
+
first_pop_even = IndividualStub.create_random_population(30)
|
27
|
+
ga = GeneticAlgorithm.new(first_pop_even)
|
28
|
+
new_pop = ga.recombination!
|
29
|
+
assert true, first_pop_even.size < new_pop.size
|
30
|
+
|
31
|
+
first_pop_odd = IndividualStub.create_random_population(31)
|
32
|
+
ga = GeneticAlgorithm.new(first_pop_odd)
|
33
|
+
new_pop = ga.recombination!
|
34
|
+
assert true, first_pop_odd.size < new_pop.size
|
35
|
+
|
36
|
+
end
|
11
37
|
end
|
metadata
CHANGED
@@ -3,12 +3,11 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: gga4r
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.9.
|
7
|
-
date: 2007-11-
|
6
|
+
version: 0.9.2
|
7
|
+
date: 2007-11-30 00:00:00 +01:00
|
8
8
|
summary: "A Ruby Genetic Algorithm. So simple to use: 1, take a class to evolve it and define fitness, recombine and mutate methods. 2, create a GeneticAlgorithm object with the population. 3, call evolve method as many times as you want.description of gem"
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
|
-
- test
|
12
11
|
email: sergio.espeja@gmail.com
|
13
12
|
homepage: http://gga4r.rubyforge.org
|
14
13
|
rubyforge_project: gga4r
|
@@ -42,12 +41,15 @@ files:
|
|
42
41
|
- test/test_helper.rb
|
43
42
|
- test/gga4r_test.rb
|
44
43
|
- examples/ga_fitness_all_1s.rb
|
45
|
-
test_files:
|
46
|
-
|
47
|
-
rdoc_options:
|
48
|
-
|
49
|
-
|
50
|
-
|
44
|
+
test_files:
|
45
|
+
- test/gga4r_test.rb
|
46
|
+
rdoc_options:
|
47
|
+
- --main
|
48
|
+
- README.txt
|
49
|
+
extra_rdoc_files:
|
50
|
+
- README.txt
|
51
|
+
- CHANGELOG.txt
|
52
|
+
- Manifest.txt
|
51
53
|
executables: []
|
52
54
|
|
53
55
|
extensions: []
|