charlie 0.5.0 → 0.6.0
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 +11 -0
- data/Manifest.txt +5 -1
- data/README.txt +33 -43
- data/Rakefile +30 -5
- data/TODO.txt +11 -9
- data/data/CROSSOVER +6 -1
- data/data/GENOTYPE +5 -2
- data/data/MUTATION +5 -0
- data/data/SELECTION +2 -3
- data/examples/money.rb +35 -0
- data/examples/output/flattened_sombero.html +3849 -3849
- data/examples/output/flattened_sombero2_.html +2321 -2321
- data/examples/output/fopt1_dblopt.html +1276 -1276
- data/examples/output/hill10.html +3906 -3906
- data/examples/output/hill2.csv +24 -24
- data/examples/output/hill2.html +177 -177
- data/examples/output/royalroad1_report.html +531 -531
- data/examples/output/royalroad2_report.html +592 -592
- data/examples/output/royalroadquick_report.html +243 -243
- data/examples/output/tsp.html +947 -403
- data/examples/output/weasel1_report.html +616 -616
- data/examples/output/weasel2_report.html +115 -115
- data/examples/tree.rb +90 -0
- data/examples/tsp.rb +19 -12
- data/lib/charlie/etc/monkey.rb +28 -44
- data/lib/charlie/genotype.rb +30 -1
- data/lib/charlie/permutation/permutation.rb +52 -1
- data/lib/charlie/population.rb +58 -20
- data/lib/charlie/selection.rb +1 -1
- data/lib/charlie/tree/tree.rb +128 -0
- data/lib/charlie.rb +2 -5
- data/test/t_common.rb +18 -2
- data/test/test_benchmark.rb +12 -10
- data/test/test_evolve.rb +87 -0
- data/test/test_permutation.rb +37 -3
- data/test/test_tree.rb +57 -0
- metadata +69 -50
- data/test/test_basic.rb +0 -32
metadata
CHANGED
@@ -1,33 +1,42 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4
|
3
|
-
specification_version: 1
|
4
2
|
name: charlie
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2007-12-19 00:00:00 +01:00
|
8
|
-
summary: A genetic algorithms library for Ruby.
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: sander.land+ruby@gmail.com
|
12
|
-
homepage: http://charlie.rubyforge.org
|
13
|
-
rubyforge_project: charlie
|
14
|
-
description: "== DESCRIPTION: Charlie is a library for genetic algorithms. It allows you to easily create and run genetic algorithms. You can choose selection, crossover or mutation strategies from either built-in options or simply write your own. It also includes methods that can be used to compare several of these strategies, generating reports with statistics that can be used to determine which one to use in future problems. == EXAMPLES: This example finds the binary representation of the number 512. require 'rubygems' require 'charlie' class Find512 < BitStringGenotype(10) # choose a genotype, in this case a list of 10 bits represents a solution # Define a fitness function. This one returns minus the offset to the best solution, so a higher number is better. # Usually, you won't know the best solution, and will define this as some value that needs to be maximized. def fitness # Use the 'genes' function to retrieve the array of bits representing this solution. -(genes.map(&:to_s).join.to_i(2) - 512).abs end end # Finally, create an instance of a population (with the default size of 20) and let it run for the default number of 100 generations. Population.new(Find512).evolve_on_console"
|
15
|
-
autorequire:
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
4
|
+
version: 0.6.0
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- Sander Land
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2007-12-26 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hoe
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.4.0
|
23
|
+
version:
|
24
|
+
description: "== DESCRIPTION: Charlie is a library for genetic algorithms (GA) and genetic programming (GP). == FEATURES: - Quickly develop GAs by combining several parts (genotype, selection, crossover, mutation) provided by the library. - Sensible defaults are provided with any genotype, so often you only need to define a fitness function. - Easily replace any of the parts by your own code. - Test different strategies in GA, and generate reports comparing them. Example report: http://charlie.rubyforge.org/example_report.html == EXAMPLES: This example solves a TSP problem (also quiz #142): N=5 CITIES = (0...N).map{|i| (0...N).map{|j| [i,j] } }.inject{|a,b|a+b} class TSP < PermutationGenotype(CITIES.size) def fitness d=0 (genes + [genes[0]]).each_cons(2){|a,b| a,b=CITIES[a],CITIES[b] d += Math.sqrt( (a[0]-b[0])**2 + (a[1]-b[1])**2 ) } -d # lower distance -> higher fitness. end use EdgeRecombinationCrossover, InversionMutator end Population.new(TSP,20).evolve_on_console(50) This example finds a polynomial which approximates cos(x) class Cos < TreeGenotype([proc{3*rand-1.5},:x], [:+,:*,:-], [:-@]) def fitness -[0,0.33,0.66,1].map{|x| (eval_genes(:x=>x) - Math.cos(x)).abs }.max end use TournamentSelection(4) end Population.new(Cos).evolve_on_console(500)"
|
25
|
+
email: sander.land+ruby@gmail.com
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- History.txt
|
32
|
+
- Manifest.txt
|
33
|
+
- README.txt
|
34
|
+
- TODO.txt
|
35
|
+
- data/GENOTYPE
|
36
|
+
- data/SELECTION
|
37
|
+
- data/CROSSOVER
|
38
|
+
- data/MUTATION
|
39
|
+
- data/BENCHMARK
|
31
40
|
files:
|
32
41
|
- History.txt
|
33
42
|
- Manifest.txt
|
@@ -46,6 +55,7 @@ files:
|
|
46
55
|
- examples/gladiatorial_simple.rb
|
47
56
|
- examples/gladiatorial_sunburn.rb
|
48
57
|
- examples/gridwalk.rb
|
58
|
+
- examples/money.rb
|
49
59
|
- examples/output/flattened_sombero.html
|
50
60
|
- examples/output/flattened_sombero2_.html
|
51
61
|
- examples/output/fopt1_dblopt.html
|
@@ -61,6 +71,7 @@ files:
|
|
61
71
|
- examples/royalroad.rb
|
62
72
|
- examples/royalroad2.rb
|
63
73
|
- examples/simple_climb_hill2.rb
|
74
|
+
- examples/tree.rb
|
64
75
|
- examples/tsp.rb
|
65
76
|
- examples/weasel.rb
|
66
77
|
- lib/charlie.rb
|
@@ -75,41 +86,49 @@ files:
|
|
75
86
|
- lib/charlie/permutation/permutation.rb
|
76
87
|
- lib/charlie/population.rb
|
77
88
|
- lib/charlie/selection.rb
|
89
|
+
- lib/charlie/tree/tree.rb
|
78
90
|
- test/t_common.rb
|
79
|
-
- test/test_basic.rb
|
80
91
|
- test/test_benchmark.rb
|
81
92
|
- test/test_cross.rb
|
93
|
+
- test/test_evolve.rb
|
82
94
|
- test/test_mutator.rb
|
83
95
|
- test/test_permutation.rb
|
84
96
|
- test/test_sel.rb
|
97
|
+
- test/test_tree.rb
|
98
|
+
has_rdoc: true
|
99
|
+
homepage: http://charlie.rubyforge.org
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options:
|
102
|
+
- --main
|
103
|
+
- README.txt
|
104
|
+
- --inline-source
|
105
|
+
- --line-numbers
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: "0"
|
113
|
+
version:
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: "0"
|
119
|
+
version:
|
120
|
+
requirements: []
|
121
|
+
|
122
|
+
rubyforge_project: charlie
|
123
|
+
rubygems_version: 1.0.1
|
124
|
+
signing_key:
|
125
|
+
specification_version: 2
|
126
|
+
summary: A genetic algorithms library for Ruby.
|
85
127
|
test_files:
|
86
128
|
- test/test_mutator.rb
|
87
129
|
- test/test_cross.rb
|
130
|
+
- test/test_evolve.rb
|
88
131
|
- test/test_sel.rb
|
89
|
-
- test/test_basic.rb
|
90
132
|
- test/test_benchmark.rb
|
133
|
+
- test/test_tree.rb
|
91
134
|
- test/test_permutation.rb
|
92
|
-
rdoc_options:
|
93
|
-
- --main
|
94
|
-
- README.txt
|
95
|
-
extra_rdoc_files:
|
96
|
-
- History.txt
|
97
|
-
- Manifest.txt
|
98
|
-
- README.txt
|
99
|
-
- TODO.txt
|
100
|
-
executables: []
|
101
|
-
|
102
|
-
extensions: []
|
103
|
-
|
104
|
-
requirements: []
|
105
|
-
|
106
|
-
dependencies:
|
107
|
-
- !ruby/object:Gem::Dependency
|
108
|
-
name: hoe
|
109
|
-
version_requirement:
|
110
|
-
version_requirements: !ruby/object:Gem::Version::Requirement
|
111
|
-
requirements:
|
112
|
-
- - ">="
|
113
|
-
- !ruby/object:Gem::Version
|
114
|
-
version: 1.3.0
|
115
|
-
version:
|
data/test/test_basic.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
require 't_common'
|
2
|
-
|
3
|
-
class BasicTest < Test::Unit::TestCase
|
4
|
-
def test_console
|
5
|
-
r = Population.new(TestProblem,10).evolve_on_console(10)
|
6
|
-
assert_respond_to r, :[]
|
7
|
-
assert_respond_to r[-1], :fitness
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_silent
|
11
|
-
r = Population.new(TestProblem,10).evolve_silent(10)
|
12
|
-
assert_respond_to r, :[]
|
13
|
-
assert_respond_to r[-1], :fitness
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_continue
|
17
|
-
p = Population.new(TestProblem,10)
|
18
|
-
best3 = p.evolve_silent(3)[-1].fitness
|
19
|
-
best33 = p.evolve_silent(30)[-1].fitness
|
20
|
-
# Not true for all problems, but in this case the probability of failure is negligible
|
21
|
-
assert( best33 > best3, "test_continue failed. Please rerun test to make sure this isn't just extremely bad luck.")
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_testclass
|
25
|
-
assert_nothing_raised{
|
26
|
-
Population.new(TestClass(Module::new),10).evolve_silent(10)
|
27
|
-
Population.new(TestClass(UniformCrossover),10).evolve_silent(10)
|
28
|
-
Population.new(TestClass(ListMutator(:single_point,:gaussian) ),10).evolve_silent(10)
|
29
|
-
Population.new(TestClass(TournamentSelection(4)),10).evolve_silent(10)
|
30
|
-
}
|
31
|
-
end
|
32
|
-
end
|