charlie 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +3 -0
- data/README.txt +1 -1
- data/examples/output/bitstring_royalroad.html +659 -659
- data/examples/output/function_optimization_sombrero.html +1441 -1441
- data/examples/output/function_optimization_twopeak.csv +210 -210
- data/examples/output/function_optimization_twopeak.html +1342 -1342
- data/examples/output/string_weasel.html +249 -249
- data/lib/charlie.rb +1 -1
- data/lib/charlie/crossover.rb +1 -1
- data/lib/charlie/list/list_genotype.rb +4 -2
- data/lib/charlie/selection.rb +3 -1
- metadata +2 -2
data/lib/charlie.rb
CHANGED
data/lib/charlie/crossover.rb
CHANGED
@@ -40,8 +40,10 @@ def StringGenotype(n,elements)
|
|
40
40
|
elements = elements.chars if elements.is_a? String # string to array of chars
|
41
41
|
elements = elements.to_a
|
42
42
|
Class.new(Genotype) {
|
43
|
-
|
44
|
-
|
43
|
+
[self,metaclass].each{|c| c.class_eval{ # include both in class and metaclass
|
44
|
+
define_method(:size){ n }
|
45
|
+
define_method(:elements){ elements }
|
46
|
+
}}
|
45
47
|
def initialize
|
46
48
|
@genes = Array.new(size){ elements.at_rand }
|
47
49
|
end
|
data/lib/charlie/selection.rb
CHANGED
@@ -48,6 +48,7 @@ module RouletteSelection
|
|
48
48
|
|
49
49
|
new_pop = []
|
50
50
|
while new_pop.size < population.size
|
51
|
+
i1 = i2 = nil
|
51
52
|
i1,i2 = [0,0].map{
|
52
53
|
r = rand * sum
|
53
54
|
partial_sum.index partial_sum.find{|x| x > r }
|
@@ -81,6 +82,7 @@ def ScaledRouletteSelection(&block)
|
|
81
82
|
population = population.sort_by(&:fitness)
|
82
83
|
new_pop = []
|
83
84
|
while new_pop.size < population.size
|
85
|
+
i1 = i2 = nil
|
84
86
|
i1,i2 = @@index.at_rand, @@index.at_rand until i1!=i2 # no replacement
|
85
87
|
new_pop += yield(population[i1],population[i2])
|
86
88
|
end
|
@@ -99,7 +101,7 @@ ScaledRouletteSelection = ScaledRouletteSelection()
|
|
99
101
|
# Elitism is saving the best +elite_n+ individuals each generation, to ensure the best solutions are never lost.
|
100
102
|
def Elitism(sel_module,elite_n=1)
|
101
103
|
Module.new{
|
102
|
-
include sel_module
|
104
|
+
include sel_module.dup
|
103
105
|
@@elite_n = elite_n
|
104
106
|
def next_generation(population)
|
105
107
|
population = population.sort_by(&:fitness)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: charlie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sander Land
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-01-
|
12
|
+
date: 2008-01-12 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|