charlie 0.6.0 → 0.7.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 (66) hide show
  1. data/History.txt +14 -0
  2. data/Manifest.txt +13 -22
  3. data/README.txt +3 -3
  4. data/Rakefile +1 -1
  5. data/TODO.txt +11 -21
  6. data/data/BENCHMARK +25 -23
  7. data/data/CROSSOVER +5 -1
  8. data/data/GENOTYPE +6 -6
  9. data/data/MUTATION +19 -7
  10. data/data/SELECTION +2 -1
  11. data/data/template.html +2 -1
  12. data/examples/EXAMPLES_README.txt +70 -0
  13. data/examples/bitstring.rb +72 -0
  14. data/examples/{gladiatorial_sunburn.rb → coevolution.rb} +80 -22
  15. data/examples/function_optimization.rb +113 -0
  16. data/examples/output/{royalroad1_report.html → bitstring_royalroad.html} +822 -655
  17. data/examples/output/function_optimization_sombrero.html +2289 -0
  18. data/examples/output/function_optimization_twopeak.csv +210 -0
  19. data/examples/output/function_optimization_twopeak.html +2477 -0
  20. data/examples/output/string_weasel.html +513 -0
  21. data/examples/output/tsp.html +633 -882
  22. data/examples/{money.rb → permutation.rb} +20 -8
  23. data/examples/string.rb +98 -0
  24. data/examples/tree.rb +37 -12
  25. data/examples/tsp.rb +34 -22
  26. data/lib/charlie.rb +5 -1
  27. data/lib/charlie/1.9fixes.rb +46 -0
  28. data/lib/charlie/crossover.rb +31 -14
  29. data/lib/charlie/etc/minireport.rb +5 -4
  30. data/lib/charlie/etc/monkey.rb +11 -8
  31. data/lib/charlie/gabenchmark.rb +230 -0
  32. data/lib/charlie/genotype.rb +4 -0
  33. data/lib/charlie/list/list_crossover.rb +25 -5
  34. data/lib/charlie/mutate.rb +34 -7
  35. data/lib/charlie/permutation/permutation.rb +34 -6
  36. data/lib/charlie/population.rb +12 -122
  37. data/lib/charlie/selection.rb +1 -0
  38. data/lib/charlie/tree/tree.rb +179 -17
  39. data/test/t_common.rb +1 -1
  40. data/test/test_benchmark.rb +19 -5
  41. data/test/test_cross.rb +23 -1
  42. data/test/test_evolve.rb +14 -1
  43. data/test/test_mutator.rb +28 -2
  44. data/test/test_permutation.rb +23 -1
  45. data/test/test_sel.rb +3 -1
  46. data/test/test_tree.rb +63 -1
  47. metadata +17 -25
  48. data/examples/bit.rb +0 -10
  49. data/examples/function_opt_2peak.rb +0 -24
  50. data/examples/function_opt_sombero.rb +0 -38
  51. data/examples/gladiatorial_simple.rb +0 -17
  52. data/examples/gridwalk.rb +0 -29
  53. data/examples/output/flattened_sombero.html +0 -6400
  54. data/examples/output/flattened_sombero2_.html +0 -3576
  55. data/examples/output/fopt1_dblopt.html +0 -2160
  56. data/examples/output/hill10.html +0 -5816
  57. data/examples/output/hill2.csv +0 -24
  58. data/examples/output/hill2.html +0 -384
  59. data/examples/output/royalroad2_report.html +0 -1076
  60. data/examples/output/royalroadquick_report.html +0 -504
  61. data/examples/output/weasel1_report.html +0 -1076
  62. data/examples/output/weasel2_report.html +0 -240
  63. data/examples/royalroad.rb +0 -26
  64. data/examples/royalroad2.rb +0 -18
  65. data/examples/simple_climb_hill2.rb +0 -47
  66. data/examples/weasel.rb +0 -36
@@ -1,240 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
-
3
- <html xmlns="http://www.w3.org/1999/xhtml">
4
- <head>
5
- <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
6
- <title>GA Benchmark Report</title>
7
- <style type='text/css'>
8
- table{
9
- background: #ccc;
10
- font-family: Verdana, Helvetica, sans-serif;
11
- }
12
- th {
13
- background: #666;
14
- color: white;
15
- padding: 3px;
16
- font-weight: bold;
17
- }
18
- td {
19
- color: #333;
20
- background: #e2e2e2;
21
- padding: 2px;
22
- text-align: center;
23
- }
24
- </style>
25
-
26
- </script>
27
- <script type="text/javascript">
28
-
29
- </script>
30
- </head>
31
- <body>
32
- <h1>Information</h1>
33
-
34
- <table>
35
- <tr><td>Genotype class</td><td>Weasel</td></tr>
36
- <tr><td>Population size</td><td>20</td></tr>
37
- <tr><td># of generations per run</td><td>50</td></tr>
38
- <tr><td>Number of tests </td><td>12</td></tr>
39
- <tr><td>Tests repeated </td><td>10 times</td></tr>
40
- <tr><td>Number of runs </td><td>120</td></tr>
41
- <tr><td>Total number of generations </td><td>6000</td></tr>
42
- <tr><td>Total time</td><td>23.51 seconds</td></tr>
43
- </table
44
- <h1>Stats for all</h1><table>
45
- <tr><th>.</th><th>min</th><th>max</th><th>avg</th><th>stddev</th><th>avg-time</th></tr>
46
- <tr>
47
- <td>All</td>
48
- <td>13.00000</td>
49
- <td>22.00000</td>
50
- <td>17.80833</td>
51
- <td>2.25202</td>
52
- <td>0.19585</td>
53
- </tr>
54
- </table><h1>Stats for selection</h1><table>
55
- <tr><th>selection</th><th>min</th><th>max</th><th>avg</th><th>stddev</th><th>avg-time</th></tr>
56
- <tr>
57
- <td>TruncationSelection(0.2)</td>
58
- <td>13.00000</td>
59
- <td>22.00000</td>
60
- <td>17.86667</td>
61
- <td>2.17153</td>
62
- <td>0.19556</td>
63
- </tr>
64
- <tr>
65
- <td>TruncationSelection(1)</td>
66
- <td>13.00000</td>
67
- <td>22.00000</td>
68
- <td>17.75000</td>
69
- <td>2.32827</td>
70
- <td>0.19614</td>
71
- </tr>
72
- </table><h1>Stats for crossover</h1><table>
73
- <tr><th>crossover</th><th>min</th><th>max</th><th>avg</th><th>stddev</th><th>avg-time</th></tr>
74
- <tr>
75
- <td>UniformCrossover</td>
76
- <td>14.00000</td>
77
- <td>22.00000</td>
78
- <td>19.00000</td>
79
- <td>2.00000</td>
80
- <td>0.21745</td>
81
- </tr>
82
- <tr>
83
- <td>SinglePointCrossover</td>
84
- <td>14.00000</td>
85
- <td>22.00000</td>
86
- <td>18.20000</td>
87
- <td>1.90000</td>
88
- <td>0.18830</td>
89
- </tr>
90
- <tr>
91
- <td>NullCrossover</td>
92
- <td>13.00000</td>
93
- <td>20.00000</td>
94
- <td>16.22500</td>
95
- <td>1.87733</td>
96
- <td>0.18179</td>
97
- </tr>
98
- </table><h1>Stats for mutation</h1><table>
99
- <tr><th>mutation</th><th>min</th><th>max</th><th>avg</th><th>stddev</th><th>avg-time</th></tr>
100
- <tr>
101
- <td>ListMutator([:n_point, 2],[:replace, "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", " "])</td>
102
- <td>13.00000</td>
103
- <td>22.00000</td>
104
- <td>18.23333</td>
105
- <td>2.01136</td>
106
- <td>0.20229</td>
107
- </tr>
108
- <tr>
109
- <td>ListMutator(:single_point,[:replace, "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", " "])</td>
110
- <td>13.00000</td>
111
- <td>22.00000</td>
112
- <td>17.38333</td>
113
- <td>2.39508</td>
114
- <td>0.18940</td>
115
- </tr>
116
- </table><h1>Raw Stats</h1><table>
117
- <tr><th>selection</th><th>crossover</th><th>mutation</th><th>min</th><th>max</th><th>avg</th><th>stddev</th><th>avg-time</th></tr>
118
- <tr>
119
- <td>TruncationSelection(1)</td>
120
- <td>UniformCrossover</td>
121
- <td>ListMutator([:n_point, 2],[:replace, "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", " "])</td>
122
- <td>18.00000</td>
123
- <td>22.00000</td>
124
- <td>19.50000</td>
125
- <td>1.02470</td>
126
- <td>0.22375</td>
127
- </tr>
128
- <tr>
129
- <td>TruncationSelection(0.2)</td>
130
- <td>UniformCrossover</td>
131
- <td>ListMutator([:n_point, 2],[:replace, "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", " "])</td>
132
- <td>17.00000</td>
133
- <td>22.00000</td>
134
- <td>19.50000</td>
135
- <td>1.50000</td>
136
- <td>0.22246</td>
137
- </tr>
138
- <tr>
139
- <td>TruncationSelection(1)</td>
140
- <td>SinglePointCrossover</td>
141
- <td>ListMutator([:n_point, 2],[:replace, "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", " "])</td>
142
- <td>16.00000</td>
143
- <td>22.00000</td>
144
- <td>18.80000</td>
145
- <td>2.03961</td>
146
- <td>0.19627</td>
147
- </tr>
148
- <tr>
149
- <td>TruncationSelection(0.2)</td>
150
- <td>UniformCrossover</td>
151
- <td>ListMutator(:single_point,[:replace, "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", " "])</td>
152
- <td>14.00000</td>
153
- <td>22.00000</td>
154
- <td>18.50000</td>
155
- <td>2.37697</td>
156
- <td>0.21168</td>
157
- </tr>
158
- <tr>
159
- <td>TruncationSelection(1)</td>
160
- <td>UniformCrossover</td>
161
- <td>ListMutator(:single_point,[:replace, "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", " "])</td>
162
- <td>16.00000</td>
163
- <td>22.00000</td>
164
- <td>18.50000</td>
165
- <td>2.45967</td>
166
- <td>0.21192</td>
167
- </tr>
168
- <tr>
169
- <td>TruncationSelection(0.2)</td>
170
- <td>SinglePointCrossover</td>
171
- <td>ListMutator([:n_point, 2],[:replace, "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", " "])</td>
172
- <td>16.00000</td>
173
- <td>21.00000</td>
174
- <td>18.20000</td>
175
- <td>1.53623</td>
176
- <td>0.19442</td>
177
- </tr>
178
- <tr>
179
- <td>TruncationSelection(0.2)</td>
180
- <td>SinglePointCrossover</td>
181
- <td>ListMutator(:single_point,[:replace, "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", " "])</td>
182
- <td>14.00000</td>
183
- <td>21.00000</td>
184
- <td>18.10000</td>
185
- <td>2.21133</td>
186
- <td>0.18162</td>
187
- </tr>
188
- <tr>
189
- <td>TruncationSelection(1)</td>
190
- <td>SinglePointCrossover</td>
191
- <td>ListMutator(:single_point,[:replace, "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", " "])</td>
192
- <td>15.00000</td>
193
- <td>20.00000</td>
194
- <td>17.70000</td>
195
- <td>1.55242</td>
196
- <td>0.18088</td>
197
- </tr>
198
- <tr>
199
- <td>TruncationSelection(1)</td>
200
- <td>NullCrossover</td>
201
- <td>ListMutator([:n_point, 2],[:replace, "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", " "])</td>
202
- <td>14.00000</td>
203
- <td>20.00000</td>
204
- <td>16.80000</td>
205
- <td>1.83303</td>
206
- <td>0.18853</td>
207
- </tr>
208
- <tr>
209
- <td>TruncationSelection(0.2)</td>
210
- <td>NullCrossover</td>
211
- <td>ListMutator([:n_point, 2],[:replace, "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", " "])</td>
212
- <td>13.00000</td>
213
- <td>20.00000</td>
214
- <td>16.60000</td>
215
- <td>1.68523</td>
216
- <td>0.18833</td>
217
- </tr>
218
- <tr>
219
- <td>TruncationSelection(0.2)</td>
220
- <td>NullCrossover</td>
221
- <td>ListMutator(:single_point,[:replace, "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", " "])</td>
222
- <td>14.00000</td>
223
- <td>19.00000</td>
224
- <td>16.30000</td>
225
- <td>1.73494</td>
226
- <td>0.17482</td>
227
- </tr>
228
- <tr>
229
- <td>TruncationSelection(1)</td>
230
- <td>NullCrossover</td>
231
- <td>ListMutator(:single_point,[:replace, "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", " "])</td>
232
- <td>13.00000</td>
233
- <td>18.00000</td>
234
- <td>15.20000</td>
235
- <td>1.83303</td>
236
- <td>0.17549</td>
237
- </tr>
238
- </table>
239
- </body>
240
- </html>
@@ -1,26 +0,0 @@
1
- require '../lib/charlie'
2
-
3
- class RoyalRoad < BitStringGenotype(64) # Royal Road problem
4
- def fitness
5
- 1e-6 + genes.enum_slice(8).find_all{|e| e.all?{|x|x==1} }.size
6
- end
7
- #use TruncationSelection()
8
- use RouletteSelection
9
- end
10
-
11
- Population.new(RoyalRoad).evolve_on_console(1000)
12
-
13
- Population.benchmark(RoyalRoad,'output/royalroad1_report.html'){
14
- selection TruncationSelection(), Elitism(ScaledRouletteSelection(),1), Elitism(RouletteSelection,1), BestOnlySelection, ScaledRouletteSelection()
15
- crossover NullCrossover, SinglePointCrossover, UniformCrossover
16
- mutator ListMutator(:single_point,:flip), ListMutator(:n_point[2],:flip),ListMutator(:n_point[3],:flip),
17
- ListMutator(:expected_n[1],:flip), ListMutator(:expected_n[2],:flip), ListMutator(:expected_n[3],:flip)
18
-
19
- }
20
-
21
- Population.benchmark(RoyalRoad,'output/royalroad2_report.html'){
22
- selection TruncationSelection(0.2), TruncationSelection(0.3), TruncationSelection(0.4), Elitism(ScaledRouletteSelection(),1), Elitism(RouletteSelection,1)
23
- crossover NullCrossover, SinglePointCrossover, UniformCrossover
24
- mutator *( (2..4).map{|n| [ListMutator(:n_point[n],:flip), ListMutator(:expected_n[n],:flip)] }.flatten)
25
- }
26
-
@@ -1,18 +0,0 @@
1
- require '../lib/charlie'
2
-
3
- class RoyalRoad < BitStringGenotype(64) # Royal Road problem
4
- def fitness
5
- genes.enum_slice(8).find_all{|e| e.all?{|x|x==1} }.size
6
- end
7
-
8
- #use TruncationSelection(0.1)
9
- #use PCross(0.75,SingleChild(UniformCrossover))
10
- end
11
-
12
- Population.benchmark(RoyalRoad,'output/royalroadquick_report.html'){
13
- selection TruncationSelection(), Elitism(ScaledRouletteSelection(),1), TournamentSelection(4)
14
-
15
- crossover SinglePointCrossover, UniformCrossover, PCross(0.75,UniformCrossover), SingleChild(UniformCrossover)
16
- mutator ListMutator(:expected_n[1],:flip), ListMutator(:expected_n[2],:flip), ListMutator(:expected_n[3],:flip)
17
- self.repeat = 50
18
- }
@@ -1,47 +0,0 @@
1
- require '../lib/charlie'
2
-
3
- class Hill2 < FloatListGenotype(2,(-1..1)) # simple hill function
4
-
5
- def fitness
6
- x,y=genes
7
- 1 / (1+x*x+y*y)
8
- end
9
- #use BestOnlySelection
10
- use TournamentSelection(4)
11
- use NullCrossover
12
- end
13
-
14
- Population.new(Hill2,10).evolve_on_console(20)
15
-
16
-
17
- class Hill10 < FloatListGenotype(10,(-1..1)) # 10-dimensional simple hill function
18
- def fitness
19
- 1 / (1 + genes.inject(0){|s,x|s+x*x})
20
- end
21
- #use BestOnlySelection
22
- #use TournamentSelection(4)
23
- #use NullCrossover
24
- end
25
-
26
- Population.benchmark(Hill2,'output/hill2.html','output/hill2.csv') {
27
- selection BestOnlySelection, TournamentSelection(4)
28
- crossover NullCrossover,SinglePointCrossover
29
-
30
- mt = [:expected_n[1],:expected_n[2]].map{|s|
31
- [:uniform[0.1],:uniform[0.2],:gaussian[0.3]].map{|p| ListMutator(s,p) } }.flatten
32
- mutator *mt
33
- self.generations = 20
34
- self.population_size = 10
35
- }
36
-
37
- Population.benchmark(Hill10,'output/hill10.html') {
38
- selection BestOnlySelection, TournamentSelection(4), TournamentSelection(3), RouletteSelection, Elitism(RouletteSelection,1)
39
- crossover NullCrossover,SinglePointCrossover,UniformCrossover
40
-
41
- mt = [:expected_n[1],:expected_n[2],:expected_n[3],:single_point,:n_point[2],:n_point[3]].map{|s|
42
- [:uniform[0.1],:uniform[0.2],:uniform[0.3],:gaussian[0.1],:gaussian[0.2],:gaussian[0.3]].map{|p| ListMutator(s,p) } }.flatten
43
-
44
- mutator *mt
45
- self.generations = 20
46
- self.population_size = 10
47
- }
@@ -1,36 +0,0 @@
1
- require '../lib/charlie'
2
-
3
- STR = 'methinks it is like a weasel'
4
- Schars = ('a'..'z').to_a << ' '
5
-
6
- class Weasel < StringGenotype(STR.size,Schars)
7
- def fitness
8
- genes.zip(STR.chars).find_all{|a,b|a==b}.size
9
- end
10
-
11
- def to_s
12
- genes.join.inspect
13
- end
14
- use BestOnlySelection
15
- use UniformCrossover
16
- use ListMutator(:single_point,:replace[*Schars])
17
- end
18
-
19
- Population.new(Weasel).evolve_on_console(200)
20
-
21
- Population.benchmark(Weasel,'output/weasel1_report.html'){
22
- selection TruncationSelection(), Elitism(ScaledRouletteSelection(),1), Elitism(RouletteSelection,1), BestOnlySelection, ScaledRouletteSelection()
23
- crossover NullCrossover, SinglePointCrossover, UniformCrossover
24
- mutator ListMutator(:single_point,:replace[*Schars]), ListMutator(:n_point[2],:replace[*Schars]),ListMutator(:n_point[3],:replace[*Schars]),
25
- ListMutator(:expected_n[1],:replace[*Schars]), ListMutator(:expected_n[2],:replace[*Schars]), ListMutator(:expected_n[3],:replace[*Schars])
26
-
27
- }
28
-
29
-
30
- Population.benchmark(Weasel,'output/weasel2_report.html'){
31
- selection TruncationSelection(0.2), BestOnlySelection
32
- crossover NullCrossover, SinglePointCrossover, UniformCrossover
33
- mutator ListMutator(:single_point,:replace[*Schars]), ListMutator(:n_point[2],:replace[*Schars])
34
- }
35
-
36
-