/// <summary> /// 1. Dynamic rate mute operator /// </summary> /// <param name="chrom">The individual to mutate</param> /// <returns>A mutated individual</returns> public Chromosome DRM(Chromosome chrom) { int nVar, nmu, it, MaxIt; int[] muLocation;// double a, b, sm; nVar = chrom.chromosome.Length; //double[] chromosomeTemp = chrom.chromosome; double[] Fai0; //Chromosome chromTemp =(Chromosome)DeepClone(chrom);// deep clone not work Chromosome chromTemp = Chromosome.Clone <Chromosome>(chrom);//use this method doing deep copy nmu = Convert.ToInt32(Math.Ceiling(chrom.MutationProbability * nVar)); if (nmu > nVar) { nmu = nVar; } muLocation = myRandom.NextUnique(1, nVar, nmu); //生成nmu个1~nVar之间的随机整数,突变的位置,突变一个或多个元素 Fai0 = myRandom.NextDouble(-1, 1, 10, nVar); //产生[-1, 1]之间随机数行向量 b = 1.0; a = 10.0; it = chrom.CurrentIteration; MaxIt = chrom.MaxIteration; double waveNum = 3; //sm = 1.0 / 3.0 * Math.Atan(a * Math.Pow((1.0 - 2.0 * (it/ MaxIt)), b)) + 0.5;//% 数 ,3 * it决定有3个波段 sm = 1.0 / 3.0 * Math.Atan(a * Math.Pow(1.0 - 2.0 * (((waveNum * it) % MaxIt) / MaxIt), b)) + 0.5;//% 数 ,3 * it决定有3个波段 for (int i = 0; i < muLocation.Length; i++) { for (int j = 0; j < nVar; j++) { if (muLocation[i] == j) { //chromosomeTemp[i] = chrom.chromosome[i] + 0.5 * sm * Fai0[i]* (chrom.UpperBd[i] - chrom.LowerBd[i]);// 0.5 *[1, 0] *[-1, 1] *[区间长度]; chromTemp.chromosome[i] = chrom.chromosome[i] + 0.5 * sm * Fai0[i] * (chrom.UpperBd[i] - chrom.LowerBd[i]);// 0.5 *[1, 0] *[-1, 1] *[区间长度]; } //chrom.chromosome[i] = chromosomeTemp[i];// } } chromTemp.Fit = double.MaxValue; chromTemp.CheckBoundary(); chromTemp.SetChromDecimalPlace(); return(chromTemp); }//DRM
/// <summary> /// 2. Simplex crossover:Da Ronco C C, Benini E. GeDEA-II: A simplex crossover based evolutionary algorithm /// including the genetic diversity as objective[J]. Engineering Letters, 2013, 21(1): 23-35. /// </summary> /// <param name="mom">parnet 1</param> /// <param name="dad">parent 2</param> /// <returns>two children</returns> public List <Chromosome> CrossOver_SPX(Chromosome mom, Chromosome dad) { List <Chromosome> result = new List <Chromosome>(); Chromosome child1 = Chromosome.Clone <Chromosome>(mom); //use this method doing deep copy Chromosome child2 = Chromosome.Clone <Chromosome>(dad); double Refl = myRandom.NextDouble(0, 0.5); //Generates a uniform random number between 0 and 0.5 double Refl2 = myRandom.NextDouble(0.5, 1); double n = 2.0; double M; if (mom.Fit < dad.Fit) { for (int i = 0; i < mom.ChromosomeSize; i++) { M = mom.chromosome[i] / n; child1.chromosome[i] = (1 + Refl) * M - Refl * dad.chromosome[i]; child2.chromosome[i] = (1 + Refl2) * M - Refl2 * dad.chromosome[i]; } } else { for (int i = 0; i < mom.ChromosomeSize; i++) { M = dad.chromosome[i] / n; child1.chromosome[i] = (1 + Refl) * M - Refl * mom.chromosome[i]; child2.chromosome[i] = (1 + Refl2) * M - Refl2 * mom.chromosome[i]; } } child1.Fit = double.MaxValue;//Fit need re-compute,so here give a great value child2.Fit = double.MaxValue; child1.CheckBoundary(); child1.SetChromDecimalPlace(); child2.CheckBoundary(); child2.SetChromDecimalPlace(); result.Add(child1); result.Add(child2); return(result); }
/// <summary> /// 1. Simulate binary crossover operator /// </summary> /// <param name="mom">parent 1</param> /// <param name="dad">parent 2</param> /// <returns>two children</returns> public List <Chromosome> CrossOver_SBX(Chromosome mom, Chromosome dad) { List <Chromosome> result = new List <Chromosome>(); //if (mom == dad) // Debug.WriteLine("Oh shet! are the mom and dad same!?"); //Chromosome child1 = (Chromosome)DeepClone(mom);//This method doesn't work //Chromosome child2 = (Chromosome)DeepClone(dad); Chromosome child1 = Chromosome.Clone <Chromosome>(mom);//use this method doing deep copy Chromosome child2 = Chromosome.Clone <Chromosome>(dad); double EPS = 1E-14; double etaC = mom.CurrentIteration / mom.MaxIteration * 5.0; //etaC=2~5 Random ran = new Random(Guid.NewGuid().GetHashCode()); //http://www.splaybow.com/post/csharp-generate-random-num.html double y1, y2, yl, yu, rnd, beta, alpha, betaq, c1, c2; for (int qq = 0; qq < mom.chromosome.Length; qq++) { if (ran.NextDouble() < 0.5) { if (Math.Abs(mom.chromosome[qq] - dad.chromosome[qq]) > EPS) { if (mom.chromosome[qq] < dad.chromosome[qq]) { y1 = mom.chromosome[qq]; y2 = dad.chromosome[qq]; } else { y1 = dad.chromosome[qq]; y2 = mom.chromosome[qq]; } yl = mom.LowerBd[qq]; yu = mom.UpperBd[qq]; rnd = ran.NextDouble(); beta = 1.0 + (2.0 * (y1 - yl) / (y2 - y1)); alpha = 2.0 - Math.Pow(beta, (-(etaC + 1.0))); if (rnd <= (1.0 / alpha)) { betaq = Math.Pow((rnd * alpha), (1.0 / (etaC + 1.0))); } else { betaq = Math.Pow((1.0 / (2.0 - rnd * alpha)), (1.0 / (etaC + 1.0))); } c1 = 0.5 * ((y1 + y2) - betaq * (y2 - y1)); beta = 1.0 + (2.0 * (yu - y2) / (y2 - y1)); alpha = 2.0 - Math.Pow(beta, (-(etaC + 1.0))); if (rnd <= (1.0 / alpha)) { betaq = Math.Pow((rnd * alpha), (1.0 / (etaC + 1.0))); } else { betaq = Math.Pow((1.0 / (2.0 - rnd * alpha)), (1.0 / (etaC + 1.0))); } c2 = 0.5 * ((y1 + y2) + betaq * (y2 - y1)); if (c1 < yl) { c1 = yl; } if (c2 < yl) { c2 = yl; } if (c1 > yu) { c1 = yu; } if (c2 > yu) { c2 = yu; } if (ran.NextDouble() <= 0.5) { child1.chromosome[qq] = c2; child2.chromosome[qq] = c1; } else { child1.chromosome[qq] = c1; child2.chromosome[qq] = c2; } } else { child1.chromosome[qq] = mom.chromosome[qq]; child2.chromosome[qq] = dad.chromosome[qq]; } } else { child1.chromosome[qq] = mom.chromosome[qq]; child2.chromosome[qq] = dad.chromosome[qq]; } } child1.Fit = double.MaxValue;//Fit need re-compute,so here give a great value child2.Fit = double.MaxValue; //child1.CheckBoundary(); child1.SetChromDecimalPlace(); //child2.CheckBoundary(); child2.SetChromDecimalPlace(); result.Add(child1); result.Add(child2); return(result); }
public Chromosome ChaoticLS(Chromosome chrom) //Jia D , Zheng G , Khan M K . An effective memetic differential evolution algorithm based on chaotic local search[J]. Information ences, 2011, 181(15):3175-3187. { Chromosome betterChrom = Chromosome.Clone <Chromosome>(chrom); //use this method doing deep copy double beta = myRandom.NextDouble(0.0, 1.0); double u = 4.0, m = 1000; double betac, lambda; int Sl = (int)Math.Round(chrom.ChromosomeSize / 5.0); if (Sl < 1) { Sl = 1; } int[] loc = myRandom.NextUnique(0, chrom.ChromosomeSize - 1, Sl); //Random ran = new Random(Guid.NewGuid().GetHashCode()); while (true) { if (beta != 0.25 && beta != 0.5 && beta != 0.75) { break; } beta = myRandom.NextDouble(0.0, 1.0); } for (int i = 0; i < chrom.PopulationSize * 5; i++) { beta = u * beta * (1 - beta); foreach (var j in loc) { betac = chrom.LowerBd[j] + beta * (chrom.UpperBd[j] - chrom.LowerBd[j]); if (chrom.Fit > 0.0) { lambda = 1 - Math.Pow(Math.Abs((chrom.Fit - 1) / chrom.Fit), m); } else { lambda = 1 - Math.Pow(Math.Abs((chrom.Fit + 1) / chrom.Fit), m); } betterChrom.chromosome[j] = (1 - lambda) * chrom.chromosome[j] + lambda * betac; } betterChrom.CheckBoundary(); betterChrom.SetChromDecimalPlace(); betterChrom.SolveFitness(); if (betterChrom.Fit < chrom.Fit) { //Console.WriteLine("local search find a better individuals!"); break; } } if (betterChrom.Fit < chrom.Fit) { return(betterChrom); } else { return(chrom); } }