public override IEnumerable<IndividualBase> Execute()
        {
            //Initialize Population + Evaluate Objective Values
            Population = new Population_MultiObjective_AG(Problem, InitialPopulationSize);
            Population.RandomInitialize();

            // Assign Rank Based on Pareto Dominance
            FastNonDominatedSort(Population);

            // Assign Crowding Distance for the Population
            CrowdingDistanceAssignment(Population.Content);

            // Creates Offspring through Selection, Recombination, and Mutation
            Population_MultiObjective_AG childPopulation = Procreate(Population);

            Population_MultiObjective_AG Pnext = Population;
            Population_MultiObjective_AG Qnext = childPopulation;

            Population_MultiObjective_AG currentGeneration = new Population_MultiObjective_AG(Problem, 2 * InitialPopulationSize);
            currentGeneration.AddPopulation(Pnext);
            currentGeneration.AddPopulation(Qnext);

            for (int idxGeracao = 1; idxGeracao < NumberOfGenerations; ++idxGeracao) {
                Pnext = RunGeneration(currentGeneration);
                Qnext = Procreate(Pnext);

                currentGeneration = new Population_MultiObjective_AG(Problem, 2 * InitialPopulationSize);
                currentGeneration.AddPopulation(Pnext);
                currentGeneration.AddPopulation(Qnext);
            }
            return FastNonDominatedSort(currentGeneration).First().Content;
        }
        public override IEnumerable <IndividualBase> Execute()
        {
            //Initialize Population + Evaluate Objective Values
            Population = new Population_MultiObjective_AG(Problem, InitialPopulationSize);
            Population.RandomInitialize();

            // Assign Rank Based on Pareto Dominance
            FastNonDominatedSort(Population);

            // Assign Crowding Distance for the Population
            CrowdingDistanceAssignment(Population.Content);

            // Creates Offspring through Selection, Recombination, and Mutation
            Population_MultiObjective_AG childPopulation = Procreate(Population);

            Population_MultiObjective_AG Pnext = Population;
            Population_MultiObjective_AG Qnext = childPopulation;

            Population_MultiObjective_AG currentGeneration = new Population_MultiObjective_AG(Problem, 2 * InitialPopulationSize);

            currentGeneration.AddPopulation(Pnext);
            currentGeneration.AddPopulation(Qnext);

            for (int idxGeracao = 1; idxGeracao < NumberOfGenerations; ++idxGeracao)
            {
                Pnext = RunGeneration(currentGeneration);
                Qnext = Procreate(Pnext);

                currentGeneration = new Population_MultiObjective_AG(Problem, 2 * InitialPopulationSize);
                currentGeneration.AddPopulation(Pnext);
                currentGeneration.AddPopulation(Qnext);
            }
            return(FastNonDominatedSort(currentGeneration).First().Content);
        }
        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);
        }
        private IndividualBase BinaryTournment(Population_MultiObjective_AG population)
        {
            IndividualBase[] contestants = new IndividualBase[2];

            contestants[0] = population.GetRandomIndividual();
            do
            {
                contestants[1] = population.GetRandomIndividual();
            } while (contestants[0] == contestants[1]);

            return(BestByCrowdedComparison(contestants[0], contestants[1]));
        }
        protected override Population_MultiObjective_AG RunGeneration(Population_MultiObjective_AG currentGeneration)
        {
            List<Population_MultiObjective_AG> fronts = FastNonDominatedSort(currentGeneration);

            Population_MultiObjective_AG Pnext = new Population_MultiObjective_AG(Problem, InitialPopulationSize);
            int i = 0;
            while ((Pnext.IndividualCount + fronts[i].IndividualCount) < InitialPopulationSize) {
                CrowdingDistanceAssignment(fronts[i].Content);
                Pnext.AddPopulation(fronts[i]);
                i++;
            }
            fronts[i].Content.Sort(CrowdedComparison);
            fronts[i].Content.Reverse();
            Pnext.AddRange(fronts[i].Content.Take(InitialPopulationSize - Pnext.IndividualCount));
            return Pnext;
        }
Exemple #6
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);
        }
        protected override Population_MultiObjective_AG RunGeneration(Population_MultiObjective_AG currentGeneration)
        {
            List <Population_MultiObjective_AG> fronts = FastNonDominatedSort(currentGeneration);

            Population_MultiObjective_AG Pnext = new Population_MultiObjective_AG(Problem, InitialPopulationSize);
            int i = 0;

            while ((Pnext.IndividualCount + fronts[i].IndividualCount) < InitialPopulationSize)
            {
                CrowdingDistanceAssignment(fronts[i].Content);
                Pnext.AddPopulation(fronts[i]);
                i++;
            }
            fronts[i].Content.Sort(CrowdedComparison);
            fronts[i].Content.Reverse();
            Pnext.AddRange(fronts[i].Content.Take(InitialPopulationSize - Pnext.IndividualCount));
            return(Pnext);
        }
Exemple #8
0
        private IndividualBase BinaryTournment(Population_MultiObjective_AG population)
        {
            IndividualBase[] contestants = new IndividualBase[2];

            contestants[0] = population.GetRandomIndividual();
            for (int i = 0; i < 10; ++i)
            {
                contestants[1] = population.GetRandomIndividual();
                if ((contestants[0] != contestants[1]) || i == 9)
                {
                    break;
                }
            }
            //do {
            //    contestants[1] = population.GetRandomIndividual();
            //} while (contestants[0] == contestants[1]);

            return(finalFitnessComparison(contestants[0], contestants[1]) >= 0 ? contestants[0] : contestants[1]);
        }
        public override IEnumerable<IndividualBase> Execute()
        {
            //Inicializacao
            Population = new Population_MultiObjective_AG(Problem, InitialPopulationSize);
            Population.RandomInitialize();

            Archive = new Population_MultiObjective_AG(Problem, ArchivePopulationSize);

            Population_MultiObjective_AG currentGeneration = Population;
            Population_MultiObjective_AG newGeneration = null;

            for (int idxGeracao = 0; idxGeracao < NumberOfGenerations; ++idxGeracao) {
                newGeneration = RunGeneration(currentGeneration);
                currentGeneration = newGeneration;
            }

            IEnumerable<IndividualBase> nonDominatedFront = currentGeneration.FastNonDominatedSort().First().Content;
            IEnumerable<IndividualBase> firstItemsByMakeSpan = (from i in nonDominatedFront.Cast<TaskSchedulingSolution>()
                                                               group i by i.MakeSpan into g
                                                               select g.First()).OrderBy(I => I.MakeSpan);

            return firstItemsByMakeSpan;
        }
Exemple #10
0
        public override IEnumerable <IndividualBase> Execute()
        {
            //Inicializacao
            Population = new Population_MultiObjective_AG(Problem, InitialPopulationSize);
            Population.RandomInitialize();

            Archive = new Population_MultiObjective_AG(Problem, ArchivePopulationSize);

            Population_MultiObjective_AG currentGeneration = Population;
            Population_MultiObjective_AG newGeneration     = null;

            for (int idxGeracao = 0; idxGeracao < NumberOfGenerations; ++idxGeracao)
            {
                newGeneration     = RunGeneration(currentGeneration);
                currentGeneration = newGeneration;
            }

            IEnumerable <IndividualBase> nonDominatedFront    = currentGeneration.FastNonDominatedSort().First().Content;
            IEnumerable <IndividualBase> firstItemsByMakeSpan = (from i in nonDominatedFront.Cast <TaskSchedulingSolution>()
                                                                 group i by i.MakeSpan into g
                                                                 select g.First()).OrderBy(I => I.MakeSpan);

            return(firstItemsByMakeSpan);
        }
        protected override Population_MultiObjective_AG RunGeneration(Population_MultiObjective_AG currentGeneration)
        {
            Population_MultiObjective_AG everyone = new Population_MultiObjective_AG(Problem, InitialPopulationSize + ArchivePopulationSize);
            everyone.AddPopulation(currentGeneration);
            everyone.AddPopulation(Archive);

            #region Fitness Assignment
            // The Strength of an Individual is the Count of those he Dominates
            foreach (IndividualBase individual in everyone.Content) {
                individual.Strength = everyone.Content.Where(I => !I.Equals(individual)).Count(I => individual.Dominates(I));
            }

            // The RawFitness of an Individual is the sum of the strengths of all those who Dominate him
            foreach (IndividualBase individual in everyone.Content) {
                individual.RawFitness = everyone.Content.Where(I => I.Dominates(individual)).Sum(D => D.Strength);
            }

            // The True Fitness is Calculated
            everyone.CalculateSortedDistances();
            int k = (int)Math.Sqrt(InitialPopulationSize + ArchivePopulationSize);
            foreach (IndividualBase i in everyone.Content) {
                double distanceSought = i.DistancesToOtherIndividuals[k].Item2;
                double density = (1 / (distanceSought + 2));
                i.FinalFitness = i.RawFitness + density;
            }
            #endregion

            #region Environment Selection
            Population_MultiObjective_AG nextArchive = new Population_MultiObjective_AG(Problem, ArchivePopulationSize);
            List<IndividualBase> excludeList = new List<IndividualBase>();

            //insere em nextArchive todos os elementos da populacao total com finalFitness < 1
            //poderia ser tambem rawFitness = 0, mas no artigo especifica o dito acima, podemos seguir
            //aproveitar pra remover do total os elementos inseridos, vai facilitar no proximo passo..
            IEnumerable<IndividualBase> nonDominatedSolutions = everyone.Content.Where(I => I.FinalFitness < 1);
            nextArchive.AddRange(nonDominatedSolutions);
            everyone.Content.RemoveAll(I => nonDominatedSolutions.Contains(I));

            if (nextArchive.IndividualCount < ArchivePopulationSize) {
                everyone.Content.Sort(finalFitnessComparison);

                //TODO: Confirmar se é melhor maior ou menor, esse reverse faz pegar os menores
                everyone.Content.Reverse();

                IEnumerable<IndividualBase> complement = everyone.Content.Take(ArchivePopulationSize - nextArchive.IndividualCount);
                nextArchive.AddRange(complement);
            }
            else if(nextArchive.IndividualCount > ArchivePopulationSize) {
                //trunca a população pela distancia
                nextArchive.Truncate(ArchivePopulationSize);
            }

            //acho que não vai precisar do antigo mais.. conferir !
            this.Archive = nextArchive;
            #endregion

            #region Mating Selection
            //Seleção dos Pais da proxima populacao, leva em conta apenas archive
            Population_MultiObjective_AG matingPool = Procreate(nextArchive);
            #endregion

            return matingPool;
        }
        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;
        }
        private IndividualBase BinaryTournment(Population_MultiObjective_AG population)
        {
            IndividualBase[] contestants = new IndividualBase[2];

            contestants[0] = population.GetRandomIndividual();
            for (int i = 0; i < 10; ++i) {
                contestants[1] = population.GetRandomIndividual();
                if ((contestants[0] != contestants[1]) || i == 9) {
                    break;
                }
            }
            //do {
            //    contestants[1] = population.GetRandomIndividual();
            //} while (contestants[0] == contestants[1]);

            return finalFitnessComparison(contestants[0], contestants[1]) >= 0 ? contestants[0] : contestants[1];
        }
 public abstract Population_MultiObjective_AG Execute(Population_MultiObjective_AG lastGeneration, Population_MultiObjective_AG generatedChildren);
        private static IEnumerable<IndividualBase> SPEA2MultiExecution(int executionCount, ProblemBase problem, int populationSize)
        {
            MultiObjectiveGeneticAlgorithm SPEA2 = new NSGA2(
               problem,
               populationSize,
               200,
               200,
               10);

            Population_MultiObjective_AG Aggregator = new Population_MultiObjective_AG(problem);

            for (int i = 0; i < executionCount; ++i) {
                IEnumerable<IndividualBase> executionResult = SPEA2.Execute();
                Aggregator.AddRange(executionResult);
            }

            IEnumerable<IndividualBase> nonDominatedFront = Aggregator.FastNonDominatedSort().First().Content;
            IEnumerable<IndividualBase> firstItemsByMakeSpan = (from i in nonDominatedFront.Cast<TaskSchedulingSolution>()
                                                                group i by i.MakeSpan into g
                                                                select g.First()).OrderBy(I => I.MakeSpan);

            return firstItemsByMakeSpan;
        }
 public abstract Population_MultiObjective_AG Execute(Population_MultiObjective_AG lastGeneration, Population_MultiObjective_AG generatedChildren);
 protected abstract Population_MultiObjective_AG RunGeneration(Population_MultiObjective_AG currentGeneration);
 protected abstract Population_MultiObjective_AG RunGeneration(Population_MultiObjective_AG currentGeneration);
Exemple #19
0
        protected override Population_MultiObjective_AG RunGeneration(Population_MultiObjective_AG currentGeneration)
        {
            Population_MultiObjective_AG everyone = new Population_MultiObjective_AG(Problem, InitialPopulationSize + ArchivePopulationSize);

            everyone.AddPopulation(currentGeneration);
            everyone.AddPopulation(Archive);

            #region Fitness Assignment
            // The Strength of an Individual is the Count of those he Dominates
            foreach (IndividualBase individual in everyone.Content)
            {
                individual.Strength = everyone.Content.Where(I => !I.Equals(individual)).Count(I => individual.Dominates(I));
            }

            // The RawFitness of an Individual is the sum of the strengths of all those who Dominate him
            foreach (IndividualBase individual in everyone.Content)
            {
                individual.RawFitness = everyone.Content.Where(I => I.Dominates(individual)).Sum(D => D.Strength);
            }

            // The True Fitness is Calculated
            everyone.CalculateSortedDistances();
            int k = (int)Math.Sqrt(InitialPopulationSize + ArchivePopulationSize);
            foreach (IndividualBase i in everyone.Content)
            {
                double distanceSought = i.DistancesToOtherIndividuals[k].Item2;
                double density        = (1 / (distanceSought + 2));
                i.FinalFitness = i.RawFitness + density;
            }
            #endregion

            #region Environment Selection
            Population_MultiObjective_AG nextArchive = new Population_MultiObjective_AG(Problem, ArchivePopulationSize);
            List <IndividualBase>        excludeList = new List <IndividualBase>();

            //insere em nextArchive todos os elementos da populacao total com finalFitness < 1
            //poderia ser tambem rawFitness = 0, mas no artigo especifica o dito acima, podemos seguir
            //aproveitar pra remover do total os elementos inseridos, vai facilitar no proximo passo..
            IEnumerable <IndividualBase> nonDominatedSolutions = everyone.Content.Where(I => I.FinalFitness < 1);
            nextArchive.AddRange(nonDominatedSolutions);
            everyone.Content.RemoveAll(I => nonDominatedSolutions.Contains(I));

            if (nextArchive.IndividualCount < ArchivePopulationSize)
            {
                everyone.Content.Sort(finalFitnessComparison);

                //TODO: Confirmar se é melhor maior ou menor, esse reverse faz pegar os menores
                everyone.Content.Reverse();

                IEnumerable <IndividualBase> complement = everyone.Content.Take(ArchivePopulationSize - nextArchive.IndividualCount);
                nextArchive.AddRange(complement);
            }
            else if (nextArchive.IndividualCount > ArchivePopulationSize)
            {
                //trunca a população pela distancia
                nextArchive.Truncate(ArchivePopulationSize);
            }

            //acho que não vai precisar do antigo mais.. conferir !
            this.Archive = nextArchive;
            #endregion

            #region Mating Selection
            //Seleção dos Pais da proxima populacao, leva em conta apenas archive
            Population_MultiObjective_AG matingPool = Procreate(nextArchive);
            #endregion

            return(matingPool);
        }
        private IndividualBase BinaryTournment(Population_MultiObjective_AG population)
        {
            IndividualBase[] contestants = new IndividualBase[2];

            contestants[0] = population.GetRandomIndividual();
            do {
                contestants[1] = population.GetRandomIndividual();
            } while (contestants[0] == contestants[1]);

            return BestByCrowdedComparison(contestants[0], contestants[1]);
        }
        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;
        }