示例#1
0
        protected MoChromosome GeneticOPDE(int pos, int i)
        {//Differential Evolution
            int k, l;

            MoChromosome chromosome1;
            MoChromosome chromosome2;

            if (Pop[pos].Count < 4)
            {
                do
                {
                    k = random.Next(0, popsize - 1);
                }while (k == i);
                do
                {
                    l = random.Next(0, popsize - 1);
                }while (l == k || l == i);

                chromosome1 = mainpop[k];
                chromosome2 = mainpop[l];
            }
            else
            {
                do
                {
                    k = random.Next(0, Pop[pos].Count);
                }while (k == i);
                do
                {
                    l = random.Next(0, Pop[pos].Count);
                }while (l == k || l == i);

                chromosome1 = Pop[pos][k];
                chromosome2 = Pop[pos][l];
            }

            // generic operation crossover and mutation.
            MoChromosome offSpring = this.CreateChromosome();
            MoChromosome current   = Pop[pos][i];

            offSpring.DECrossover(current, chromosome1, chromosome2, random);

            offSpring.Mutate(1d / offSpring.parDimension, random);
            return(offSpring);
        }
        /// <summary>
        /// Differential Evolution based approach to generate offspring
        /// </summary>
        /// <param name="idx">the index of individual</param>
        /// <param name="flag"></param>
        /// <returns></returns>
        protected MoChromosome DECrossover(int i, Boolean flag = false)
        {
            int k, l;

            if (true == flag && random.NextDouble() < 0.5)
            {
                do
                {
                    k = neighbourTable[i][random.Next(this.neighbourSize)];
                }while (k == i);
                do
                {
                    l = neighbourTable[i][random.Next(this.neighbourSize)];
                }while (l == k || l == i);
            }
            else
            {
                do
                {
                    k = random.Next(0, popsize - 1);
                }while (k == i);
                do
                {
                    l = random.Next(0, popsize - 1);
                }while (l == k || l == i);
            }



            MoChromosome chromosome1 = mainpop[k];
            MoChromosome chromosome2 = mainpop[l];

            // generic operation crossover and mutation.
            MoChromosome offSpring = this.CreateChromosome();
            MoChromosome current   = mainpop[i];

            offSpring.DECrossover(current, chromosome1, chromosome2, random);

            offSpring.Mutate(1d / offSpring.parDimension, random);
            return(offSpring);
        }