|
Chromosomes.
and executes until
the specified <a href="../apidocs/org/apache/commons/math/genetics/StoppingCondition.html">StoppingCondition
is reached. In the example above, a
<a href="../apidocs/org/apache/commons/math/genetics/FixedGenerationCount.html">FixedGenerationCount
stopping condition is used, which means the algorithm proceeds through a fixed number of generations.
</p>
</subsection>
</section>
</body>
</document>
Here is a short list of links related to this Commons Math genetics.xml source code file:
Commons Math example source code file (genetics.xml)
The Commons Math genetics.xml source code<?xml version="1.0"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <?xml-stylesheet type="text/xsl" href="./xdoc.xsl"?> <!-- $Revision: 799857 $ $Date: 2009-08-01 09:07:12 -0400 (Sat, 01 Aug 2009) $ --> <document url="genetics.html"> <properties> <title>The Commons Math User Guide - Genetic Algorithms </properties> <body> <section name="14 Genetic Algorithms"> <subsection name="14.1 Overview" href="overview"> <p> The genetics package provides a framework and implementations for genetic algorithms. </p> </subsection> <subsection name="14.2 GA Framework"> <p> <a href="../apidocs/org/apache/commons/math/genetics/GeneticAlgorithm.html"> org.apache.commons.math.genetic.GeneticAlgorithm</a> provides an execution framework for Genetic Algorithms (GA). <a href="../apidocs/org/apache/commons/math/genetics/Population.html">Populations, consisting of <a href="../apidocs/org/apache/commons/math/genetics/Chromosome.html"> Chromosomes</a> are evolved by the SelectionPolicy to select a pair of parents
from <code>currentCrossoverPolicy to parents
<li>With probability =
<a href="../apidocs/org/apache/commons/math/genetics/GeneticAlgorithm.html#getMutationRate()">
getMutationRate()</a>,
apply configured <code>MutationPolicy to each of the offspring
<li>Add offspring individually to nextGeneration,
space permitting</li>
</ul>
<li>Return nextGeneration
</ol>
</p>
</subsection>
<subsection name="14.3 Implementation">
<p>
Here is an example GA execution:
<source>
// initialize a new genetic algorithm
GeneticAlgorithm ga = new GeneticAlgorithm(
new OnePointCrossover<Integer>(),
1,
new RandomKeyMutation(),
0.10,
new TournamentSelection(TOURNAMENT_ARITY)
);
// initial population
Population initial = getInitialPopulation();
// stopping condition
StoppingCondition stopCond = new FixedGenerationCount(NUM_GENERATIONS);
// run the algorithm
Population finalPopulation = ga.evolve(initial, stopCond);
// best chromosome from the final population
Chromosome bestFinal = finalPopulation.getFittestChromosome();
</source>
The arguments to the <code>GeneticAlgorithm constructor above are: <table> <tr> | Parameter | value in example | meaning | |
---|---|---|---|---|
crossoverPolicy | ||||
crossoverRate | ||||
mutationPolicy | ||||
mutationRate | ||||
selectionPolicy |
... this post is sponsored by my books ... | |
![]() #1 New Release! |
![]() FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.