evolvable 1.2.0 → 2.0.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 (79) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +2 -0
  3. data/CHANGELOG.md +24 -0
  4. data/Gemfile +2 -2
  5. data/Gemfile.lock +44 -25
  6. data/README.md +498 -190
  7. data/README_YARD.md +85 -166
  8. data/bin/console +10 -19
  9. data/docs/Evolvable/ClassMethods.html +1233 -0
  10. data/docs/Evolvable/Community/ClassMethods.html +708 -0
  11. data/docs/Evolvable/Community.html +1342 -0
  12. data/docs/Evolvable/CountGene.html +886 -0
  13. data/docs/Evolvable/EqualizeGoal.html +347 -0
  14. data/docs/Evolvable/Error.html +134 -0
  15. data/docs/Evolvable/Evaluation.html +773 -0
  16. data/docs/Evolvable/Evolution.html +616 -0
  17. data/docs/Evolvable/Gene/ClassMethods.html +413 -0
  18. data/docs/Evolvable/Gene.html +522 -0
  19. data/docs/Evolvable/GeneCluster/ClassMethods.html +431 -0
  20. data/docs/Evolvable/GeneCluster.html +280 -0
  21. data/docs/Evolvable/GeneCombination.html +515 -0
  22. data/docs/Evolvable/GeneSpace.html +619 -0
  23. data/docs/Evolvable/Genome.html +1070 -0
  24. data/docs/Evolvable/Goal.html +500 -0
  25. data/docs/Evolvable/MaximizeGoal.html +348 -0
  26. data/docs/Evolvable/MinimizeGoal.html +348 -0
  27. data/docs/Evolvable/Mutation.html +729 -0
  28. data/docs/Evolvable/PointCrossover.html +444 -0
  29. data/docs/Evolvable/Population.html +2826 -0
  30. data/docs/Evolvable/RigidCountGene.html +501 -0
  31. data/docs/Evolvable/Selection.html +594 -0
  32. data/docs/Evolvable/Serializer.html +293 -0
  33. data/docs/Evolvable/UniformCrossover.html +286 -0
  34. data/docs/Evolvable.html +1619 -0
  35. data/docs/_index.html +341 -0
  36. data/docs/class_list.html +54 -0
  37. data/docs/css/common.css +1 -0
  38. data/docs/css/full_list.css +58 -0
  39. data/docs/css/style.css +503 -0
  40. data/docs/file.README.html +750 -0
  41. data/docs/file_list.html +59 -0
  42. data/docs/frames.html +22 -0
  43. data/docs/index.html +750 -0
  44. data/docs/js/app.js +344 -0
  45. data/docs/js/full_list.js +242 -0
  46. data/docs/js/jquery.js +4 -0
  47. data/docs/method_list.html +1302 -0
  48. data/docs/top-level-namespace.html +110 -0
  49. data/evolvable.gemspec +6 -6
  50. data/examples/ascii_art.rb +5 -9
  51. data/examples/stickman.rb +25 -33
  52. data/{examples/hello_world.rb → exe/hello_evolvable_world} +46 -30
  53. data/lib/evolvable/community.rb +190 -0
  54. data/lib/evolvable/count_gene.rb +65 -0
  55. data/lib/evolvable/equalize_goal.rb +2 -9
  56. data/lib/evolvable/evaluation.rb +113 -14
  57. data/lib/evolvable/evolution.rb +38 -15
  58. data/lib/evolvable/gene.rb +124 -25
  59. data/lib/evolvable/gene_cluster.rb +106 -0
  60. data/lib/evolvable/gene_combination.rb +57 -16
  61. data/lib/evolvable/gene_space.rb +111 -0
  62. data/lib/evolvable/genome.rb +32 -4
  63. data/lib/evolvable/goal.rb +19 -24
  64. data/lib/evolvable/maximize_goal.rb +2 -9
  65. data/lib/evolvable/minimize_goal.rb +3 -9
  66. data/lib/evolvable/mutation.rb +87 -41
  67. data/lib/evolvable/point_crossover.rb +24 -4
  68. data/lib/evolvable/population.rb +258 -84
  69. data/lib/evolvable/rigid_count_gene.rb +36 -0
  70. data/lib/evolvable/selection.rb +68 -14
  71. data/lib/evolvable/serializer.rb +46 -0
  72. data/lib/evolvable/uniform_crossover.rb +30 -6
  73. data/lib/evolvable/version.rb +2 -1
  74. data/lib/evolvable.rb +268 -107
  75. metadata +57 -36
  76. data/examples/images/diagram.png +0 -0
  77. data/exe/hello +0 -16
  78. data/lib/evolvable/error/undefined_method.rb +0 -7
  79. data/lib/evolvable/search_space.rb +0 -181
@@ -0,0 +1,444 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>
7
+ Class: Evolvable::PointCrossover
8
+
9
+ &mdash; Documentation by YARD 0.9.37
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="../css/style.css" type="text/css" />
14
+
15
+ <link rel="stylesheet" href="../css/common.css" type="text/css" />
16
+
17
+ <script type="text/javascript">
18
+ pathId = "Evolvable::PointCrossover";
19
+ relpath = '../';
20
+ </script>
21
+
22
+
23
+ <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
24
+
25
+ <script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
26
+
27
+
28
+ </head>
29
+ <body>
30
+ <div class="nav_wrap">
31
+ <iframe id="nav" src="../class_list.html?1"></iframe>
32
+ <div id="resizer"></div>
33
+ </div>
34
+
35
+ <div id="main" tabindex="-1">
36
+ <div id="header">
37
+ <div id="menu">
38
+
39
+ <a href="../_index.html">Index (P)</a> &raquo;
40
+ <span class='title'><span class='object_link'><a href="../Evolvable.html" title="Evolvable (module)">Evolvable</a></span></span>
41
+ &raquo;
42
+ <span class="title">PointCrossover</span>
43
+
44
+ </div>
45
+
46
+ <div id="search">
47
+
48
+ <a class="full_list_link" id="class_list_link"
49
+ href="../class_list.html">
50
+
51
+ <svg width="24" height="24">
52
+ <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
53
+ <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
54
+ <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
55
+ </svg>
56
+ </a>
57
+
58
+ </div>
59
+ <div class="clear"></div>
60
+ </div>
61
+
62
+ <div id="content"><h1>Class: Evolvable::PointCrossover
63
+
64
+
65
+
66
+ </h1>
67
+ <div class="box_info">
68
+
69
+ <dl>
70
+ <dt>Inherits:</dt>
71
+ <dd>
72
+ <span class="inheritName">Object</span>
73
+
74
+ <ul class="fullTree">
75
+ <li>Object</li>
76
+
77
+ <li class="next">Evolvable::PointCrossover</li>
78
+
79
+ </ul>
80
+ <a href="#" class="inheritanceTree">show all</a>
81
+
82
+ </dd>
83
+ </dl>
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+ <dl>
96
+ <dt>Defined in:</dt>
97
+ <dd>lib/evolvable/point_crossover.rb</dd>
98
+ </dl>
99
+
100
+ </div>
101
+
102
+ <h2>Overview</h2><div class="docstring">
103
+ <div class="discussion">
104
+ <p>A classic genetic algorithm strategy that performs single or multi-point crossover
105
+ by selecting random positions in the genome and swapping gene segments between parents.</p>
106
+
107
+ <ul>
108
+ <li><strong>Single-point crossover (default):</strong> Swaps all genes after a randomly chosen position.</li>
109
+ <li><strong>Multi-point crossover:</strong> Alternates segments between multiple randomly chosen points.</li>
110
+ </ul>
111
+
112
+ <p>Best for:</p>
113
+
114
+ <ul>
115
+ <li>Preserving beneficial gene blocks</li>
116
+ <li>Problems where related traits are located near each other</li>
117
+ </ul>
118
+
119
+ <p>Set your population to use this strategy during initialization with:</p>
120
+
121
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_population'>population</span> <span class='op'>=</span> <span class='const'>MyEvolvable</span><span class='period'>.</span><span class='id identifier rubyid_new_population'>new_population</span><span class='lparen'>(</span>
122
+ <span class='label'>combination:</span> <span class='const'><span class='object_link'><a href="../Evolvable.html" title="Evolvable (module)">Evolvable</a></span></span><span class='op'>::</span><span class='const'>PointCrossover</span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="#initialize-instance_method" title="Evolvable::PointCrossover#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='label'>points_count:</span> <span class='int'>2</span><span class='rparen'>)</span>
123
+ <span class='rparen'>)</span>
124
+ </code></pre>
125
+
126
+ <p>Or update an existing population:</p>
127
+
128
+ <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_population'>population</span><span class='period'>.</span><span class='id identifier rubyid_combination'>combination</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="../Evolvable.html" title="Evolvable (module)">Evolvable</a></span></span><span class='op'>::</span><span class='const'>PointCrossover</span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="#initialize-instance_method" title="Evolvable::PointCrossover#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='label'>points_count:</span> <span class='int'>3</span><span class='rparen'>)</span>
129
+ </code></pre>
130
+
131
+
132
+ </div>
133
+ </div>
134
+ <div class="tags">
135
+
136
+
137
+ </div>
138
+
139
+
140
+
141
+ <h2>Instance Attribute Summary <small><a href="#" class="summary_toggle">collapse</a></small></h2>
142
+ <ul class="summary">
143
+
144
+ <li class="public ">
145
+ <span class="summary_signature">
146
+
147
+ <a href="#points_count-instance_method" title="#points_count (instance method)">#<strong>points_count</strong> &#x21d2; Object </a>
148
+
149
+
150
+
151
+ </span>
152
+
153
+
154
+
155
+
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+
164
+ <span class="summary_desc"><div class='inline'><p>Returns the value of attribute points_count.</p>
165
+ </div></span>
166
+
167
+ </li>
168
+
169
+
170
+ </ul>
171
+
172
+
173
+
174
+
175
+
176
+ <h2>
177
+ Instance Method Summary
178
+ <small><a href="#" class="summary_toggle">collapse</a></small>
179
+ </h2>
180
+
181
+ <ul class="summary">
182
+
183
+ <li class="public ">
184
+ <span class="summary_signature">
185
+
186
+ <a href="#call-instance_method" title="#call (instance method)">#<strong>call</strong>(population) &#x21d2; Object </a>
187
+
188
+
189
+
190
+ </span>
191
+
192
+
193
+
194
+
195
+
196
+
197
+
198
+
199
+
200
+ <span class="summary_desc"><div class='inline'></div></span>
201
+
202
+ </li>
203
+
204
+
205
+ <li class="public ">
206
+ <span class="summary_signature">
207
+
208
+ <a href="#initialize-instance_method" title="#initialize (instance method)">#<strong>initialize</strong>(points_count: 1) &#x21d2; PointCrossover </a>
209
+
210
+
211
+
212
+ </span>
213
+
214
+
215
+ <span class="note title constructor">constructor</span>
216
+
217
+
218
+
219
+
220
+
221
+
222
+
223
+
224
+ <span class="summary_desc"><div class='inline'><p>A new instance of PointCrossover.</p>
225
+ </div></span>
226
+
227
+ </li>
228
+
229
+
230
+ <li class="public ">
231
+ <span class="summary_signature">
232
+
233
+ <a href="#new_evolvables-instance_method" title="#new_evolvables (instance method)">#<strong>new_evolvables</strong>(population, count) &#x21d2; Object </a>
234
+
235
+
236
+
237
+ </span>
238
+
239
+
240
+
241
+
242
+
243
+
244
+
245
+
246
+
247
+ <span class="summary_desc"><div class='inline'></div></span>
248
+
249
+ </li>
250
+
251
+
252
+ </ul>
253
+
254
+
255
+ <div id="constructor_details" class="method_details_list">
256
+ <h2>Constructor Details</h2>
257
+
258
+ <div class="method_details first">
259
+ <h3 class="signature first" id="initialize-instance_method">
260
+
261
+ #<strong>initialize</strong>(points_count: 1) &#x21d2; <tt><span class='object_link'><a href="" title="Evolvable::PointCrossover (class)">PointCrossover</a></span></tt>
262
+
263
+
264
+
265
+
266
+
267
+ </h3><div class="docstring">
268
+ <div class="discussion">
269
+ <p>Returns a new instance of PointCrossover.</p>
270
+
271
+
272
+ </div>
273
+ </div>
274
+ <div class="tags">
275
+
276
+
277
+ </div><table class="source_code">
278
+ <tr>
279
+ <td>
280
+ <pre class="lines">
281
+
282
+
283
+ 31
284
+ 32
285
+ 33</pre>
286
+ </td>
287
+ <td>
288
+ <pre class="code"><span class="info file"># File 'lib/evolvable/point_crossover.rb', line 31</span>
289
+
290
+ <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='label'>points_count:</span> <span class='int'>1</span><span class='rparen'>)</span>
291
+ <span class='ivar'>@points_count</span> <span class='op'>=</span> <span class='id identifier rubyid_points_count'>points_count</span>
292
+ <span class='kw'>end</span></pre>
293
+ </td>
294
+ </tr>
295
+ </table>
296
+ </div>
297
+
298
+ </div>
299
+
300
+ <div id="instance_attr_details" class="attr_details">
301
+ <h2>Instance Attribute Details</h2>
302
+
303
+
304
+ <span id="points_count=-instance_method"></span>
305
+ <div class="method_details first">
306
+ <h3 class="signature first" id="points_count-instance_method">
307
+
308
+ #<strong>points_count</strong> &#x21d2; <tt>Object</tt>
309
+
310
+
311
+
312
+
313
+
314
+ </h3><div class="docstring">
315
+ <div class="discussion">
316
+ <p>Returns the value of attribute points_count.</p>
317
+
318
+
319
+ </div>
320
+ </div>
321
+ <div class="tags">
322
+
323
+
324
+ </div><table class="source_code">
325
+ <tr>
326
+ <td>
327
+ <pre class="lines">
328
+
329
+
330
+ 35
331
+ 36
332
+ 37</pre>
333
+ </td>
334
+ <td>
335
+ <pre class="code"><span class="info file"># File 'lib/evolvable/point_crossover.rb', line 35</span>
336
+
337
+ <span class='kw'>def</span> <span class='id identifier rubyid_points_count'>points_count</span>
338
+ <span class='ivar'>@points_count</span>
339
+ <span class='kw'>end</span></pre>
340
+ </td>
341
+ </tr>
342
+ </table>
343
+ </div>
344
+
345
+ </div>
346
+
347
+
348
+ <div id="instance_method_details" class="method_details_list">
349
+ <h2>Instance Method Details</h2>
350
+
351
+
352
+ <div class="method_details first">
353
+ <h3 class="signature first" id="call-instance_method">
354
+
355
+ #<strong>call</strong>(population) &#x21d2; <tt>Object</tt>
356
+
357
+
358
+
359
+
360
+
361
+ </h3><table class="source_code">
362
+ <tr>
363
+ <td>
364
+ <pre class="lines">
365
+
366
+
367
+ 37
368
+ 38
369
+ 39
370
+ 40</pre>
371
+ </td>
372
+ <td>
373
+ <pre class="code"><span class="info file"># File 'lib/evolvable/point_crossover.rb', line 37</span>
374
+
375
+ <span class='kw'>def</span> <span class='id identifier rubyid_call'>call</span><span class='lparen'>(</span><span class='id identifier rubyid_population'>population</span><span class='rparen'>)</span>
376
+ <span class='id identifier rubyid_population'>population</span><span class='period'>.</span><span class='id identifier rubyid_evolvables'>evolvables</span> <span class='op'>=</span> <span class='id identifier rubyid_new_evolvables'>new_evolvables</span><span class='lparen'>(</span><span class='id identifier rubyid_population'>population</span><span class='comma'>,</span> <span class='id identifier rubyid_population'>population</span><span class='period'>.</span><span class='id identifier rubyid_size'>size</span><span class='rparen'>)</span>
377
+ <span class='id identifier rubyid_population'>population</span>
378
+ <span class='kw'>end</span></pre>
379
+ </td>
380
+ </tr>
381
+ </table>
382
+ </div>
383
+
384
+ <div class="method_details ">
385
+ <h3 class="signature " id="new_evolvables-instance_method">
386
+
387
+ #<strong>new_evolvables</strong>(population, count) &#x21d2; <tt>Object</tt>
388
+
389
+
390
+
391
+
392
+
393
+ </h3><table class="source_code">
394
+ <tr>
395
+ <td>
396
+ <pre class="lines">
397
+
398
+
399
+ 42
400
+ 43
401
+ 44
402
+ 45
403
+ 46
404
+ 47
405
+ 48
406
+ 49
407
+ 50
408
+ 51
409
+ 52
410
+ 53</pre>
411
+ </td>
412
+ <td>
413
+ <pre class="code"><span class="info file"># File 'lib/evolvable/point_crossover.rb', line 42</span>
414
+
415
+ <span class='kw'>def</span> <span class='id identifier rubyid_new_evolvables'>new_evolvables</span><span class='lparen'>(</span><span class='id identifier rubyid_population'>population</span><span class='comma'>,</span> <span class='id identifier rubyid_count'>count</span><span class='rparen'>)</span>
416
+ <span class='id identifier rubyid_parent_genome_cycle'>parent_genome_cycle</span> <span class='op'>=</span> <span class='id identifier rubyid_population'>population</span><span class='period'>.</span><span class='id identifier rubyid_new_parent_genome_cycle'>new_parent_genome_cycle</span>
417
+ <span class='id identifier rubyid_evolvables'>evolvables</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
418
+ <span class='id identifier rubyid_loop'>loop</span> <span class='kw'>do</span>
419
+ <span class='id identifier rubyid_genome_1'>genome_1</span><span class='comma'>,</span> <span class='id identifier rubyid_genome_2'>genome_2</span> <span class='op'>=</span> <span class='id identifier rubyid_parent_genome_cycle'>parent_genome_cycle</span><span class='period'>.</span><span class='id identifier rubyid_next'>next</span>
420
+ <span class='id identifier rubyid_crossover_genomes'>crossover_genomes</span><span class='lparen'>(</span><span class='id identifier rubyid_genome_1'>genome_1</span><span class='comma'>,</span> <span class='id identifier rubyid_genome_2'>genome_2</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_genome'>genome</span><span class='op'>|</span>
421
+ <span class='id identifier rubyid_evolvable'>evolvable</span> <span class='op'>=</span> <span class='id identifier rubyid_population'>population</span><span class='period'>.</span><span class='id identifier rubyid_new_evolvable'>new_evolvable</span><span class='lparen'>(</span><span class='label'>genome:</span> <span class='id identifier rubyid_genome'>genome</span><span class='rparen'>)</span>
422
+ <span class='id identifier rubyid_evolvables'>evolvables</span> <span class='op'>&lt;&lt;</span> <span class='id identifier rubyid_evolvable'>evolvable</span>
423
+ <span class='kw'>return</span> <span class='id identifier rubyid_evolvables'>evolvables</span> <span class='kw'>if</span> <span class='id identifier rubyid_evolvable'>evolvable</span><span class='period'>.</span><span class='id identifier rubyid_generation_index'>generation_index</span> <span class='op'>==</span> <span class='id identifier rubyid_count'>count</span>
424
+ <span class='kw'>end</span>
425
+ <span class='kw'>end</span>
426
+ <span class='kw'>end</span></pre>
427
+ </td>
428
+ </tr>
429
+ </table>
430
+ </div>
431
+
432
+ </div>
433
+
434
+ </div>
435
+
436
+ <div id="footer">
437
+ Generated on Sat May 10 18:39:22 2025 by
438
+ <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
439
+ 0.9.37 (ruby-3.4.2).
440
+ </div>
441
+
442
+ </div>
443
+ </body>
444
+ </html>