package ac.essex.ooechs.ecj.jasmine.util;

import ec.gp.koza.KozaStatistics;
import ec.gp.koza.KozaFitness;
import ec.EvolutionState;
import ec.util.Output;
import ec.simple.SimpleProblemForm;
import ac.essex.ooechs.ecj.jasmine.problems.ECJMulticlassClassificationProblem2;

/**
 *
 * <p>
 * Causes the descibe method on the MathsProblem class to fire
 * at the end of every generation, allowing the JavaWriter
 * to output the best individual as a Java file
 * </p>
 *
 * <p/>
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version,
 * provided that any use properly credits the author.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details at http://www.gnu.org
 * </p>
 *
 * @author Olly Oechsle, University of Essex, Date: 05-Sep-2006
 * @version 1.0
 */
public class StatisticsPrinter extends KozaStatistics {

    public void postEvaluationStatistics(EvolutionState state) {

        super.postEvaluationStatistics(state);
        // we have only one population, so this is kosher
        // call the describe method which allows us to process the best individual
        // at the end of every generation. In this case we'd like to convert that individual
        // into Java and save it for later use.
        //((SimpleProblemForm) (state.evaluator.p_problem.clone())).describe(best_of_run[0], state, 0, statisticslog, Output.V_NO_GENERAL);

        ec.Individual ind = best_of_run[0];
        int gen = state.generation;
        float fitness = ((KozaFitness) ind.fitness).rawFitness();
        int hits = ((KozaFitness) ind.fitness).hits;
        long size = ind.size();
        long time = System.currentTimeMillis() - ECJMulticlassClassificationProblem2.start;

        System.out.println(gen + ", " + fitness + ", " + hits + ", 0" + ", " + size + ", " + time + ", " + ECJMulticlassClassificationProblem2.nodeCount + ", evals=" + ECJMulticlassClassificationProblem2.evals);

    }

}
