private AlgoOutput RunAlgo() { // Crossover = 80% // Mutation = 5% // Population size = 100 // Generations = 2000 // Genome size = 2 GA ga = new GA(0.8, 0.05, 100, 5, 9, MaxMin.Minimize); ga.FitnessFunction = new GAFunction(theActualFunction); //ga.FitnessFile = @"E:\fitness.csv"; ga.Elitism = true; ga.Go(); double[] values_Best; double fitness_Best; double[] values_Worst; double fitness_Worst; ga.GetBest(out values_Best, out fitness_Best); Console.WriteLine("Best ({0}):", fitness_Best); for (int i = 0; i < values_Best.Length; i++) { Console.WriteLine("{0} ", values_Best[i]); } ga.GetWorst(out values_Worst, out fitness_Worst); Console.WriteLine("\nWorst ({0}):", fitness_Worst); for (int i = 0; i < values_Worst.Length; i++) { Console.WriteLine("{0} ", values_Worst[i]); } var ar = new AlgoOutput() { Best = fitness_Best, Worst = fitness_Worst, Values_Best = values_Best, Values_Worst = values_Worst, }; return(ar); }
private AlgoOutput RunAlgo() { // Crossover = 80% // Mutation = 5% // Population size = 100 // Generations = 2000 // Genome size = 2 GA ga = new GA(0.8, 0.05, 100, 5, 9, MaxMin.Minimize); ga.FitnessFunction = new GAFunction(theActualFunction); //ga.FitnessFile = @"E:\fitness.csv"; ga.Elitism = true; ga.Go(); double[] values_Best; double fitness_Best; double[] values_Worst; double fitness_Worst; ga.GetBest(out values_Best, out fitness_Best); Console.WriteLine("Best ({0}):", fitness_Best); for (int i = 0; i < values_Best.Length; i++) Console.WriteLine("{0} ", values_Best[i]); ga.GetWorst(out values_Worst, out fitness_Worst); Console.WriteLine("\nWorst ({0}):", fitness_Worst); for (int i = 0; i < values_Worst.Length; i++) Console.WriteLine("{0} ", values_Worst[i]); var ar = new AlgoOutput() { Best=fitness_Best, Worst=fitness_Worst, Values_Best=values_Best, Values_Worst=values_Worst, }; return ar; }