package jcgp.modules.fitness; import jcgp.TruthTable; import jcgp.parameters.Parameters; import jcgp.population.Population; public class TruthTableEvaluator implements FitnessFunction { @Override public void evaluate(Population population) { // for every chromosome in the population for (int i = 0; i < Parameters.getPopulationSize(); i++) { int fitness = 0; // for every test case for (int t = 0; t < TruthTable.getTestCaseCount(); t++) { population.getChromosome(i).setInputs(TruthTable.getTestCase(t).getInputs()); // check every output for (int o = 0; o < Parameters.getOutputs(); o++) { if (population.getChromosome(i).getOutput(o).calculate() == TruthTable.getTestCase(t).getOutput(o)) { fitness++; } } } population.getChromosome(i).setFitness(fitness); if (Parameters.getDebug()) { System.out.println("active nodes: " + population.getChromosome(i).getActiveNodes().size()); } } } }