//The method the sort the genomes. #endregion public void PopulationGeneration() { for (int i = 0; i < kInitialPopulation; i++) { ListGenome aGenome = new ListGenome(kMin, kMax, kParameterMin, kParameterMax, kParameterStep); int kLength = kParameterMin.Length; int crossoverRandomSeed = ListGenome.TheSeed.Next(kLength); kCrossover = crossoverRandomSeed; //kCrossover or crossover point was a random number among the length of the genome. aGenome.SetCrossoverPoint(kCrossover); aGenome.CalculateFitness(calibrationRoundID, dataDirectory, workDirectory, projectDirectory, genericAlgorithmsDirectory, observationArray, stdArray, kParameterSiteIndex, amplificationFactor, CV, observationDateArray, observationSeperator); aGenome.OutputString(observationArray); Genomes.Add(aGenome); } Genomes.Sort(myCompareMethod); int kPopulationLimitOfInitialPopulation = 20 * kPopulationLimit;//The population limit of first generation is 10 times of the limits of other generations. // kill all the genes above the population limit if (Genomes.Count > kPopulationLimitOfInitialPopulation) { Genomes.RemoveRange(kPopulationLimitOfInitialPopulation, Genomes.Count - kPopulationLimitOfInitialPopulation); } CurrentPopulation = Genomes.Count; }
public void LocalPopulationGeneration( ) { int parameterNumber = optimalParameterValueArray.Count; double bestFitness = 0; int numberOfGenomes = 0; double[] kLocalParameterValue = new double[parameterNumber]; double[] kLocalParameterMin = new double[parameterNumber]; double[] kLocalParameterMax = new double[parameterNumber]; double[] kLocalParameterStep = new double[parameterNumber]; double[] kLocalParameterStepLimit = new double[parameterNumber]; for (int i = 0; i < optimalParameterValueArray.Count; i++) { double tempLocalParameterValue = Convert.ToDouble(optimalParameterValueArray[i]); kLocalParameterValue[i] = tempLocalParameterValue; double tempInitialParameterMin = kParameterMin[i]; double tempInitialParameterMax = kParameterMax[i]; kLocalParameterMin[i] = Math.Max((tempLocalParameterValue * (1 - kLocalParameterRatio)), tempInitialParameterMin); kLocalParameterMax[i] = Math.Min((tempLocalParameterValue * (1 + kLocalParameterRatio)), tempInitialParameterMax); //Restric the local seaching range of the parameters with climbing hill methods. Modified by He, 14/10/2010. kLocalParameterStep[i] = kParameterStep[i] * (kLocalParameterRatio / kLocalParameterRatioPartition); //Define the local searching spaces. } for (int j = 0; j < kLocalPopulation; j++) { ListGenome aGenome = new ListGenome(kMin, kMax, kLocalParameterValue, kLocalParameterMin, kLocalParameterMax, kLocalParameterStep, kParameterChangeProbability); aGenome.CalculateFitness(calibrationRoundID, dataDirectory, workDirectory, projectDirectory, genericAlgorithmsDirectory, observationArray, stdArray, kParameterSiteIndex, amplificationFactor, CV, observationDateArray, observationSeperator); aGenome.OutputString(observationArray); if (j == 0) { Genomes.Add(aGenome); } //Add the first genome. numberOfGenomes = Genomes.Count; double tempFitness = aGenome.CurrentFitness; if (tempFitness > bestFitness) { Genomes.RemoveAt((numberOfGenomes - 1));//Remove the last element of Genomes. Genomes.Add(aGenome); bestFitness = tempFitness; } } }