charlie 0.5.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.
Files changed (54) hide show
  1. data/History.txt +3 -0
  2. data/Manifest.txt +53 -0
  3. data/README.txt +90 -0
  4. data/Rakefile +43 -0
  5. data/TODO.txt +28 -0
  6. data/data/BENCHMARK +53 -0
  7. data/data/CROSSOVER +49 -0
  8. data/data/GENOTYPE +49 -0
  9. data/data/MUTATION +43 -0
  10. data/data/SELECTION +48 -0
  11. data/data/template.html +34 -0
  12. data/examples/bit.rb +10 -0
  13. data/examples/function_opt_2peak.rb +24 -0
  14. data/examples/function_opt_sombero.rb +38 -0
  15. data/examples/gladiatorial_simple.rb +17 -0
  16. data/examples/gladiatorial_sunburn.rb +89 -0
  17. data/examples/gridwalk.rb +29 -0
  18. data/examples/output/flattened_sombero.html +6400 -0
  19. data/examples/output/flattened_sombero2_.html +3576 -0
  20. data/examples/output/fopt1_dblopt.html +2160 -0
  21. data/examples/output/hill10.html +5816 -0
  22. data/examples/output/hill2.csv +24 -0
  23. data/examples/output/hill2.html +384 -0
  24. data/examples/output/royalroad1_report.html +1076 -0
  25. data/examples/output/royalroad2_report.html +1076 -0
  26. data/examples/output/royalroadquick_report.html +504 -0
  27. data/examples/output/tsp.html +632 -0
  28. data/examples/output/weasel1_report.html +1076 -0
  29. data/examples/output/weasel2_report.html +240 -0
  30. data/examples/royalroad.rb +26 -0
  31. data/examples/royalroad2.rb +18 -0
  32. data/examples/simple_climb_hill2.rb +47 -0
  33. data/examples/tsp.rb +35 -0
  34. data/examples/weasel.rb +36 -0
  35. data/lib/charlie.rb +35 -0
  36. data/lib/charlie/crossover.rb +49 -0
  37. data/lib/charlie/etc/minireport.rb +45 -0
  38. data/lib/charlie/etc/monkey.rb +136 -0
  39. data/lib/charlie/genotype.rb +45 -0
  40. data/lib/charlie/list/list_crossover.rb +30 -0
  41. data/lib/charlie/list/list_genotype.rb +53 -0
  42. data/lib/charlie/list/list_mutate.rb +75 -0
  43. data/lib/charlie/mutate.rb +25 -0
  44. data/lib/charlie/permutation/permutation.rb +47 -0
  45. data/lib/charlie/population.rb +156 -0
  46. data/lib/charlie/selection.rb +162 -0
  47. data/test/t_common.rb +32 -0
  48. data/test/test_basic.rb +32 -0
  49. data/test/test_benchmark.rb +56 -0
  50. data/test/test_cross.rb +28 -0
  51. data/test/test_mutator.rb +44 -0
  52. data/test/test_permutation.rb +23 -0
  53. data/test/test_sel.rb +39 -0
  54. metadata +115 -0
@@ -0,0 +1,44 @@
1
+ require 't_common'
2
+
3
+ ms = [:single_point,:single_point[],[:single_point],:n_point,:n_point[],:n_point[3],:expected_n,:expected_n[1],:probability,:probability[0.3]]
4
+ pm = [:gaussian,:gaussian[],:gaussian[0.25],:uniform,:uniform[0.1],:flip,:replace[0.2,0.1,0.0,-0.1,-0.2]]
5
+ $mut_mth = [NullMutator]
6
+ ms.each{|m| pm.each{|p| $mut_mth << ListMutator(m,p) } }
7
+
8
+
9
+ class TestMutator < Test::Unit::TestCase
10
+ def test_mutate
11
+ $mut_mth.each{|m|
12
+ klass = TestClass(m)
13
+ assert_nothing_raised("#{m} failed") { Population.new(klass,10).evolve_silent(10) }
14
+ }
15
+ end
16
+
17
+ def test_bit
18
+ klass = TestClass(ListMutator(:single_point,:flip),RoyalRoad)
19
+ p = nil
20
+ assert_nothing_raised{ p=Population.new(klass,10).evolve_silent(10) }
21
+ assert p.all?{|s| s.genes.all?{|x| x==0 || x==1 }}
22
+ klass = TestClass(ListMutator(:expected_n[100],:replace[0,1]),RoyalRoad)
23
+ assert_nothing_raised{ p=Population.new(klass,10).evolve_silent(10) }
24
+ assert p.all?{|s| s.genes.all?{|x| x==0 || x==1 }}
25
+ end
26
+
27
+ def test_str
28
+ klass = TestClass(ListMutator(:single_point,:replace['a','b']),StringA)
29
+ p = nil
30
+ assert_nothing_raised{ p=Population.new(klass,10).evolve_silent(10) }
31
+ assert p.all?{|s| s.genes.all?{|x| ('a'..'d')===x }}
32
+
33
+ klass = TestClass(ListMutator(:single_point,:replace['z','x']),StringA)
34
+ assert_nothing_raised{ p=Population.new(klass,10).evolve_silent(10) }
35
+ assert p.all?{|s| s.genes.all?{|x| ['a','b','c','d','x','z'].include? x }}
36
+ end
37
+
38
+ def test_pmutate
39
+ klass = TestClass(PMutate(0.5,ListMutator(:single_point,:replace['a','b'])),StringA)
40
+ p = nil
41
+ assert_nothing_raised{ p=Population.new(klass,10).evolve_silent(10) }
42
+ assert p.all?{|s| s.genes.all?{|x| ('a'..'d')===x }}
43
+ end
44
+ end
@@ -0,0 +1,23 @@
1
+ require 't_common'
2
+
3
+ N=10
4
+
5
+ #CITIES = (0...N).map{|i| th = i * 2 * Math::PI / N; [Math.cos(th),Math.sin(th)] }
6
+ #p CITIES
7
+
8
+ class PermutationTest < PermutationGenotype(N)
9
+ def fitness
10
+ (0...N).zip_with(genes){|a,b| a==b ? 1 : 0}.sum
11
+ end
12
+ end
13
+
14
+
15
+ class PermTests < Test::Unit::TestCase
16
+ def test_evolve
17
+ p=nil
18
+ assert_nothing_raised{
19
+ p=Population.new(PermutationTest,20).evolve_silent(20)
20
+ }
21
+ p.each{|s| assert_equal s.genes.sort, (0...N).to_a }
22
+ end
23
+ end
data/test/test_sel.rb ADDED
@@ -0,0 +1,39 @@
1
+ require 't_common'
2
+
3
+ #ObjectSpace.each_object(Module){|m|
4
+ # $sel_mth << m if m.instance_methods.include?('next_generation')
5
+ #}
6
+ #p $sel_mth
7
+ $sel_mth = [RouletteSelection, RandomSelection]
8
+
9
+ $sel_mth += [TournamentSelection(3),TournamentSelection(4,1),TournamentSelection(8,30),
10
+ TruncationSelection(0.0),TruncationSelection(0.3),TruncationSelection(1), TruncationSelection(6),
11
+ ScaledRouletteSelection(), ScaledRouletteSelection{|i| 2*i+1 }, ScaledRouletteSelection{|i| i<10 ? 1 : i }
12
+ ]
13
+
14
+ $sel_mth = $sel_mth.uniq
15
+
16
+ class TestSelection < Test::Unit::TestCase
17
+ def test_selection
18
+ $sel_mth.each{|s|
19
+ klass = TestClass(s)
20
+ assert_nothing_raised{ Population.new(klass,10).evolve_silent(10) }
21
+ }
22
+ end
23
+
24
+ def test_elitism
25
+ $sel_mth.map{|s| Elitism(s,rand(4)) }.each{|s|
26
+ klass = TestClass(s)
27
+ assert_nothing_raised{ Population.new(klass,10).evolve_silent(10) }
28
+ }
29
+ end
30
+
31
+ def test_singlechild
32
+ scc = TestClass(SingleChild(NullCrossover))
33
+ $sel_mth.each{|s|
34
+ klass = TestClass(s,scc)
35
+ assert_nothing_raised{ Population.new(klass,10).evolve_silent(10) }
36
+ }
37
+ end
38
+
39
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.4
3
+ specification_version: 1
4
+ name: charlie
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.5.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:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Sander Land
31
+ files:
32
+ - History.txt
33
+ - Manifest.txt
34
+ - README.txt
35
+ - Rakefile
36
+ - TODO.txt
37
+ - data/BENCHMARK
38
+ - data/CROSSOVER
39
+ - data/GENOTYPE
40
+ - data/MUTATION
41
+ - data/SELECTION
42
+ - data/template.html
43
+ - examples/bit.rb
44
+ - examples/function_opt_2peak.rb
45
+ - examples/function_opt_sombero.rb
46
+ - examples/gladiatorial_simple.rb
47
+ - examples/gladiatorial_sunburn.rb
48
+ - examples/gridwalk.rb
49
+ - examples/output/flattened_sombero.html
50
+ - examples/output/flattened_sombero2_.html
51
+ - examples/output/fopt1_dblopt.html
52
+ - examples/output/hill10.html
53
+ - examples/output/hill2.csv
54
+ - examples/output/hill2.html
55
+ - examples/output/royalroad1_report.html
56
+ - examples/output/royalroad2_report.html
57
+ - examples/output/royalroadquick_report.html
58
+ - examples/output/tsp.html
59
+ - examples/output/weasel1_report.html
60
+ - examples/output/weasel2_report.html
61
+ - examples/royalroad.rb
62
+ - examples/royalroad2.rb
63
+ - examples/simple_climb_hill2.rb
64
+ - examples/tsp.rb
65
+ - examples/weasel.rb
66
+ - lib/charlie.rb
67
+ - lib/charlie/crossover.rb
68
+ - lib/charlie/etc/minireport.rb
69
+ - lib/charlie/etc/monkey.rb
70
+ - lib/charlie/genotype.rb
71
+ - lib/charlie/list/list_crossover.rb
72
+ - lib/charlie/list/list_genotype.rb
73
+ - lib/charlie/list/list_mutate.rb
74
+ - lib/charlie/mutate.rb
75
+ - lib/charlie/permutation/permutation.rb
76
+ - lib/charlie/population.rb
77
+ - lib/charlie/selection.rb
78
+ - test/t_common.rb
79
+ - test/test_basic.rb
80
+ - test/test_benchmark.rb
81
+ - test/test_cross.rb
82
+ - test/test_mutator.rb
83
+ - test/test_permutation.rb
84
+ - test/test_sel.rb
85
+ test_files:
86
+ - test/test_mutator.rb
87
+ - test/test_cross.rb
88
+ - test/test_sel.rb
89
+ - test/test_basic.rb
90
+ - test/test_benchmark.rb
91
+ - 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: