public void MutationTest1() { int populationSize = 2000; file = root + "\\bays29.xml"; XDocument tspFile = XDocument.Load(file); AdjacencyMatrix testMatrix = new AdjacencyMatrix(tspFile); PMXCrossover crossover = new PMXCrossover((float)(0.80)); TournamentSelection selector = new TournamentSelection((int)populationSize / 2); InversionMutation inv = new InversionMutation((float)0.05); GeneticSolver solver = new GeneticSolver(testMatrix, inv, crossover, selector, populationSize, 10); List <Candidate> listCand = solver.randomPopulation(); Candidate parentX = listCand[0]; Candidate parentY = listCand[1]; parentX.chromoson = new List <int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; parentY.chromoson = new List <int>() { 5, 3, 6, 7, 8, 1, 2, 9, 4, }; inv.Mutate(parentX); }
public void ItCanRandomlyInverseGenes() { var chromosome = GATestHelper.GetAlphabetCharacterChromosome(); var mutation = new InversionMutation(); for (int i = 0; i < 100; i++) { mutation.Mutate(chromosome, GATestHelper.GetTravelingSalesmanDefaultConfiguration()); } }
public void Should_Perform_Mutation() { var algorithm = new InversionMutation(1); var a = new Element(new double[] { 8D, 3D, 2D, 9D, 1D, 0D, 7D, 6D, 5D, 4D }); algorithm.Mutate(ref a, 1, 4); var expectedData = new double[] { 8D, 1D, 9D, 2D, 3D, 0D, 7D, 6D, 5D, 4D }; Assert.Equal(expectedData, a.Data); }