/// <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
示例#2
0
        /// <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);
        }
示例#3
0
        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);
            }
        }