public override bool Mutate(List <double> solution)
        {
            bool successfulMutation = false;

            for (int i = 0; i < solution.Count; ++i)
            {
                if (uniformRNG.Next(Probability))
                {
                    // Poprawiono kod, ponieważ w poprzednim stanie nie był sprawdzany zakres przez co zdarza sie ze wychodzi poza zakres i nie moze wrocic
                    double tempSolution = 0;
                    int    counter      = 0;
                    do
                    {
                        counter++;
                        tempSolution  = solution[i];
                        tempSolution += gaussianRNG.Next(0.0, sigmas[i]);
                        if (counter > 100)
                        {
                            return(false);
                        }
                    } while (!evaluationProfile.pcConstraint.bIsFeasible(i, tempSolution));
                    solution[i] = tempSolution;
                    //do
                    //{
                    //    solution[i] += gaussianRNG.Next(0.0, sigmas[i]);
                    //} while (!evaluationProfile.pcConstraint.bIsFeasible(i, solution[i]));

                    successfulMutation = true;
                }
            }

            return(successfulMutation);
        }
Esempio n. 2
0
        public bool Crossover <Element>(List <Element> parent1, List <Element> parent2, List <Element> offspring1, List <Element> offspring2)
        {
            if (crossoverRNG.Next(Probability))
            {
                return(Cross(parent1, parent2, offspring1, offspring2));
            }

            return(false);
        }
Esempio n. 3
0
        public override bool Mutate(List <bool> solution)
        {
            bool successfulMutation = false;

            for (int i = 0; i < solution.Count; ++i)
            {
                if (rng.Next(Probability) &&
                    evaluationProfile.pcConstraint.bIsFeasible(i, !solution[i]))
                {
                    solution[i]        = !solution[i];
                    successfulMutation = true;
                }
            }

            return(successfulMutation);
        }
Esempio n. 4
0
        protected override bool Cross <Element>(List <Element> parent1, List <Element> parent2, List <Element> offspring1, List <Element> offspring2)
        {
            for (int i = 0; i < parent1.Count; ++i)
            {
                if (rng.Next())
                {
                    offspring1[i] = parent1[i];
                    offspring2[i] = parent2[i];
                }
                else
                {
                    offspring1[i] = parent2[i];
                    offspring2[i] = parent1[i];
                }
            }

            return(true);
        }
        public override bool Mutate(List <double> solution)
        {
            bool successfulMutation = false;

            for (int i = 0; i < solution.Count; ++i)
            {
                if (uniformRNG.Next(Probability))
                {
                    do
                    {
                        solution[i] += gaussianRNG.Next(0.0, sigmas[i]);
                    } while (!evaluationProfile.pcConstraint.bIsFeasible(i, solution[i]));

                    successfulMutation = true;
                }
            }

            return(successfulMutation);
        }
        public override List <bool> Fill(List <bool> solution)
        {
            bool lowerBound;

            for (int i = 0; i < solution.Capacity; ++i)
            {
                lowerBound = constraint.tGetLowerBound(i);

                solution.Add((lowerBound == constraint.tGetUpperBound(i)) ? lowerBound : rng.Next());
            }

            return(solution);
        }