Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2825-NSGA3/HeuristicLab.Algorithms.NSGA3/3.3/ReferencePoint.cs @ 17558

Last change on this file since 17558 was 17558, checked in by dleko, 4 years ago

#2825: Generate structured reference points and show them in Results tab.

File size: 3.3 KB
Line 
1using System.Collections.Generic;
2
3namespace HeuristicLab.Algorithms.NSGA3
4{
5    /*
6     * The method for generating the reference points is based on the NSGA3 implementation in the jMetal framework (http://jmetal.sourceforge.net/).
7     * That implementation in return is based on Tsung-Che Chiang's code
8     * http://web.ntnu.edu.tw/~tcchiang/publications/nsga3cpp/nsga3cpp.htm
9     */
10
11    internal class ReferencePoint
12    {
13        public ReferencePoint(int numberOfDimensions)
14        {
15            NumberOfDimensions = numberOfDimensions;
16            Values = new double[NumberOfDimensions];
17        }
18
19        public ReferencePoint(ReferencePoint other)
20        {
21            NumberOfDimensions = other.NumberOfDimensions;
22            Values = new double[NumberOfDimensions];
23            for (int i = 0; i < NumberOfDimensions; i++)
24                Values[i] = other.Values[i];
25        }
26
27        public int NumberOfDimensions { get; }
28
29        public double[] Values { get; }
30
31        // todo: use this (for optimization)
32        /// <summary>
33        /// Returns the number of reference points that are generated by <see
34        /// cref="GenerateReferencePoints(List{ReferencePoint}, int, int)" /> for the given number
35        /// of dimensions and divisions.
36        /// </summary>
37        /// <param name="nDim">The number of dimensions</param>
38        /// <param name="nDiv">The number of divisions</param>
39        /// <returns></returns>
40        internal static int GetNumberOfReferencePoints(int nDim, int nDiv)
41        {
42            return Utility.NCR(nDim + nDiv - 1, nDiv);
43        }
44
45        /// <summary>
46        /// Generate reference points that are evenly distributed over a hyperplane with dimensions
47        /// <paramref name="nDim" /> - 1 with the sum of the values in all dimensions being equal to
48        /// 1 for each reference point.
49        /// </summary>
50        /// <param name="nDim">The number of dimensions for the reference points</param>
51        /// <param name="nDiv">The number of divisions to use to generate reference points</param>
52        /// <returns>The generated reference points</returns>
53        internal static List<ReferencePoint> GenerateReferencePoints(int nDim, int nDiv)
54        {
55            List<ReferencePoint> referencePoints = new List<ReferencePoint>();
56            ReferencePoint refPoint = new ReferencePoint(nDim);
57            GenerateRecursive(referencePoints, refPoint, nDim, nDiv, nDiv, 0);
58
59            return referencePoints;
60        }
61
62        private static void GenerateRecursive(List<ReferencePoint> referencePoints, ReferencePoint refPoint, int numberOfObjectives, int left, int total, int element)
63        {
64            if (element == numberOfObjectives - 1)
65            {
66                refPoint.Values[element] = ((double)left) / total;
67                var newRefPoint = new ReferencePoint(refPoint);
68                referencePoints.Add(newRefPoint);
69            }
70            else
71            {
72                for (int i = 0; i <= left; i++)
73                {
74                    refPoint.Values[element] = (double)i / total;
75                    GenerateRecursive(referencePoints, refPoint, numberOfObjectives, left - i, total, element + 1);
76                }
77            }
78        }
79    }
80}
Note: See TracBrowser for help on using the repository browser.