コード例 #1
0
        public Population(int size, GH_ParameterHandler _ghHandler)
        {
            populationSize = size;
            ghHandler      = _ghHandler;

            nonDominatedFront = new List <Individual>();
            fronts            = new List <List <Individual> >();

            population = new List <Individual>();

            for (int i = 0; i < populationSize; i++)
            {
                Individual individual = new Individual(ghHandler);
                individual.fitnesses = ghHandler.GetFitnessValues();
                population.Add(individual);
            }
        }
コード例 #2
0
ファイル: Individual.cs プロジェクト: sofia-feist/NSGA_II
 public Individual(GH_ParameterHandler _ghHandler)
 {
     ghHandler = _ghHandler;
     genes     = ghHandler.GetSetGeneValues();
 }
コード例 #3
0
        ////////////////////////////////////////////////////////////////////////
        ////////////////////////    NSGA-II Algorithm   ////////////////////////
        ////////////////////////////////////////////////////////////////////////

        // REFERENCES:
        // Deb, K., Pratap, A., Agarwal, S., & Meyarivan, T. A. M. T. (2002).
        // A fast and elitist multiobjective genetic algorithm: NSGA-II.
        // IEEE transactions on evolutionary computation, 6(2), pp. 182-197.
        // &
        // http://www.cleveralgorithms.com/nature-inspired/evolution/nsga.html
        public static void NSGAII(object sender, DoWorkEventArgs e)
        {
            // Initialize Archive Lists
            archive       = new List <Individual>();
            paretoHistory = new List <Individual>();

            // Create Parameter Handler
            var component = e.Argument as NSGAII_GHComponent;
            var GhHandler = new GH_ParameterHandler(component);



            // START OPTIMIZATION
            stopWatch.Start();

            Population pop = new Population(PopulationSize, GhHandler);

            pop.FastNonDominatedSort();

            while (StopCondition())
            {
                var offspring = pop.Offspring();
                pop.population.AddRange(offspring);
                pop.FastNonDominatedSort();

                // Selection of the Next Generation by Rank and Crowding Distance
                var newGeneration = new List <Individual>();

                foreach (var front in pop.fronts)
                {
                    pop.CrowdingDistance(front);
                    var orderedFront = front.OrderBy(p => p.rank).ThenByDescending(p => p.crowdingDistance).ToList();

                    if (newGeneration.Count + front.Count > PopulationSize)
                    {
                        for (int j = newGeneration.Count; j < PopulationSize; j++)
                        {
                            newGeneration.Add(orderedFront[j - newGeneration.Count]);
                        }
                        break;
                    }
                    else
                    {
                        newGeneration.AddRange(orderedFront);
                    }
                }

                pop.population = newGeneration;
                currentGeneration++;


                // UPDATE BACKGROUNDWORKER THREAD
                // Check for cancellation
                if (NSGAII_Editor.backgroundWorker.CancellationPending)
                {
                    break;
                }

                // Report Progress
                NSGAII_Editor.backgroundWorker.ReportProgress(50);


                // UPDATE ARCHIVE LISTS
                archive.AddRange(pop.population);
                currentParetoFront = pop.fronts[0];
                currentPopulation  = pop.population;
                paretoHistory.AddRange(pop.fronts[0]);
            }

            stopWatch.Stop();
        }