public void ExecuteSelectionTest() { Individual[] individuals = new Individual[] { new Individual(new[] { 0.1, 0.2, 0.3 }, 1), new Individual(new[] { 0.2, 0.3, 0.4 }, 2), new Individual(new[] { 0.3, 0.4, 0.5 }, 3), new Individual(new[] { 0.4, 0.5, 0.6 }, 4), new Individual(new[] { 0.5, 0.6, 0.7 }, 5), new Individual(new[] { 0.6, 0.7, 0.8 }, 6) }; MGG mggExecutor = new MGG(); IndividualsGroup individualsGroup = new IndividualsGroup(); foreach (var item in individuals) { individualsGroup.AddIndivisual(item); } for (int i = 0; i < 10000; i++) { var selectedIndividuals = mggExecutor.ExecuteSelection(individualsGroup); Console.WriteLine(mggExecutor.SelectedIndividualsIndex[0].ToString() + "," + mggExecutor.SelectedIndividualsIndex[1].ToString()); } }
public void ExecuteCrossoverTest() { UNDX_Parameters undxParameters = new UNDX_Parameters() { Alpha = 0.5, Beta = 0.35, NumberOfCrossovers = 10, NumberOfParameters = 3 }; IndividualsGroup individualsGroup = new IndividualsGroup(); UNDX undx = new UNDX(undxParameters); for (int i = 0; i < 3; i++) { individualsGroup.AddIndivisual(new Individual(new double[] { 0.9 * (i + 1), 0.2 * (i + 1), 0.4 * (i + 1) }, 0.1 * (i + 1))); // For Debug Console.WriteLine(individualsGroup.IndivisualsGroup[i].OptParameters[0] + "\t" + individualsGroup.IndivisualsGroup[i].OptParameters[1] + "\t" + individualsGroup.IndivisualsGroup[i].OptParameters[2] + "\t"); } var result = undx.ExecuteCrossover(individualsGroup); // Displaying Result for (int i = 0; i < result.Length; i++) { Console.Write(i + ". "); for (int j = 0; j < result[i].Length; j++) { Console.Write(result[i][j] + "\t"); } Console.Write("\r\n"); } }
public void ExecuteGenerationChangeTest() { GenerationalChange generationalChange = new GenerationalChange(evaluationTest, GenerationalChange.GenerationChangeModel.UNDX_MGG); IndividualsGroup parents = new IndividualsGroup(); for (int i = 0; i < 3; i++) { parents.AddIndivisual(new Individual(new double[] { 0.9 * (i + 1), 0.2 * (i + 1), 0.4 * (i + 1) }, 0.1 * (i + 1))); // For Debug Console.WriteLine(parents.IndivisualsGroup[i].OptParameters[0] + "\t" + parents.IndivisualsGroup[i].OptParameters[1] + "\t" + parents.IndivisualsGroup[i].OptParameters[2] + "\t"); } var result = generationalChange.ExecuteGenerationChange(parents); for (int i = 0; i < 3; i++) { // For Debug Console.WriteLine(result.IndivisualsGroup[i].OptParameters[0] + "\t" + result.IndivisualsGroup[i].OptParameters[1] + "\t" + result.IndivisualsGroup[i].OptParameters[2] + "\t"); } }