Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2521_ProblemRefactoring/HeuristicLab.Tests/HeuristicLab.Analysis-3.3/Multi-objective/HyperVolumeTests.cs @ 17262

Last change on this file since 17262 was 17262, checked in by mkommend, 4 years ago

#2521: Adapted unit tests for multi-objective analysis.

File size: 9.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21using System;
22using System.Linq;
23using HeuristicLab.Optimization;
24using Microsoft.VisualStudio.TestTools.UnitTesting;
25
26namespace HeuristicLab.Analysis.MultiObjective.Tests {
27  [TestClass]
28  public class HypervolumeTest {
29
30    /// <summary>
31    ///  /*
32    /// +-----+
33    /// |     |
34    /// |  x  |
35    /// |     |
36    /// +-----+
37    ///
38    /// box between(0,0) and(1,1) with singular point Pareto front at(0.5,0.5)
39    /// Hypervolume to each of the corners should be 0.25; 
40    ///
41    /// </summary>
42    [TestMethod]
43    [TestCategory("Analysis.MultiObjective")]
44    [TestProperty("Time", "short")]
45    public void HypervolumeTestSinglePoint() {
46
47      //Front with a single Point
48      double[] point = new double[2];
49      point[0] = 0.5;
50      point[1] = 0.5;
51      double[][] front = { point };
52
53      double[] referencePoint = new double[2];
54      bool[] maximization;
55
56      //Northeast
57      maximization = new bool[] { false, false };
58      referencePoint[0] = 1;
59      referencePoint[1] = 1;
60      double ne = HypervolumeCalculator.CalculateHypervolume(front, referencePoint, maximization);
61      Assert.AreEqual(0.25, ne);
62
63      //NorthWest
64      maximization = new bool[] { true, false };
65      referencePoint[0] = 0;
66      referencePoint[1] = 1;
67      double nw = HypervolumeCalculator.CalculateHypervolume(front, referencePoint, maximization);
68      Assert.AreEqual(0.25, nw);
69
70      //SouthWest
71      maximization = new bool[] { true, true };
72      referencePoint[0] = 0;
73      referencePoint[1] = 0;
74      double sw = HypervolumeCalculator.CalculateHypervolume(front, referencePoint, maximization);
75      Assert.AreEqual(0.25, sw);
76
77      //SouthEast
78      maximization = new bool[] { false, true };
79      referencePoint[0] = 1;
80      referencePoint[1] = 0;
81      double se = HypervolumeCalculator.CalculateHypervolume(front, referencePoint, maximization);
82      Assert.AreEqual(0.25, se);
83
84
85    }
86
87    /// <summary>
88    ///  /*
89    /// +-----+
90    /// | x   |
91    /// |     |
92    /// |     |
93    /// +-----+
94    ///
95    /// box between(0,0) and(1,1) with singular point Pareto front at a random Location
96    /// Sum of the Hypervolume to each of the corners should be 1; 
97    ///
98    /// </summary>
99    [TestMethod]
100    [TestCategory("Analysis.MultiObjective")]
101    [TestProperty("Time", "short")]
102    public void HypervolumeTestRandomSinglePoint() {
103      //Front with a single Point
104      double[] point = new double[2];
105      var r = new System.Random();
106
107      point[0] = r.NextDouble();
108      point[1] = r.NextDouble();
109      double[][] front = { point };
110
111      double[] referencePoint = new double[2];
112      bool[] maximization;
113
114      //Northeast
115      maximization = new bool[] { false, false };
116      referencePoint[0] = 1;
117      referencePoint[1] = 1;
118      double ne = HypervolumeCalculator.CalculateHypervolume(front, referencePoint, maximization);
119
120      //NorthWest
121      maximization = new bool[] { true, false };
122      referencePoint[0] = 0;
123      referencePoint[1] = 1;
124      double nw = HypervolumeCalculator.CalculateHypervolume(front, referencePoint, maximization);
125
126      //SouthWest
127      maximization = new bool[] { true, true };
128      referencePoint[0] = 0;
129      referencePoint[1] = 0;
130      double sw = HypervolumeCalculator.CalculateHypervolume(front, referencePoint, maximization);
131
132      //SouthEast
133      maximization = new bool[] { false, true };
134      referencePoint[0] = 1;
135      referencePoint[1] = 0;
136      double se = HypervolumeCalculator.CalculateHypervolume(front, referencePoint, maximization);
137      Assert.AreEqual(1.0, ne + se + nw + sw, 1e8);
138    }
139
140    /// <summary>
141    ///  /*
142    /// x-----+
143    /// |     |
144    /// |  X  |
145    /// |     |
146    /// +-----x
147    ///
148    /// box between(0,0) and(1,1) with three point (Pareto) front at (1,0), (0.5,0.5)  and (0,1)
149    /// Hypervolume to (1,0) and (0,1) of the corners should be 1 (dominated Points need to be removed beforehand and   
150    /// Hypervolume to (0,0) and (1,1) of the corners should be 0.25
151    /// </summary>
152    [TestMethod]
153    [TestCategory("Analysis.MultiObjective")]
154    [TestProperty("Time", "short")]
155    public void HypervolumeTestDiagonalPoint() {
156      //Front with three points
157      double[] point1 = new double[2];
158      point1[0] = 0;
159      point1[1] = 1;
160      double[] point2 = new double[2];
161      point2[0] = 1;
162      point2[1] = 0;
163      double[] point3 = new double[2];
164      point3[0] = 0.5;
165      point3[1] = 0.5;
166      double[][] front = { point1, point2, point3 };
167
168      double[] referencePoint = new double[2];
169      bool[] maximization;
170
171      //Northeast
172      maximization = new bool[] { false, false };
173      referencePoint[0] = 1;
174      referencePoint[1] = 1;
175      double ne = HypervolumeCalculator.CalculateHypervolume(front, referencePoint, maximization);
176      Assert.AreEqual(0.25, ne);
177
178      //NorthWest
179      maximization = new bool[] { true, false };
180      referencePoint[0] = 0;
181      referencePoint[1] = 1;
182      var nonDominatedFront = DominationCalculator.CalculateBestParetoFront(front, front, maximization, false).Select(i => i.Item2).ToList();
183      double nw = HypervolumeCalculator.CalculateHypervolume(nonDominatedFront, referencePoint, maximization);
184      Assert.AreEqual(1, nw);
185
186      //SouthWest
187      maximization = new bool[] { true, true };
188      referencePoint[0] = 0;
189      referencePoint[1] = 0;
190      double sw = HypervolumeCalculator.CalculateHypervolume(front, referencePoint, maximization);
191      Assert.AreEqual(0.25, sw);
192
193      //SouthEast
194      maximization = new bool[] { false, true };
195      referencePoint[0] = 1;
196      referencePoint[1] = 0;
197      nonDominatedFront = DominationCalculator.CalculateBestParetoFront(front, front, maximization, false).Select(i => i.Item2).ToList();
198      double se = HypervolumeCalculator.CalculateHypervolume(nonDominatedFront, referencePoint, maximization);
199      Assert.AreEqual(1, se);
200
201    }
202
203    [TestMethod()]
204    [ExpectedException(typeof(ArgumentException))]
205    [TestCategory("Analysis.MultiObjective")]
206    [TestProperty("Time", "short")]
207    public void HypervolumeTestReferencePointViolationNE() {
208      //Front with a single Point
209      double[] point = new double[2];
210      point[0] = 0.5;
211      point[1] = 0.5;
212      double[][] front = { point };
213
214      double[] referencePoint = new double[2];
215      bool[] maximization;
216
217      //Northeast
218      maximization = new bool[] { true, true };
219      referencePoint[0] = 1;
220      referencePoint[1] = 1;
221      double ne = HypervolumeCalculator.CalculateHypervolume(front, referencePoint, maximization);
222    }
223
224    [TestMethod()]
225    [ExpectedException(typeof(ArgumentException))]
226    [TestCategory("Analysis.MultiObjective")]
227    [TestProperty("Time", "short")]
228    public void HypervolumeTestReferencePointViolationNW() {
229      //Front with a single Point
230      double[] point = new double[2];
231      point[0] = 0.5;
232      point[1] = 0.5;
233      double[][] front = { point };
234
235      double[] referencePoint = new double[2];
236      bool[] maximization;
237
238      //NorthWest
239      maximization = new bool[] { false, true };
240      referencePoint[0] = 0;
241      referencePoint[1] = 1;
242      double nw = HypervolumeCalculator.CalculateHypervolume(front, referencePoint, maximization);
243      Assert.AreEqual(0.25, nw);
244    }
245
246    [TestMethod()]
247    [ExpectedException(typeof(ArgumentException))]
248    [TestCategory("Analysis.MultiObjective")]
249    [TestProperty("Time", "short")]
250    public void HypervolumeTestReferencePointViolationSW() {
251      //Front with a single Point
252      double[] point = new double[2];
253      point[0] = 0.5;
254      point[1] = 0.5;
255      double[][] front = { point };
256
257      double[] referencePoint = new double[2];
258      bool[] maximization;
259
260      //SouthWest
261      maximization = new bool[] { false, false };
262      referencePoint[0] = 0;
263      referencePoint[1] = 0;
264      double sw = HypervolumeCalculator.CalculateHypervolume(front, referencePoint, maximization);
265      Assert.AreEqual(0.25, sw);
266    }
267
268    [TestMethod()]
269    [ExpectedException(typeof(ArgumentException))]
270    [TestCategory("Analysis.MultiObjective")]
271    [TestProperty("Time", "short")]
272    public void HypervolumeTestReferencePointViolationSE() {
273      //Front with a single Point
274      double[] point = new double[2];
275      point[0] = 0.5;
276      point[1] = 0.5;
277      double[][] front = { point };
278
279      double[] referencePoint = new double[2];
280      bool[] maximization;
281
282      //SouthEast
283      maximization = new bool[] { true, false };
284      referencePoint[0] = 1;
285      referencePoint[1] = 0;
286      double se = HypervolumeCalculator.CalculateHypervolume(front, referencePoint, maximization);
287      Assert.AreEqual(0.25, se);
288    }
289  }
290}
Note: See TracBrowser for help on using the repository browser.