Replace genetic algorithm ASCII-art with a real figure

Author: Jürgen Purtz
Discussion: https://postgr.es/m/c6027f7a-78ea-8453-0837-09903ba5fd9b@purtz.de
This commit is contained in:
Alvaro Herrera 2019-08-19 12:05:38 -04:00
parent a407012c07
commit 28b6ec1df6
4 changed files with 200 additions and 44 deletions

View File

@ -84,9 +84,19 @@
Through simulation of the evolutionary operations <firstterm>recombination</firstterm>,
<firstterm>mutation</firstterm>, and
<firstterm>selection</firstterm> new generations of search points are found
that show a higher average fitness than their ancestors.
that show a higher average fitness than their ancestors. <xref linkend="geqo-figure"/>
illustrates these steps.
</para>
<figure id="geqo-figure">
<title>Structure of a Genetic Algorithm</title>
<mediaobject>
<imageobject>
<imagedata fileref="images/genetic-algorithm.svg" format="SVG" width="100%"/>
</imageobject>
</mediaobject>
</figure>
<para>
According to the <systemitem class="resource">comp.ai.genetic</systemitem> <acronym>FAQ</acronym> it cannot be stressed too
strongly that a <acronym>GA</acronym> is not a pure random search for a solution to a
@ -94,49 +104,6 @@
non-random (better than random).
</para>
<figure id="geqo-diagram">
<title>Structured Diagram of a Genetic Algorithm</title>
<informaltable frame="none">
<tgroup cols="2">
<tbody>
<row>
<entry>P(t)</entry>
<entry>generation of ancestors at a time t</entry>
</row>
<row>
<entry>P''(t)</entry>
<entry>generation of descendants at a time t</entry>
</row>
</tbody>
</tgroup>
</informaltable>
<literallayout class="monospaced">
+=========================================+
|&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Algorithm GA &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;|
+=========================================+
| INITIALIZE t := 0 |
+=========================================+
| INITIALIZE P(t) |
+=========================================+
| evaluate FITNESS of P(t) |
+=========================================+
| while not STOPPING CRITERION do |
| +-------------------------------------+
| | P'(t) := RECOMBINATION{P(t)} |
| +-------------------------------------+
| | P''(t) := MUTATION{P'(t)} |
| +-------------------------------------+
| | P(t+1) := SELECTION{P''(t) + P(t)} |
| +-------------------------------------+
| | evaluate FITNESS of P''(t) |
| +-------------------------------------+
| | t := t + 1 |
+===+=====================================+
</literallayout>
</figure>
</sect1>
<sect1 id="geqo-pg-intro">

View File

@ -3,6 +3,7 @@
# see README in this directory about image handling
ALL_IMAGES = \
genetic-algorithm.svg \
gin.svg \
pagelayout.svg

View File

@ -0,0 +1,48 @@
digraph {
layout=dot;
// default values
node [shape=box, label="", fontname="sans-serif", style=filled, fillcolor=white, fontsize=8];
graph [fontname="sans-serif"]; // must be specified separately
edge [fontname="sans-serif"]; // must be specified separately
// an unobtrusive background color
pad="1.0, 0.5";
bgcolor=whitesmoke;
// layout of edges and nodes
splines=ortho;
nodesep=0.3;
ranksep=0.3;
// nodes
a1[label="INITIALIZE t := 0"];
a2[label="INITIALIZE P(t)"];
a3[label="evaluate FITNESS of P(t)"];
a4[shape="diamond", label="STOPPING CRITERION"; width=4];
// connect 'end' node with 'a9' node (bottom of figure)
{
rank=same;
a9[label="t := t + 1"];
// end-symbol similar to UML notation
end[shape=doublecircle, label="end", width=0.5];
}
a5[label="P'(t) := RECOMBINATION{P(t)}"];
a6[label="P''(t) := MUTATION{P'(t)}"];
a7[label="P(t+1) := SELECTION{P''(t) + P(t)}"];
a8[label="evaluate FITNESS of P''(t)"];
// edges
a1 -> a2 -> a3 -> a4;
a4 -> a5[xlabel="false ", fontsize=10];
a4 -> end[xlabel="true ", fontsize=10];
a5 -> a6 -> a7 -> a8 -> a9;
a4 -> a9 [dir=back];
// explain the notation
expl [shape=plaintext, fontsize=10, width=3.2, fillcolor=whitesmoke,
label="P(t): generation of ancestors at a time t\lP''(t): generation of descendants at a time t\l"];
}

View File

@ -0,0 +1,140 @@
<?xml version="1.0"?>
<!-- Generated by graphviz version 2.40.1 (20161225.0304)
-->
<!-- Title: %3 Pages: 1 -->
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="583pt" height="580pt" viewBox="0.00 0.00 583.00 580.30">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(72 544.3026)">
<title>%3</title>
<polygon fill="#f5f5f5" stroke="none" points="-72,36 -72,-544.3026 511,-544.3026 511,36 -72,36"/>
<!-- a1 -->
<g id="node1" class="node">
<title>a1</title>
<polygon fill="#ffffff" stroke="#000000" points="187,-508.3026 101,-508.3026 101,-472.3026 187,-472.3026 187,-508.3026"/>
<text text-anchor="middle" x="144" y="-488.4026" font-family="sans-serif" font-size="8.00" fill="#000000">INITIALIZE t := 0</text>
</g>
<!-- a2 -->
<g id="node2" class="node">
<title>a2</title>
<polygon fill="#ffffff" stroke="#000000" points="182,-450.3026 106,-450.3026 106,-414.3026 182,-414.3026 182,-450.3026"/>
<text text-anchor="middle" x="144" y="-430.4026" font-family="sans-serif" font-size="8.00" fill="#000000">INITIALIZE P(t)</text>
</g>
<!-- a1&#45;&gt;a2 -->
<g id="edge1" class="edge">
<title>a1-&gt;a2</title>
<path fill="none" stroke="#000000" d="M144,-472.269C144,-472.269 144,-460.5248 144,-460.5248"/>
<polygon fill="#000000" stroke="#000000" points="147.5001,-460.5248 144,-450.5248 140.5001,-460.5249 147.5001,-460.5248"/>
</g>
<!-- a3 -->
<g id="node3" class="node">
<title>a3</title>
<polygon fill="#ffffff" stroke="#000000" points="203.5,-392.3026 84.5,-392.3026 84.5,-356.3026 203.5,-356.3026 203.5,-392.3026"/>
<text text-anchor="middle" x="144" y="-372.4026" font-family="sans-serif" font-size="8.00" fill="#000000">evaluate FITNESS of P(t)</text>
</g>
<!-- a2&#45;&gt;a3 -->
<g id="edge2" class="edge">
<title>a2-&gt;a3</title>
<path fill="none" stroke="#000000" d="M144,-414.269C144,-414.269 144,-402.5248 144,-402.5248"/>
<polygon fill="#000000" stroke="#000000" points="147.5001,-402.5248 144,-392.5248 140.5001,-402.5249 147.5001,-402.5248"/>
</g>
<!-- a4 -->
<g id="node4" class="node">
<title>a4</title>
<polygon fill="#ffffff" stroke="#000000" points="144,-334.3026 0,-316.3026 144,-298.3026 288,-316.3026 144,-334.3026"/>
<text text-anchor="middle" x="144" y="-314.4026" font-family="sans-serif" font-size="8.00" fill="#000000">STOPPING CRITERION</text>
</g>
<!-- a3&#45;&gt;a4 -->
<g id="edge3" class="edge">
<title>a3-&gt;a4</title>
<path fill="none" stroke="#000000" d="M144,-356.269C144,-356.269 144,-344.5248 144,-344.5248"/>
<polygon fill="#000000" stroke="#000000" points="147.5001,-344.5248 144,-334.5248 140.5001,-344.5249 147.5001,-344.5248"/>
</g>
<!-- a9 -->
<g id="node5" class="node">
<title>a9</title>
<polygon fill="#ffffff" stroke="#000000" points="106,-40.1513 50,-40.1513 50,-4.1513 106,-4.1513 106,-40.1513"/>
<text text-anchor="middle" x="78" y="-20.2513" font-family="sans-serif" font-size="8.00" fill="#000000">t := t + 1</text>
</g>
<!-- a4&#45;&gt;a9 -->
<g id="edge10" class="edge">
<title>a4-&gt;a9</title>
<path fill="none" stroke="#000000" d="M56.75,-299.0314C56.75,-299.0314 56.75,-40.524 56.75,-40.524"/>
<polygon fill="#000000" stroke="#000000" points="53.2501,-299.0314 56.75,-309.0314 60.2501,-299.0314 53.2501,-299.0314"/>
</g>
<!-- end -->
<g id="node6" class="node">
<title>end</title>
<ellipse fill="#ffffff" stroke="#000000" cx="259" cy="-22.1513" rx="18.2761" ry="18.2761"/>
<ellipse fill="none" stroke="#000000" cx="259" cy="-22.1513" rx="22.3036" ry="22.3036"/>
<text text-anchor="middle" x="259" y="-20.2513" font-family="sans-serif" font-size="8.00" fill="#000000">end</text>
</g>
<!-- a4&#45;&gt;end -->
<g id="edge5" class="edge">
<title>a4-&gt;end</title>
<path fill="none" stroke="#000000" d="M259,-312.5834C259,-312.5834 259,-54.659 259,-54.659"/>
<polygon fill="#000000" stroke="#000000" points="262.5001,-54.659 259,-44.659 255.5001,-54.6591 262.5001,-54.659"/>
<text text-anchor="middle" x="246" y="-186.6212" font-family="sans-serif" font-size="10.00" fill="#000000">true  </text>
</g>
<!-- a5 -->
<g id="node7" class="node">
<title>a5</title>
<polygon fill="#ffffff" stroke="#000000" points="216,-276.3026 72,-276.3026 72,-240.3026 216,-240.3026 216,-276.3026"/>
<text text-anchor="middle" x="144" y="-256.4026" font-family="sans-serif" font-size="8.00" fill="#000000">P'(t) := RECOMBINATION{P(t)}</text>
</g>
<!-- a4&#45;&gt;a5 -->
<g id="edge4" class="edge">
<title>a4-&gt;a5</title>
<path fill="none" stroke="#000000" d="M144,-298.269C144,-298.269 144,-286.5248 144,-286.5248"/>
<polygon fill="#000000" stroke="#000000" points="147.5001,-286.5248 144,-276.5248 140.5001,-286.5249 147.5001,-286.5248"/>
<text text-anchor="middle" x="127" y="-284.3969" font-family="sans-serif" font-size="10.00" fill="#000000">false   </text>
</g>
<!-- a6 -->
<g id="node8" class="node">
<title>a6</title>
<polygon fill="#ffffff" stroke="#000000" points="204.5,-218.3026 83.5,-218.3026 83.5,-182.3026 204.5,-182.3026 204.5,-218.3026"/>
<text text-anchor="middle" x="144" y="-198.4026" font-family="sans-serif" font-size="8.00" fill="#000000">P''(t) := MUTATION{P'(t)}</text>
</g>
<!-- a5&#45;&gt;a6 -->
<g id="edge6" class="edge">
<title>a5-&gt;a6</title>
<path fill="none" stroke="#000000" d="M144,-240.269C144,-240.269 144,-228.5248 144,-228.5248"/>
<polygon fill="#000000" stroke="#000000" points="147.5001,-228.5248 144,-218.5248 140.5001,-228.5249 147.5001,-228.5248"/>
</g>
<!-- a7 -->
<g id="node9" class="node">
<title>a7</title>
<polygon fill="#ffffff" stroke="#000000" points="224.5,-160.3026 63.5,-160.3026 63.5,-124.3026 224.5,-124.3026 224.5,-160.3026"/>
<text text-anchor="middle" x="144" y="-140.4026" font-family="sans-serif" font-size="8.00" fill="#000000">P(t+1) := SELECTION{P''(t) + P(t)}</text>
</g>
<!-- a6&#45;&gt;a7 -->
<g id="edge7" class="edge">
<title>a6-&gt;a7</title>
<path fill="none" stroke="#000000" d="M144,-182.269C144,-182.269 144,-170.5248 144,-170.5248"/>
<polygon fill="#000000" stroke="#000000" points="147.5001,-170.5248 144,-160.5248 140.5001,-170.5249 147.5001,-170.5248"/>
</g>
<!-- a8 -->
<g id="node10" class="node">
<title>a8</title>
<polygon fill="#ffffff" stroke="#000000" points="196.5,-102.3026 73.5,-102.3026 73.5,-66.3026 196.5,-66.3026 196.5,-102.3026"/>
<text text-anchor="middle" x="135" y="-82.4026" font-family="sans-serif" font-size="8.00" fill="#000000">evaluate FITNESS of P''(t)</text>
</g>
<!-- a7&#45;&gt;a8 -->
<g id="edge8" class="edge">
<title>a7-&gt;a8</title>
<path fill="none" stroke="#000000" d="M135,-124.269C135,-124.269 135,-112.5248 135,-112.5248"/>
<polygon fill="#000000" stroke="#000000" points="138.5001,-112.5248 135,-102.5248 131.5001,-112.5249 138.5001,-112.5248"/>
</g>
<!-- a8&#45;&gt;a9 -->
<g id="edge9" class="edge">
<title>a8-&gt;a9</title>
<path fill="none" stroke="#000000" d="M89.75,-65.9913C89.75,-65.9913 89.75,-50.5465 89.75,-50.5465"/>
<polygon fill="#000000" stroke="#000000" points="93.2501,-50.5464 89.75,-40.5465 86.2501,-50.5465 93.2501,-50.5464"/>
</g>
<!-- expl -->
<g id="node11" class="node">
<title>expl</title>
<polygon fill="#f5f5f5" stroke="none" points="439,-508.3026 209,-508.3026 209,-472.3026 439,-472.3026 439,-508.3026"/>
<text text-anchor="start" x="217" y="-493.3026" font-family="sans-serif" font-size="10.00" fill="#000000">P(t): generation of ancestors at a time t</text>
<text text-anchor="start" x="217" y="-482.3026" font-family="sans-serif" font-size="10.00" fill="#000000">P''(t): generation of descendants at a time t</text>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 7.3 KiB