/* * Genalg.java * * Copyright 2011 Paul Cockshott * * * * */ import java.util.Random; import java.util.Arrays; public class Genalg { Gene [] population; int n; public Genalg(int n,Gene g ){ this.n = n; population = new Gene[n]; population[0] = g; for (int i=1;i population[mid].fitness) { first = mid + 1; // Repeat search in top half. } else { identical = g.hash == population[mid].hash; break; } } if(!identical) for(j=0;jpopulation[j].fitness) { if (j<(n-1)){ if(f>population[j+1].fitness) population[j] = population[j+1]; else {population[j] = g; break;} } else population[j] = g; } } } } public static void main (String args[]) { int N=32;int pop=24; for(int j=0;j<10;j++) { Gene g = new Permutor1(N, new SillyEvaluator()); Genalg alg = new Genalg(pop,g); for(int i=0;i<2000;i++){ //alg.showPop(); //System.out.println("-----------------"); alg.optimise(1); System.out.println(""+N+","+(pop+i)+","+alg.population[pop-1].fitness); } } } }