public void SmallSumDecTest() { // representation of 10 in terms of summand inclusion // SumFitnessHelper could be adapted to take an int String goal = "0011"; int[] summands = new int[] { 1, 2, 3, 4 }; FH = new SumDecFitnessHelper(summands, goal); Func <string, double> f; f = FH.Fitness; int size = goal.Length; string hypothesis = GA.Run(f, size, 0.6, 0.002, 500); Assert.AreEqual(goal, hypothesis); }
public void LargeTests() { StringBuilder sb; string goal; Func <string, double> f; int size = 20; for (int i = 0; i < 3; ++i) { sb = new StringBuilder(size); for (int j = 0; j < size; ++j) { sb.Append(Math.Floor(2 * random.NextDouble()).ToString()); } goal = sb.ToString(); FH = new BitStringFitnessHelper(goal); f = FH.Fitness; Assert.AreEqual(goal, GA.Run(f, size, 0.6, 0.002, 600)); } }