package jcgp.modules.fitness; import java.util.HashMap; import jcgp.JCGP.Resources; import jcgp.parameters.Parameter; import jcgp.population.Population; public class TestCaseEvaluator implements FitnessFunction { @Override public void evaluate(Population population, Resources resources) { // for every chromosome in the population for (int i = 0; i < (int) resources.get("popSize"); i++) { int fitness = 0; // for every test case for (int t = 0; t < resources.getTestCaseCount(); t++) { population.getChromosome(i).setInputs(resources.getTestCase(t).getInputs()); // check every output for (int o = 0; o < (int) resources.get("outputs"); o++) { if (population.getChromosome(i).getOutput(o).calculate() == resources.getTestCase(t).getOutput(o)) { fitness++; } } } population.getChromosome(i).setFitness(fitness); } } @Override public HashMap activate(Resources parameters) { return new HashMap(); } }