public void GeneralEdgeRecombinationCrossover_ElementsAreRepeated() { var elements = new [] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" }; var generator = new FromElementsVectorChromosomePopulationGenerator <string>(elements, elements.Length, true, null, null); var parentChromosomes = generator.GeneratePopulation(2); var child = new GeneralEdgeRecombinationCrossover <string>(null, null).Crossover(parentChromosomes.ElementAt(0), parentChromosomes.ElementAt(1)).ToArray <string>(); var distinctElements = child.Distinct().Count(); Assert.IsTrue(distinctElements < 10); }
public void GeneralEdgeRecombinationCrossover_NextNodeIsNeighborsOfPreviousNode() { var elements = new[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" }; var generator = new FromElementsVectorChromosomePopulationGenerator <string>(elements, elements.Length, true, null, null); var parentChromosomes = generator.GeneratePopulation(2); var child = new GeneralEdgeRecombinationCrossover <string>(null, null).Crossover(parentChromosomes.ElementAt(0), parentChromosomes.ElementAt(1)).ToArray <string>(); for (int i = 0; i < child.Length - 1; i++) { var neigbors = GetNeighbors(parentChromosomes.ElementAt(0).ToArray <string>(), parentChromosomes.ElementAt(1).ToArray <string>(), child[i]); if (neigbors.Count == 0) { continue; } Assert.IsTrue(neigbors.Contains(child[i + 1]), "Didn't jump to neighbor"); } }