예제 #1
0
        private Population_MultiObjective_AG Procreate(Population_MultiObjective_AG mating)
        {
            int expectedChildCount = InitialPopulationSize;

            Population_MultiObjective_AG newGeneration = new Population_MultiObjective_AG(Problem, expectedChildCount);

            while (newGeneration.IndividualCount < expectedChildCount)
            {
                // Selection Method
                IndividualBase parent1 = BinaryTournment(mating);
                IndividualBase parent2 = BinaryTournment(mating);
                IndividualBase child1 = null, child2 = null;

                // Crossover Method
                Problem.PMXCrossover(parent1, parent2, out child1, out child2);
                for (int i = 0; i < 10; ++i)
                {
                    if (!newGeneration.Content.Contains(child1) || i == 9)
                    {
                        newGeneration.AddIndividual(child1);
                        break;
                    }
                }
                for (int i = 0; i < 10; ++i)
                {
                    if (!newGeneration.Content.Contains(child2) || i == 9)
                    {
                        newGeneration.AddIndividual(child2);
                        break;
                    }
                }
            }

            foreach (IndividualBase individual in newGeneration.Content)
            {
                int aleatoryPercentage = Aleatoriety.GetRandomInt(100);
                if (aleatoryPercentage < mutationPct)
                {
                    Problem.MutateIndividual(individual);
                }
                Problem.ValidateIndividual(individual);
                IndividualEvaluator.Execute(individual, Problem);
            }
            return(newGeneration);
        }
        public List <Population_MultiObjective_AG> FastNonDominatedSort()
        {
            List <Population_MultiObjective_AG> Fronts = new List <Population_MultiObjective_AG>();

            Population_MultiObjective_AG NonDominatedFront = new Population_MultiObjective_AG(Problem);

            foreach (IndividualBase individual in Content)
            {
                individual.DominatesList    = new List <IndividualBase>();
                individual.DominatedByCount = 0;

                foreach (IndividualBase another in Content.Where(I => !I.Equals(individual)))
                {
                    if (individual.Dominates(another))
                    {
                        individual.DominatesList.Add(another);  // Lista dos elementos que sao dominados
                    }
                    else if (another.Dominates(individual))
                    {
                        individual.DominatedByCount++; // O atributo np nao foi implementado ainda, se refere a qnt de elementos q o dominam
                    }
                }
                if (individual.DominatedByCount == 0)
                {
                    individual.NonDominationRank = 1;
                    NonDominatedFront.AddIndividual(individual);
                }
            }
            int NonDominationRank = 2;
            Population_MultiObjective_AG CurrentFront = NonDominatedFront;
            Population_MultiObjective_AG FrontQ       = NonDominatedFront;

            do
            {
                Fronts.Add(FrontQ);
                FrontQ = new Population_MultiObjective_AG(Problem);
                foreach (IndividualBase individual in CurrentFront.Content)
                {
                    foreach (IndividualBase dominatedIndividual in individual.DominatesList)
                    {
                        dominatedIndividual.DominatedByCount--;
                        if (dominatedIndividual.DominatedByCount == 0)
                        {
                            dominatedIndividual.NonDominationRank = NonDominationRank;
                            FrontQ.AddIndividual(dominatedIndividual);
                        }
                    }
                }
                CurrentFront = FrontQ;
                NonDominationRank++;
            } while (FrontQ.IndividualCount != 0);
            return(Fronts);
        }
예제 #3
0
        private Population_MultiObjective_AG Procreate(Population_MultiObjective_AG mating)
        {
            int expectedChildCount = InitialPopulationSize;

            Population_MultiObjective_AG newGeneration = new Population_MultiObjective_AG(Problem, expectedChildCount);
            while(newGeneration.IndividualCount < expectedChildCount) {
                // Selection Method
                IndividualBase parent1 = BinaryTournment(mating);
                IndividualBase parent2 = BinaryTournment(mating);
                IndividualBase child1 = null, child2 = null;

                // Crossover Method
                Problem.PMXCrossover(parent1, parent2, out child1, out child2);
                for (int i = 0; i < 10; ++i) {
                    if (!newGeneration.Content.Contains(child1) || i == 9) {
                        newGeneration.AddIndividual(child1);
                        break;
                    }
                }
                for (int i = 0; i < 10; ++i) {
                    if (!newGeneration.Content.Contains(child2) || i == 9) {
                        newGeneration.AddIndividual(child2);
                        break;
                    }
                }
            }

            foreach (IndividualBase individual in newGeneration.Content) {
                int aleatoryPercentage = Aleatoriety.GetRandomInt(100);
                if (aleatoryPercentage < mutationPct)
                    Problem.MutateIndividual(individual);
                Problem.ValidateIndividual(individual);
                IndividualEvaluator.Execute(individual, Problem);
            }
            return newGeneration;
        }
        public List<Population_MultiObjective_AG> FastNonDominatedSort()
        {
            List<Population_MultiObjective_AG> Fronts = new List<Population_MultiObjective_AG>();

            Population_MultiObjective_AG NonDominatedFront = new Population_MultiObjective_AG(Problem);
            foreach (IndividualBase individual in Content) {
                individual.DominatesList = new List<IndividualBase>();
                individual.DominatedByCount = 0;

                foreach (IndividualBase another in Content.Where(I => !I.Equals(individual))) {
                    if (individual.Dominates(another)) {
                        individual.DominatesList.Add(another);  // Lista dos elementos que sao dominados
                    }
                    else if (another.Dominates(individual)) {
                        individual.DominatedByCount++; // O atributo np nao foi implementado ainda, se refere a qnt de elementos q o dominam
                    }
                }
                if (individual.DominatedByCount == 0) {
                    individual.NonDominationRank = 1;
                    NonDominatedFront.AddIndividual(individual);
                }
            }
            int NonDominationRank = 2;
            Population_MultiObjective_AG CurrentFront = NonDominatedFront;
            Population_MultiObjective_AG FrontQ = NonDominatedFront;
            do {
                Fronts.Add(FrontQ);
                FrontQ = new Population_MultiObjective_AG(Problem);
                foreach (IndividualBase individual in CurrentFront.Content) {
                    foreach (IndividualBase dominatedIndividual in individual.DominatesList) {
                        dominatedIndividual.DominatedByCount--;
                        if (dominatedIndividual.DominatedByCount == 0) {
                            dominatedIndividual.NonDominationRank = NonDominationRank;
                            FrontQ.AddIndividual(dominatedIndividual);
                        }
                    }
                }
                CurrentFront = FrontQ;
                NonDominationRank++;
            } while (FrontQ.IndividualCount != 0);
            return Fronts;
        }