Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17662 for branches/2825-NSGA3


Ignore:
Timestamp:
07/09/20 16:11:31 (4 years ago)
Author:
dleko
Message:

#2825 Correction: Use NumberOfObjectives instead of Problem.Encoding.Length where it is correct.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2825-NSGA3/HeuristicLab.Algorithms.NSGA3/3.3/NSGA3.cs

    r17661 r17662  
    4343        }
    4444
     45        public int NumberOfObjectives => Problem.Maximization.Length;
     46
    4547        #endregion ProblemProperties
    4648
     
    236238        }
    237239
    238         private void InitReferencePoints()
    239         {
    240             // Generate reference points and add them to results
    241             ReferencePoints = ReferencePoint.GenerateReferencePoints(random, Problem.Maximization.Length);
    242             ResultsGeneratedReferencePoints = Utility.ConvertToDoubleMatrix(ReferencePoints);
    243         }
    244 
    245240        private void InitResults()
    246241        {
    247242            Results.Add(new Result(GeneratedReferencePointsResultName, "The initially generated reference points", new DoubleMatrix()));
    248243            Results.Add(new Result(CurrentFrontResultName, "The Pareto Front", new DoubleMatrix()));
     244        }
     245
     246        private void InitReferencePoints()
     247        {
     248            // Generate reference points and add them to results
     249            ReferencePoints = ReferencePoint.GenerateReferencePoints(random, NumberOfObjectives);
     250            ResultsGeneratedReferencePoints = Utility.ConvertToDoubleMatrix(ReferencePoints);
    249251        }
    250252
     
    343345        {
    344346            // Find the ideal point
    345             double[] idealPoint = new double[Problem.Encoding.Length];
    346             for (int j = 0; j < Problem.Encoding.Length; j++)
     347            double[] idealPoint = new double[NumberOfObjectives];
     348            for (int j = 0; j < NumberOfObjectives; j++)
    347349            {
    348350                // Compute ideal point
     
    355357
    356358            // Find the extreme points
    357             Solution[] extremePoints = new Solution[Problem.Encoding.Length];
    358             for (int j = 0; j < Problem.Encoding.Length; j++)
     359            Solution[] extremePoints = new Solution[NumberOfObjectives];
     360            for (int j = 0; j < NumberOfObjectives; j++)
    359361            {
    360362                // Compute extreme points
    361                 double[] weights = new double[Problem.Encoding.Length];
    362                 for (int i = 0; i < Problem.Encoding.Length; i++) weights[i] = EPSILON;
     363                double[] weights = new double[NumberOfObjectives];
     364                for (int i = 0; i < NumberOfObjectives; i++) weights[i] = EPSILON;
    363365                weights[j] = 1;
    364366                double func(Solution s) => ASF(s.Fitness, weights);
     
    379381                foreach (var solution in Fronts[f])
    380382                {
    381                     for (int i = 0; i < Problem.Encoding.Length; i++)
     383                    for (int i = 0; i < NumberOfObjectives; i++)
    382384                    {
    383385                        if (Math.Abs(intercepts[i] - idealPoint[i]) > EPSILON)
     
    498500        {
    499501            List<int> dimensions = new List<int>();
    500             for (int i = 0; i < Problem.Encoding.Length; i++) dimensions.Add(i);
     502            for (int i = 0; i < NumberOfObjectives; i++) dimensions.Add(i);
    501503            double f(int dim) => x[dim] / weight[dim];
    502504            return Utility.Max(f, dimensions);
     
    521523            if (duplicate)
    522524            { // cannot construct the unique hyperplane (this is a casual method to deal with the condition)
    523                 for (int f = 0; f < Problem.Encoding.Length; f++)
     525                for (int f = 0; f < NumberOfObjectives; f++)
    524526                {
    525527                    // extreme_points[f] stands for the individual with the largest value of
     
    532534                // Find the equation of the hyperplane
    533535                List<double> b = new List<double>(); //(pop[0].objs().size(), 1.0);
    534                 for (int i = 0; i < Problem.Encoding.Length; i++)
     536                for (int i = 0; i < NumberOfObjectives; i++)
    535537                {
    536538                    b.Add(1.0);
     
    541543                {
    542544                    List<double> aux = new List<double>();
    543                     for (int i = 0; i < Problem.Encoding.Length; i++)
     545                    for (int i = 0; i < NumberOfObjectives; i++)
    544546                        aux.Add(s.Fitness[i]);
    545547                    a.Add(aux);
     
    548550
    549551                // Find intercepts
    550                 for (int f = 0; f < Problem.Encoding.Length; f++)
     552                for (int f = 0; f < NumberOfObjectives; f++)
    551553                {
    552554                    intercepts.Add(1.0 / x[f]);
Note: See TracChangeset for help on using the changeset viewer.