public void FitnessCalculationTest() { IReadOnlyFitnessCalculator test = FitnessCalculator.getInstance(); IReadOnlyIndividual indiv = new Individual("Hello World!"); IReadOnlyIndividual halfIndiv = new Individual("Hello "); IReadOnlyIndividual goal = new Individual("Hello World!"); double fitness = test.CalcFitness(indiv, goal); double halfFitness = test.CalcFitness(halfIndiv, goal); Assert.AreEqual(1.0d, fitness); Assert.AreEqual(0.5d, halfFitness); }
public void PopFitnessCalculationTest() { //arrange IReadOnlyFitnessCalculator test = FitnessCalculator.getInstance(); Population pop = new Population(); pop.Populate(10); //act test.CalcFitness(pop); //assert foreach (Individual i in pop) { Assert.AreNotEqual(-1.0d, i.Fitness); } }
static void Main(string[] args) { calc = FitnessCalculator.getInstance(); config = ConfigClass.getInstance(); //1. Initialize Population p = new Population(true); //4. Repeat with new generation while (Console.ReadKey().KeyChar != 'x') { p = GenerationStep(p); foreach (IReadOnlyIndividual i in p) { Console.WriteLine(i); } Console.WriteLine("Continue to next generation? (Press x to exit)"); } }