package org.java.evolutionary.sequence; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; import ec.EvolutionState; import ec.gp.GPIndividual; /** * This is our simple implementation of Hall of Fame to capture good individuals from the run. * It writes to the file instead of holding in memory to be crash safe. * @author udaykamath * */ public class HallOfFame { PrintWriter hallOfFameWriter; public void setup(String fileName){ try{ hallOfFameWriter = new PrintWriter(fileName); }catch(Exception e){ e.printStackTrace(); } } public void addTopPopulationToHallOfFame(EvolutionState state, GPIndividual[] inds, int size){ int total = size; if(inds.length < size) total = inds.length; for(int i =0 ; i < total; i++){ inds[i].trees[0].printTree(state, hallOfFameWriter) ; //hallOfFameWriter.println("\t " + inds[i].fitness.fitness()); } hallOfFameWriter.flush(); } public void flushToFile(EvolutionState state,String fileName){ try{ hallOfFameWriter.close(); }catch(Exception e){ e.printStackTrace(); } } }