1 | using System.Collections.Generic;
|
---|
2 |
|
---|
3 | namespace 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 | public class ReferencePoint
|
---|
12 | {
|
---|
13 | #region Properties
|
---|
14 |
|
---|
15 | public double[] Values { get; }
|
---|
16 | public int NumberOfDimensions => Values.Length;
|
---|
17 |
|
---|
18 | #endregion Properties
|
---|
19 |
|
---|
20 | #region Constructors
|
---|
21 |
|
---|
22 | public ReferencePoint(int numberOfDimensions)
|
---|
23 | {
|
---|
24 | Values = new double[numberOfDimensions];
|
---|
25 | }
|
---|
26 |
|
---|
27 | public ReferencePoint(ReferencePoint other)
|
---|
28 | {
|
---|
29 | Values = new double[other.NumberOfDimensions];
|
---|
30 | for (int i = 0; i < other.NumberOfDimensions; i++)
|
---|
31 | Values[i] = other.Values[i];
|
---|
32 | }
|
---|
33 |
|
---|
34 | #endregion Constructors
|
---|
35 |
|
---|
36 | // todo: use this (for optimization)
|
---|
37 | /// <summary>
|
---|
38 | /// Returns the number of reference points that are generated by <see
|
---|
39 | /// cref="GenerateReferencePoints(List{ReferencePoint}, int, int)" /> for the given number
|
---|
40 | /// of dimensions and divisions.
|
---|
41 | /// </summary>
|
---|
42 | /// <param name="nDim">The number of dimensions</param>
|
---|
43 | /// <param name="nDiv">The number of divisions</param>
|
---|
44 | /// <returns></returns>
|
---|
45 | internal static int GetNumberOfReferencePoints(int nDim, int nDiv)
|
---|
46 | {
|
---|
47 | return Utility.NCR(nDim + nDiv - 1, nDiv);
|
---|
48 | }
|
---|
49 |
|
---|
50 | // maybe todo: move this to another class?
|
---|
51 | /// <summary>
|
---|
52 | /// Generate reference points that are evenly distributed over a hyperplane with dimensions
|
---|
53 | /// <paramref name="nDim" /> - 1 with the sum of the values in all dimensions being equal to
|
---|
54 | /// 1 for each reference point.
|
---|
55 | /// </summary>
|
---|
56 | /// <param name="nDim">The number of dimensions for the reference points</param>
|
---|
57 | /// <param name="nDiv">The number of divisions to use to generate reference points</param>
|
---|
58 | /// <returns>The generated reference points</returns>
|
---|
59 | internal static List<ReferencePoint> GenerateReferencePoints(int nDim, int nDiv)
|
---|
60 | {
|
---|
61 | List<ReferencePoint> referencePoints = new List<ReferencePoint>();
|
---|
62 | ReferencePoint refPoint = new ReferencePoint(nDim);
|
---|
63 | GenerateRecursive(referencePoints, refPoint, nDim, nDiv, nDiv, 0);
|
---|
64 |
|
---|
65 | return referencePoints;
|
---|
66 | }
|
---|
67 |
|
---|
68 | private static void GenerateRecursive(List<ReferencePoint> referencePoints, ReferencePoint refPoint, int numberOfObjectives, int left, int total, int element)
|
---|
69 | {
|
---|
70 | if (element == numberOfObjectives - 1)
|
---|
71 | {
|
---|
72 | refPoint.Values[element] = ((double)left) / total;
|
---|
73 | var newRefPoint = new ReferencePoint(refPoint);
|
---|
74 | referencePoints.Add(newRefPoint);
|
---|
75 | }
|
---|
76 | else
|
---|
77 | {
|
---|
78 | for (int i = 0; i <= left; i++)
|
---|
79 | {
|
---|
80 | refPoint.Values[element] = (double)i / total;
|
---|
81 | GenerateRecursive(referencePoints, refPoint, numberOfObjectives, left - i, total, element + 1);
|
---|
82 | }
|
---|
83 | }
|
---|
84 | }
|
---|
85 | }
|
---|
86 | } |
---|