aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/fitness/TruthTableEvaluator.java
blob: 987ea4c655c1be5e2a87ee54ce10a8f8794e48fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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);
			}
		}
	}

}