?? testgenetics.java
字號(hào):
/*
* This file is part of JGAP.
*
* JGAP offers a dual license model containing the LGPL as well as the MPL.
*
* For licencing information please see the file license.txt included with JGAP
* or have a look at the top of class org.jgap.Chromosome which representatively
* includes the JGAP license policy applicable for any file delivered with JGAP.
*/
package examples.simpleBoolean;
import org.jgap.*;
import org.jgap.impl.*;
/**
* Simple test class that demonstrates basic usage of JGAP.
*
* @author Neil Rotstan
* @author Klaus Meffert
* @since 2.0
*/
public class TestGenetics {
/** String containing the CVS revision. Read out via reflection!*/
private static final String CVS_REVISION = "$Revision: 1.5 $";
/**
* Starts the example
* @param args ignored here
*/
public static void main(String[] args) {
int numEvolutions = 500;
Configuration gaConf = new DefaultConfiguration();
gaConf.setPreservFittestIndividual(true);
gaConf.setKeepPopulationSizeConstant(false);
Genotype genotype = null;
try {
int chromeSize = 16;
if (chromeSize > 32) {
System.err.println("This example does not handle " +
"Chromosomes greater than 32 bits in length.");
System.exit( -1);
}
Chromosome sampleChromosome = new Chromosome(new BooleanGene(),
chromeSize);
gaConf.setSampleChromosome(sampleChromosome);
gaConf.setPopulationSize(20);
gaConf.setFitnessFunction(new MaxFunction());
genotype = Genotype.randomInitialGenotype(gaConf);
}
catch (InvalidConfigurationException e) {
e.printStackTrace();
System.exit( -2);
}
int progress = 0;
int percentEvolution = numEvolutions / 100;
for (int i = 0; i < numEvolutions; i++) {
genotype.evolve();
// Print progress.
// ---------------
if (percentEvolution > 0 && i % percentEvolution == 0) {
progress++;
Chromosome fittest = genotype.getFittestChromosome();
double fitness = fittest.getFitnessValue();
System.out.println("Fittest Chromosome has value " + fitness);
}
}
Chromosome fittest = genotype.getFittestChromosome();
System.out.println("Fittest Chromosome has value " +
fittest.getFitnessValue());
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -