package ac.essex.ooechs.ecj.jasmine.nodes.classification;

import ac.essex.ooechs.ecj.commons.data.DoubleData;
import ac.essex.ooechs.ecj.ecj2java.nodes.ParseableERC;
import ac.essex.ooechs.ecj.jasmine.problems.JasmineClassificationProblemDRS;

import ec.EvolutionState;
import ec.Problem;
import ec.gp.GPData;
import ec.gp.ADFStack;
import ec.gp.GPIndividual;

/**
 * <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: 14-Jun-2007
 * @version 1.0
 */
public class FeatureERC extends ParseableERC {

    public static double[] values;

    public static int NUM_FEATURES = 20;

    public void mutateERC(EvolutionState evolutionState, int i) {
        // do nothing - not mutatable
    }

    public double setNumber(EvolutionState state, int thread) {

        value = state.random[thread].nextInt(NUM_FEATURES);

        return value;

    }

    public void eval(final EvolutionState state, final int thread, final GPData input, final ADFStack stack, final GPIndividual individual, final Problem problem) {
        DoubleData rd = ((DoubleData) (input));
        rd.x = values[(int)value];
        JasmineClassificationProblemDRS.usesImaging = true;
    }

    public String name() {
        return "ReturnClassERC";
    }

    public int getObjectType() {
        return DOUBLE;
    }

    public String toString() {
        return getJavaCode();
    }

    public String toStringForHumans() {
        return getJavaCode();
    }    

    /**
     * Convert this code to pure Java
     */
    public String getJavaCode() {
        return "values[" + (int) value + "]";
    }

}
