annotate libs/commons-math-2.1/docs/userguide/genetics.html @ 10:5f2c5fb36e93

commons-math-2.1 added
author dwinter
date Tue, 04 Jan 2011 10:00:53 +0100
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
2
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
3
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
4
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
5
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
6
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
7
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
8
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
9
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
10
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
11
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
12
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
13 <html xmlns="http://www.w3.org/1999/xhtml">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
14 <head>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
15 <title>Math - The Commons Math User Guide - Genetic Algorithms</title>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
16 <style type="text/css" media="all">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
17 @import url("../css/maven-base.css");
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
18 @import url("../css/maven-theme.css");
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
19 @import url("../css/site.css");
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
20 </style>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
21 <link rel="stylesheet" href="../css/print.css" type="text/css" media="print" />
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
22 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
23 </head>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
24 <body class="composite">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
25 <div id="banner">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
26 <span id="bannerLeft">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
27
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
28 Commons Math User Guide
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
29
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
30 </span>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
31 <div class="clear">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
32 <hr/>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
33 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
34 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
35 <div id="breadcrumbs">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
36
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
37
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
38
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
39
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
40
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
41
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
42
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
43
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
44 <div class="xright">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
45
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
46
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
47
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
48
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
49
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
50
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
51
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
52 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
53 <div class="clear">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
54 <hr/>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
55 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
56 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
57 <div id="leftColumn">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
58 <div id="navcolumn">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
59
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
60
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
61
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
62
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
63
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
64
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
65
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
66
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
67 <h5>User Guide</h5>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
68 <ul>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
69
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
70 <li class="none">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
71 <a href="../userguide/index.html">Contents</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
72 </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
73
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
74 <li class="none">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
75 <a href="../userguide/overview.html">Overview</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
76 </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
77
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
78 <li class="none">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
79 <a href="../userguide/stat.html">Statistics</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
80 </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
81
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
82 <li class="none">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
83 <a href="../userguide/random.html">Data Generation</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
84 </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
85
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
86 <li class="none">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
87 <a href="../userguide/linear.html">Linear Algebra</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
88 </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
89
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
90 <li class="none">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
91 <a href="../userguide/analysis.html">Numerical Analysis</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
92 </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
93
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
94 <li class="none">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
95 <a href="../userguide/special.html">Special Functions</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
96 </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
97
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
98 <li class="none">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
99 <a href="../userguide/utilities.html">Utilities</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
100 </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
101
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
102 <li class="none">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
103 <a href="../userguide/complex.html">Complex Numbers</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
104 </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
105
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
106 <li class="none">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
107 <a href="../userguide/distribution.html">Distributions</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
108 </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
109
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
110 <li class="none">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
111 <a href="../userguide/fraction.html">Fractions</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
112 </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
113
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
114 <li class="none">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
115 <a href="../userguide/transform.html">Transform Methods</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
116 </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
117
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
118 <li class="none">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
119 <a href="../userguide/geometry.html">3D Geometry</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
120 </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
121
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
122 <li class="none">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
123 <a href="../userguide/optimization.html">Optimization</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
124 </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
125
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
126 <li class="none">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
127 <a href="../userguide/ode.html">Ordinary Differential Equations</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
128 </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
129
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
130 <li class="none">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
131 <strong>Genetic Algorithms</strong>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
132 </li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
133 </ul>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
134 <a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
135 <img alt="Built by Maven" src="../images/logos/maven-feather.png"></img>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
136 </a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
137
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
138
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
139
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
140
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
141
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
142
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
143
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
144
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
145 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
146 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
147 <div id="bodyColumn">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
148 <div id="contentBox">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
149 <div class="section"><h2><a name="a14_Genetic_Algorithms"></a>14 Genetic Algorithms</h2>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
150 <div class="section"><h3><a name="a14.1_Overview"></a>14.1 Overview</h3>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
151 <p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
152 The genetics package provides a framework and implementations for
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
153 genetic algorithms.
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
154 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
155 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
156 <div class="section"><h3><a name="a14.2_GA_Framework"></a>14.2 GA Framework</h3>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
157 <p><a href="../apidocs/org/apache/commons/math/genetics/GeneticAlgorithm.html">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
158 org.apache.commons.math.genetic.GeneticAlgorithm</a> provides an
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
159 execution framework for Genetic Algorithms (GA).
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
160 <a href="../apidocs/org/apache/commons/math/genetics/Population.html">Populations,</a> consisting
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
161 of <a href="../apidocs/org/apache/commons/math/genetics/Chromosome.html">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
162 Chromosomes</a> are evolved by the <code>GeneticAlgorithm</code> until a
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
163 <a href="../apidocs/org/apache/commons/math/genetics/StoppingCondition.html">StoppingCondition</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
164 is reached. Evolution is determined by
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
165 <a href="../apidocs/org/apache/commons/math/genetics/SelectionPolicy.html">SelectionPolicies</a>,
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
166 <a href="../apidocs/org/apache/commons/math/genetics/MutationPolicy.html"> MutationPolicies</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
167 and <a href="../apidocs/org/apache/commons/math/genetics/Fitness.html">Fitness</a>.
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
168 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
169 <p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
170 The GA itself is implemented by the <code>evolve</code> method of the <code>GeneticAlgorithm</code> class,
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
171 which looks like this:
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
172 <div class="source"><pre>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
173 public Population evolve(Population initial, StoppingCondition condition) {
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
174 Population current = initial;
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
175 while (!condition.isSatisfied(current)) {
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
176 current = nextGeneration(current);
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
177 }
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
178 return current;
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
179 }
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
180 </pre>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
181 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
182
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
183 The <code>nextGeneration</code> method implements the following algorithm:
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
184 <ol type="1"><li>Get nextGeneration population to fill from <code>current</code>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
185 generation, using its nextGeneration method</li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
186 <li>Loop until new generation is filled:</li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
187 <ul><li>Apply configured <code>SelectionPolicy</code> to select a pair of parents
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
188 from <code>current</code></li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
189 <li>With probability =
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
190 <a href="../apidocs/org/apache/commons/math/genetics/GeneticAlgorithm.html#getCrossoverRate()">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
191 getCrossoverRate()</a>, apply configured <code>CrossoverPolicy</code> to parents</li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
192 <li>With probability =
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
193 <a href="../apidocs/org/apache/commons/math/genetics/GeneticAlgorithm.html#getMutationRate()">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
194 getMutationRate()</a>,
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
195 apply configured <code>MutationPolicy</code> to each of the offspring</li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
196 <li>Add offspring individually to nextGeneration,
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
197 space permitting</li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
198 </ul>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
199 <li>Return nextGeneration</li>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
200 </ol>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
201 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
202 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
203 <div class="section"><h3><a name="a14.3_Implementation"></a>14.3 Implementation</h3>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
204 <p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
205 Here is an example GA execution:
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
206 <div class="source"><pre>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
207 // initialize a new genetic algorithm
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
208 GeneticAlgorithm ga = new GeneticAlgorithm(
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
209 new OnePointCrossover&lt;Integer&gt;(),
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
210 1,
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
211 new RandomKeyMutation(),
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
212 0.10,
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
213 new TournamentSelection(TOURNAMENT_ARITY)
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
214 );
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
215
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
216 // initial population
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
217 Population initial = getInitialPopulation();
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
218
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
219 // stopping condition
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
220 StoppingCondition stopCond = new FixedGenerationCount(NUM_GENERATIONS);
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
221
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
222 // run the algorithm
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
223 Population finalPopulation = ga.evolve(initial, stopCond);
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
224
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
225 // best chromosome from the final population
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
226 Chromosome bestFinal = finalPopulation.getFittestChromosome();
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
227 </pre>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
228 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
229
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
230 The arguments to the <code>GeneticAlgorithm</code> constructor above are: <br />
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
231 <table class="bodyTable"><tr class="a"><th>Parameter</th>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
232 <th>value in example</th>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
233 <th>meaning</th>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
234 </tr>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
235 <tr class="b"><td>crossoverPolicy</td>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
236 <td><a href="../apidocs/org/apache/commons/math/genetics/OnePointCrossover.html">OnePointCrossover</a></td>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
237 <td>A random crossover point is selected and the first part from each parent is copied to the corresponding
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
238 child, and the second parts are copied crosswise.</td>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
239 </tr>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
240 <tr class="a"><td>crossoverRate</td>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
241 <td>1</td>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
242 <td>Always apply crossover</td>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
243 </tr>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
244 <tr class="b"><td>mutationPolicy</td>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
245 <td><a href="../apidocs/org/apache/commons/math/genetics/RandomKeyMutation.html">RandomKeyMutation</a></td>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
246 <td>Changes a randomly chosen element of the array representation to a random value uniformly distributed in [0,1].</td>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
247 </tr>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
248 <tr class="a"><td>mutationRate</td>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
249 <td>.1</td>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
250 <td>Apply mutation with probability 0.1 - that is, 10% of the time.</td>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
251 </tr>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
252 <tr class="b"><td>selectionPolicy</td>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
253 <td><a href="../apidocs/org/apache/commons/math/genetics/TournamentSelection.html">TournamentSelection</a></td>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
254 <td>Each of the two selected chromosomes is selected based on an n-ary tournament -- this is done by drawing
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
255 n random chromosomes without replacement from the population, and then selecting the fittest chromosome among them.</td>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
256 </tr>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
257 </table>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
258 <br />
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
259
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
260 The algorithm starts with an <code>initial</code> population of <code>Chromosomes.</code> and executes until
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
261 the specified <a href="../apidocs/org/apache/commons/math/genetics/StoppingCondition.html">StoppingCondition</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
262 is reached. In the example above, a
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
263 <a href="../apidocs/org/apache/commons/math/genetics/FixedGenerationCount.html">FixedGenerationCount</a>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
264 stopping condition is used, which means the algorithm proceeds through a fixed number of generations.
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
265 </p>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
266 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
267 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
268
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
269 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
270 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
271 <div class="clear">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
272 <hr/>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
273 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
274 <div id="footer">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
275 <div class="xright">&#169;
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
276 2003-2010
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
277
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
278
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
279
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
280
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
281
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
282
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
283
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
284
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
285
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
286 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
287 <div class="clear">
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
288 <hr/>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
289 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
290 </div>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
291 </body>
5f2c5fb36e93 commons-math-2.1 added
dwinter
parents:
diff changeset
292 </html>