1 10 package org.jgap.perf; 11 12 import java.util.*; 13 import org.jgap.*; 14 import org.jgap.impl.*; 15 16 29 public class TestOverallPerformance { 30 31 private final static String CVS_REVISION = "$Revision: 1.5 $"; 32 33 36 private static final int MAX_ALLOWED_EVOLUTIONS = 1000; 37 38 51 public void makeChangeForAmount(int a_targetChangeAmount) 52 throws Exception { 53 Configuration.reset(); 57 Configuration conf = new DefaultConfiguration(); 58 RandomGeneratorForTest gen = new RandomGeneratorForTest(); 59 gen.setNextDouble(0.5d); 60 gen.setNextBoolean(true); 61 gen.setNextInt(3); 62 gen.setNextFloat(0.7f); 63 gen.setNextLong(6); 64 conf.setRandomGenerator(gen); 65 FitnessFunction myFunc = 70 new TestOverallPerformanceFitnessFunc(a_targetChangeAmount); 71 conf.setFitnessFunction(myFunc); 72 Gene[] sampleGenes = new Gene[10]; 86 sampleGenes[0] = new IntegerGene(conf, 0, 3); sampleGenes[1] = new IntegerGene(conf, 0, 2); sampleGenes[2] = new IntegerGene(conf, 0, 1); sampleGenes[3] = new IntegerGene(conf, 0, 4); sampleGenes[4] = new IntegerGene(conf, 0, 3); sampleGenes[5] = new IntegerGene(conf, 0, 1); sampleGenes[6] = new IntegerGene(conf, 0, 1); sampleGenes[7] = new IntegerGene(conf, 0, 2); sampleGenes[8] = new IntegerGene(conf, 0, 3); sampleGenes[9] = new IntegerGene(conf, 0, 1); Chromosome sampleChromosome = new Chromosome(conf, sampleGenes); 97 conf.setSampleChromosome(sampleChromosome); 98 conf.setPopulationSize(10000); 107 Genotype population = Genotype.randomInitialGenotype(conf); 110 for (int i = 0; i < MAX_ALLOWED_EVOLUTIONS; i++) { 114 population.evolve(); 115 } 116 population.getFittestChromosome(); 119 } 120 121 130 public static void main(String [] args) 131 throws Exception { 132 final int amount = 287; 133 final int numRuns = 20; 134 long starttime, timeMillis; 135 System.out.println("Test started."); 136 starttime = getCurrentMilliseconds(); 138 for (int i = 0; i < numRuns; i++) { 139 TestOverallPerformance runner = new TestOverallPerformance(); 140 runner.makeChangeForAmount(amount); 141 } 142 timeMillis = getCurrentMilliseconds() - starttime; 144 System.out.println("Overall time needed for executing performance test: " 145 + timeMillis + " [millisecs]"); 146 } 147 148 151 private static long getCurrentMilliseconds() { 152 Calendar cal = Calendar.getInstance(TimeZone.getDefault()); 153 return cal.getTimeInMillis(); 154 } 155 } 156 | Popular Tags |