static void Main(string[] args) { var population = new Population(6); var geneticAlgorythm = new GeneticAlgorithm(population, FitnessFunction, -3, 1, 0, 3, 1); geneticAlgorythm.Execute(); }
static void Main(string[] args) { //TestFunc1 double[] lowerBd = new double[] { -100.0, -100.0, -100.0, -100.0, -100.0, -100.0, -100.0, -100.0, -100.0, -100.0 }; double[] upperBd = new double[] { 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0 }; int[] decimalPlace = new int[] { 15, 15, 15, 15, 15, 15, 15, 15, 15, 15 };//[0,15] //double[] lowerBd = new double[] {-Math.PI,-Math.PI }; //double[] upperBd = new double[] { Math.PI, Math.PI }; //int[] decimalPlace = new int[] { 15, 15};//[0,15] ////TestFunc5 //double[] lowerBd = new double[] { -5, -5 }; //double[] upperBd = new double[] { 5, 5 }; //int[] decimalPlace = new int[] { 15, 15 };//[0,15] int maxIteration = 1000;// maximum iteration int numPopulation = 30; // number of Population int ChromosomeSize = lowerBd.Length; //num of the parameters int PS = ChromosomeSize * 10; //populationSize double PcUpper = 0.95; //crossover upper Probability double PcLower = 0.7; //crossover lower Probability double PmUpper = 0.1; //mutation upper Probability double PmLower = 0.01; //mutation lower Probability List <int> populationSizeList = new List <int>(numPopulation); List <double> crossoverProbabilityList = new List <double>(numPopulation); List <double> mutationProbabilityList = new List <double>(numPopulation); for (int i = 0; i < numPopulation; i++) { populationSizeList.Add(PS); crossoverProbabilityList.Add(myRandom.NextDouble(PcLower, PcUpper)); mutationProbabilityList.Add(myRandom.NextDouble(PmLower, PmUpper)); } int[] populationSize = populationSizeList.ToArray(); double[] crossoverProbability = crossoverProbabilityList.ToArray(); double[] mutationProbability = mutationProbabilityList.ToArray(); int currentIteration = 0; GeneticAlgorithm Genetic = new GeneticAlgorithm(ChromosomeSize, lowerBd, upperBd, decimalPlace, populationSize, crossoverProbability, mutationProbability, numPopulation, currentIteration, maxIteration); Genetic.PopsOfGaIni(); Genetic.Execute(); Console.WriteLine("end~~~"); Console.ReadKey(); }