Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/22/20 12:53:10 (4 years ago)
Author:
dleko
Message:

#2825 Bugfix: NSGA3 now works as intended.

File:
1 edited

Legend:

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

    r17668 r17692  
    1515        /// have the same number of objectives, undefined behavior happens.
    1616        /// </summary>
    17         /// <param name="rt"></param>
     17        /// <param name="rt">The previous generation and its mutated children.</param>
    1818        /// <param name="referencePoints"></param>
    1919        /// <param name="maximization"></param>
     20        /// <param name="N">Number of solutions to select.</param>
     21        /// <param name="random">The <see cref="IRandom" /> to use for randomness.</param>
    2022        /// <returns></returns>
    21         public static List<Solution> SelectSolutionsForNextGeneration(List<Solution> rt, List<ReferencePoint> referencePoints, bool[] maximization, IRandom random)
    22         {
    23             int N = rt.Count / 2; // number of solutions in a generation
     23        public static List<Solution> SelectSolutionsForNextGeneration(List<Solution> rt, List<ReferencePoint> referencePoints, bool[] maximization, int N, IRandom random)
     24        {
    2425            int numberOfObjectives = rt.First().Fitness.Length;
    2526            List<Solution> st = new List<Solution>();
     
    6465            // Find the ideal point
    6566            double[] idealPoint = new double[numberOfObjectives];
     67
     68            foreach (var solution in st)
     69                solution.ConvertedFitness = new double[numberOfObjectives];
     70
    6671            for (int j = 0; j < numberOfObjectives; j++)
    6772            {
     
    6974                idealPoint[j] = Utility.Min(s => s.Fitness[j], st);
    7075
    71                 // Translate objectives
     76                // Translate objectives and save the modified fitness values in ConvertedFitness
    7277                foreach (var solution in st)
    73                     solution.Fitness[j] -= idealPoint[j];
     78                    solution.ConvertedFitness[j] = solution.Fitness[j] - idealPoint[j];
    7479            }
    7580
     
    8388                weights[j] = 1;
    8489
    85                 extremePoints[j] = Utility.ArgMin(s => ASF(s.Fitness, weights), st);
     90                extremePoints[j] = Utility.ArgMin(s => ASF(s.ConvertedFitness, weights), st);
    8691            }
    8792
     
    103108                    if (Math.Abs(intercepts[i] - idealPoint[i]) > EPSILON)
    104109                    {
    105                         solution.Fitness[i] = solution.Fitness[i] / (intercepts[i] - idealPoint[i]);
     110                        solution.ConvertedFitness[i] = solution.ConvertedFitness[i] / (intercepts[i] - idealPoint[i]);
    106111                    }
    107112                    else
    108113                    {
    109                         solution.Fitness[i] = solution.Fitness[i] / EPSILON;
     114                        solution.ConvertedFitness[i] = solution.ConvertedFitness[i] / EPSILON;
    110115                    }
    111116                }
     
    121126                    // find reference point for which the perpendicular distance to the current
    122127                    // solution is the lowest
    123                     var rpAndDist = Utility.MinArgMin(rp => GetPerpendicularDistance(rp.Values, solution.Fitness), referencePoints);
     128                    var rpAndDist = Utility.MinArgMin(rp => GetPerpendicularDistance(rp.Values, solution.ConvertedFitness), referencePoints);
    124129                    // associated reference point
    125130                    var arp = rpAndDist.Item1;
     
    235240                for (int j = i + 1; !duplicate && j < extremePoints.Count; j++)
    236241                {
    237                     // maybe todo: override Equals method of solution?
    238                     duplicate = extremePoints[i].Equals(extremePoints[j]);
     242                    duplicate = extremePoints[i] == extremePoints[j];
    239243                }
    240244            }
     
    242246            List<double> intercepts = new List<double>();
    243247
     248            // todo: do handling of this case as in Tsung Che Chiang's implementation
    244249            if (duplicate)
    245250            { // cannot construct the unique hyperplane (this is a casual method to deal with the condition)
     
    248253                    // extreme_points[f] stands for the individual with the largest value of
    249254                    // objective f
    250                     intercepts.Add(extremePoints[f].Fitness[f]);
     255                    intercepts.Add(extremePoints[f].ConvertedFitness[f]);
    251256                }
    252257            }
     
    260265                }
    261266
    262                 List<List<double>> a = new List<List<double>>();
    263                 foreach (Solution s in extremePoints)
    264                 {
    265                     List<double> aux = new List<double>();
    266                     for (int i = 0; i < numberOfObjectives; i++)
    267                         aux.Add(s.Fitness[i]);
    268                     a.Add(aux);
    269                 }
     267                List<List<double>> a = extremePoints.Select(p => p.ConvertedFitness.ToList()).ToList();
     268
    270269                List<double> x = GaussianElimination(a, b);
    271270
Note: See TracChangeset for help on using the changeset viewer.