|
14 | 14 |
|
15 | 15 | <link rel="stylesheet" href="css/common.css" type="text/css" />
|
16 | 16 |
|
| 17 | + <link rel="stylesheet" href="css/custom.css" type="text/css" /> |
| 18 | + |
17 | 19 | <script type="text/javascript">
|
18 | 20 | pathId = "Evolvable";
|
19 | 21 | relpath = '';
|
|
92 | 94 |
|
93 | 95 | <h2>Overview</h2><div class="docstring">
|
94 | 96 | <div class="discussion">
|
95 |
| - <p>The evolutionary process works through these components: |
96 |
| - 1. <strong>Populations</strong>: Groups of the “evolvable” instances you define |
97 |
| - 2. <strong>Genes</strong>: Ruby objects that cache data for evolvables |
98 |
| - 3. <strong>Evaluation</strong>: Sorts evolvables by fitness |
99 |
| - 4. <strong>Evolution</strong>: Selection, combination, and mutation to generate new evolvables</p> |
100 |
| - |
101 |
| -<p>Quick start: |
102 |
| - 1. Include <code>Evolvable</code> in your Ruby class |
103 |
| - 2. Define genes with the macro-style <code>gene</code> method |
104 |
| - 3. Have the <code>#fitness</code> method return a numeric value |
105 |
| - 4. Initialize a population and evolve it</p> |
106 |
| - |
107 |
| -<p>Example population of “shirts” with various colors, buttons, and collars.</p> |
108 |
| - |
109 |
| -<p>```ruby |
110 |
| - # Step 1 |
111 |
| - class Shirt |
112 |
| - include Evolvable</p> |
113 |
| - |
114 |
| -<pre class="code ruby"><code class="ruby"># Step 2 |
115 |
| -gene :color, type: ColorGene # count: 1 default |
116 |
| -gene :buttons, type: ButtonGene, count: 0..10 # Builds an array of genes that can vary in size |
117 |
| -gene :collar, type: CollarGene, count: 0..1 # Collar optional |
118 |
| - |
119 |
| -# Step 3 |
120 |
| -attr_accessor :fitness end |
| 97 | + <p>The evolutionary process works through these components:</p> |
| 98 | + |
| 99 | +<ol> |
| 100 | +<li><strong>Populations</strong>: Groups of the "evolvable" instances you define</li> |
| 101 | +<li><strong>Genes</strong>: Ruby objects that cache data for evolvables</li> |
| 102 | +<li><strong>Evaluation</strong>: Sorts evolvables by fitness</li> |
| 103 | +<li><strong>Evolution</strong>: Selection, combination, and mutation to generate new evolvables</li> |
| 104 | +</ol> |
| 105 | + |
| 106 | +<p>Quick start:</p> |
| 107 | + |
| 108 | +<ol> |
| 109 | +<li>Include <code>Evolvable</code> in your Ruby class</li> |
| 110 | +<li>Define genes with the macro-style <code>gene</code> method</li> |
| 111 | +<li>Have the <code>#fitness</code> method return a numeric value</li> |
| 112 | +<li>Initialize a population and evolve it</li> |
| 113 | +</ol> |
| 114 | + |
| 115 | +<p>Example population of "shirts" with various colors, buttons, and collars.</p> |
| 116 | + |
| 117 | +<pre class="code ruby"><code class="ruby"> <span class='comment'># Step 1 |
| 118 | +</span> <span class='kw'>class</span> <span class='const'>Shirt</span> |
| 119 | + <span class='id identifier rubyid_include'>include</span> <span class='const'>Evolvable</span> |
| 120 | + |
| 121 | + <span class='comment'># Step 2 |
| 122 | +</span> <span class='id identifier rubyid_gene'>gene</span> <span class='symbol'>:color</span><span class='comma'>,</span> <span class='label'>type:</span> <span class='const'>ColorGene</span> <span class='comment'># count: 1 default |
| 123 | +</span> <span class='id identifier rubyid_gene'>gene</span> <span class='symbol'>:buttons</span><span class='comma'>,</span> <span class='label'>type:</span> <span class='const'>ButtonGene</span><span class='comma'>,</span> <span class='label'>count:</span> <span class='int'>0</span><span class='op'>..</span><span class='int'>10</span> <span class='comment'># Builds an array of genes that can vary in size |
| 124 | +</span> <span class='id identifier rubyid_gene'>gene</span> <span class='symbol'>:collar</span><span class='comma'>,</span> <span class='label'>type:</span> <span class='const'>CollarGene</span><span class='comma'>,</span> <span class='label'>count:</span> <span class='int'>0</span><span class='op'>..</span><span class='int'>1</span> <span class='comment'># Collar optional |
| 125 | +</span> |
| 126 | + <span class='comment'># Step 3 |
| 127 | +</span> <span class='id identifier rubyid_attr_accessor'>attr_accessor</span> <span class='symbol'>:fitness</span> |
| 128 | + <span class='kw'>end</span> |
| 129 | + |
| 130 | + <span class='comment'># Step 4 |
| 131 | +</span> <span class='id identifier rubyid_population'>population</span> <span class='op'>=</span> <span class='const'>Shirt</span><span class='period'>.</span><span class='id identifier rubyid_new_population'>new_population</span><span class='lparen'>(</span><span class='label'>size:</span> <span class='int'>10</span><span class='rparen'>)</span> |
| 132 | + <span class='id identifier rubyid_population'>population</span><span class='period'>.</span><span class='id identifier rubyid_evolvables'>evolvables</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_shirt'>shirt</span><span class='op'>|</span> <span class='id identifier rubyid_shirt'>shirt</span><span class='period'>.</span><span class='id identifier rubyid_fitness'>fitness</span> <span class='op'>=</span> <span class='id identifier rubyid_tried_it_on_score'>tried_it_on_score</span> <span class='rbrace'>}</span> |
121 | 133 | </code></pre>
|
122 | 134 |
|
123 |
| -<p># Step 4 |
124 |
| - population = Shirt.new_population(size: 10) |
125 |
| - population.evolvables.each { |shirt| shirt.fitness = tried_it_on_score } |
126 |
| - ```</p> |
127 |
| - |
128 |
| -<p>You are free to tailor the genes to your needs and “try it on” yourself.</p> |
| 135 | +<p>You are free to tailor the genes to your needs and "try it on" yourself.</p> |
129 | 136 |
|
130 | 137 | <p>The <code>ColorGene</code> could be as simple as this:</p>
|
131 | 138 |
|
132 |
| -<p>```ruby |
133 |
| - class ColorGene |
134 |
| - include Evolvable::Gene</p> |
| 139 | +<pre class="code ruby"><code class="ruby"> <span class='kw'>class</span> <span class='const'>ColorGene</span> |
| 140 | + <span class='id identifier rubyid_include'>include</span> <span class='const'>Evolvable</span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Evolvable/Gene.html" title="Evolvable::Gene (module)">Gene</a></span></span> |
135 | 141 |
|
136 |
| -<pre class="code ruby"><code class="ruby">def to_s |
137 |
| - @to_s ||= %w[red green blue].sample |
138 |
| -end end ``` |
| 142 | + <span class='kw'>def</span> <span class='id identifier rubyid_to_s'>to_s</span> |
| 143 | + <span class='ivar'>@to_s</span> <span class='op'>||=</span> <span class='qwords_beg'>%w[</span><span class='tstring_content'>red</span><span class='words_sep'> </span><span class='tstring_content'>green</span><span class='words_sep'> </span><span class='tstring_content'>blue</span><span class='tstring_end'>]</span></span><span class='period'>.</span><span class='id identifier rubyid_sample'>sample</span> |
| 144 | + <span class='kw'>end</span> |
| 145 | + <span class='kw'>end</span> |
139 | 146 | </code></pre>
|
140 | 147 |
|
141 | 148 | <p>Not into shirts?</p>
|
142 | 149 |
|
143 |
| -<p>Here’s a <a href="https://github.com/mattruzicka/evolvable/blob/main/exe/hello_evolvable_world">Hello World</a> command line demo.</p> |
| 150 | +<p>Here's a <a href="https://github.com/mattruzicka/evolvable/blob/main/exe/hello_evolvable_world">Hello World</a> command line demo.</p> |
144 | 151 |
|
145 | 152 |
|
146 | 153 | </div>
|
|
348 | 355 |
|
349 | 356 |
|
350 | 357 |
|
351 |
| - <span class="summary_desc"><div class='inline'> |
352 |
| -</div></span> |
| 358 | + <span class="summary_desc"><div class='inline'></div></span> |
353 | 359 |
|
354 | 360 | </li>
|
355 | 361 |
|
|
394 | 400 |
|
395 | 401 |
|
396 | 402 |
|
397 |
| - <span class="summary_desc"><div class='inline'> |
398 |
| -</div></span> |
| 403 | + <span class="summary_desc"><div class='inline'></div></span> |
399 | 404 |
|
400 | 405 | </li>
|
401 | 406 |
|
|
440 | 445 |
|
441 | 446 |
|
442 | 447 |
|
443 |
| - <span class="summary_desc"><div class='inline'> |
444 |
| -</div></span> |
| 448 | + <span class="summary_desc"><div class='inline'></div></span> |
445 | 449 |
|
446 | 450 | </li>
|
447 | 451 |
|
|
463 | 467 |
|
464 | 468 |
|
465 | 469 |
|
466 |
| - <span class="summary_desc"><div class='inline'> |
467 |
| -</div></span> |
| 470 | + <span class="summary_desc"><div class='inline'></div></span> |
468 | 471 |
|
469 | 472 | </li>
|
470 | 473 |
|
|
555 | 558 |
|
556 | 559 |
|
557 | 560 |
|
558 |
| - <span class="summary_desc"><div class='inline'><p>Merges another genome into this evolvable’s genome.</p> |
| 561 | + <span class="summary_desc"><div class='inline'><p>Merges another genome into this evolvable's genome.</p> |
559 | 562 | </div></span>
|
560 | 563 |
|
561 | 564 | </li>
|
@@ -1486,7 +1489,7 @@ <h3 class="signature " id="merge_genome!-instance_method">
|
1486 | 1489 |
|
1487 | 1490 | </h3><div class="docstring">
|
1488 | 1491 | <div class="discussion">
|
1489 |
| - <p>Merges another genome into this evolvable’s genome. |
| 1492 | + <p>Merges another genome into this evolvable's genome. |
1490 | 1493 | Useful for combining genetic traits from different evolvables.</p>
|
1491 | 1494 |
|
1492 | 1495 |
|
@@ -1557,7 +1560,7 @@ <h3 class="signature " id="merge_genome!-instance_method">
|
1557 | 1560 | </div>
|
1558 | 1561 |
|
1559 | 1562 | <div id="footer">
|
1560 |
| - Generated on Thu May 8 23:57:27 2025 by |
| 1563 | + Generated on Fri May 9 00:09:34 2025 by |
1561 | 1564 | <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
1562 | 1565 | 0.9.37 (ruby-3.4.2).
|
1563 | 1566 | </div>
|
|
0 commit comments