package test;

import org.jgap.FitnessFunction;
import org.jgap.Gene;
import org.jgap.IChromosome;

public class CalculFitnessFunction extends FitnessFunction {
	private final double toFound;

	public CalculFitnessFunction(final double toFound) {
		super();
		this.toFound = toFound;
	}

	@Override
	protected double evaluate(IChromosome a_subject) {
		Gene[] genes = a_subject.getGenes();
		double d = 0;
		for (Gene gene : genes) {
			Operation op = (Operation) gene.getApplicationData();
			d += op.calcul(d, ((Double) gene.getAllele()));
		}
		return Math.abs(toFound - d);
	}

}
