Beispiel #1
0
        private void DoMutation(Individual_NSGA individual)
        {
            double rnd, delta1, delta2, mut_pow, deltaq;
            double y, yl, yu, val, xy;

            Individual_NSGA x = new Individual_NSGA(individual);

            for (int var = 0; var < individual.N_gens; var++)
            {
                if (m_Random.NextDouble() <= mutationProb)
                {
                    y       = x.Values[var];
                    yl      = x.GetLowerBound();
                    yu      = x.GetUpperBound();
                    delta1  = (y - yl) / (yu - yl);
                    delta2  = (yu - y) / (yu - yl);
                    rnd     = m_Random.NextDouble();
                    mut_pow = 1.0 / (eta_m + 1.0);
                    if (rnd <= 0.5)
                    {
                        xy     = 1.0 - delta1;
                        val    = 2.0 * rnd + (1.0 - 2.0 * rnd) * (Math.Pow(xy, (distributionIndex + 1.0)));
                        deltaq = Math.Pow(val, mut_pow) - 1.0;
                    }
                    else
                    {
                        xy     = 1.0 - delta2;
                        val    = 2.0 * (1.0 - rnd) + 2.0 * (rnd - 0.5) * (Math.Pow(xy, (distributionIndex + 1.0)));
                        deltaq = 1.0 - (Math.Pow(val, mut_pow));
                    }
                    y = y + deltaq * (yu - yl);
                    if (y < yl)
                    {
                        y = yl;
                    }
                    if (y > yu)
                    {
                        y = yu;
                    }
                    x.Values[var] = y;
                    //x.SetValue(var, y);
                }
            }
        }
Beispiel #2
0
        private Individual_NSGA[] DoCrossover(double crossoverProbability, Individual_NSGA parent1, Individual_NSGA parent2)
        {
            Individual_NSGA[] offSpring = new Individual_NSGA[2];

            offSpring[0] = new Individual_NSGA(parent1);
            offSpring[1] = new Individual_NSGA(parent2);

            int             i;
            double          rand;
            double          y1, y2, yL, yu;
            double          c1, c2;
            double          alpha, beta, betaq;
            double          valueX1, valueX2;
            Individual_NSGA x1    = new Individual_NSGA(parent1);
            Individual_NSGA x2    = new Individual_NSGA(parent2);
            Individual_NSGA offs1 = new Individual_NSGA(offSpring[0]);
            Individual_NSGA offs2 = new Individual_NSGA(offSpring[1]);

            int numberOfVariables = x1.N_gens;

            if (m_Random.NextDouble() <= crossoverProbability)
            {
                for (i = 0; i < numberOfVariables; i++)
                {
                    valueX1 = x1.Values[i];
                    valueX2 = x2.Values[i];
                    if (m_Random.NextDouble() <= 0.5)
                    {
                        if (Math.Abs(valueX1 - valueX2) > EPS)
                        {
                            if (valueX1 < valueX2)
                            {
                                y1 = valueX1;
                                y2 = valueX2;
                            }
                            else
                            {
                                y1 = valueX2;
                                y2 = valueX1;
                            }

                            yL = x1.GetLowerBound(); //lowerBound
                            yu = x1.GetUpperBound(); //upperBound

                            rand  = m_Random.NextDouble();
                            beta  = 1.0 + (2.0 * (y1 - yL) / (y2 - y1));
                            alpha = 2.0 - Math.Pow(beta, -(distributionIndex + 1.0));

                            if (rand <= (1.0 / alpha))
                            {
                                betaq = Math.Pow((rand * alpha), (1.0 / (distributionIndex + 1.0)));
                            }
                            else
                            {
                                betaq = Math.Pow((1.0 / (2.0 - rand * alpha)), (1.0 / (distributionIndex + 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, -(distributionIndex + 1.0));

                            if (rand <= (1.0 / alpha))
                            {
                                betaq = Math.Pow((rand * alpha), (1.0 / (distributionIndex + 1.0)));
                            }
                            else
                            {
                                betaq = Math.Pow((1.0 / (2.0 - rand * alpha)), (1.0 / (distributionIndex + 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 (m_Random.NextDouble() <= 0.5)
                            {
                                offs1.Values[i] = c2;
                                offs2.Values[i] = c1;
                                //offs1.SetValue(i, c2);
                                //offs2.SetValue(i, c1);
                            }
                            else
                            {
                                offs1.Values[i] = c1;
                                offs2.Values[i] = c2;
                                //offs1.SetValue(i, c1);
                                //offs2.SetValue(i, c2);
                            }
                        }
                        else
                        {
                            offs1.Values[i] = valueX1;
                            offs2.Values[i] = valueX2;
                            //offs1.SetValue(i, valueX1);
                            //offs2.SetValue(i, valueX2);
                        }
                    }
                    else
                    {
                        offs1.Values[i] = valueX2;
                        offs2.Values[i] = valueX1;
                        //offs1.SetValue(i, valueX2);
                        //offs2.SetValue(i, valueX1);
                    }
                }
            }

            return(offSpring);
        }