package jcgp.fitness; import jcgp.Parameters; import jcgp.TruthTable; import jcgp.population.Chromosome; import jcgp.population.Population; public class TruthTableEvaluator implements FitnessFunction { @Override public void evaluate(Population population) { for (Chromosome chromosome : population) { for (int t = 0; t < TruthTable.getTestCaseCount(); t++) { chromosome.setInputs(TruthTable.getTestCase(t).getInputs()); int fitness = 0; for (int o = 0; o < Parameters.getOutputs(); o++) { if (chromosome.getOutput(o).calculate() == TruthTable.getTestCase(t).getOutput(o)) { fitness++; } } chromosome.setFitness(fitness); } } } }