Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Tests/HeuristicLab.Problems.TestFunctions.MultiObjective-3.3/HyperVolumeTests.cs @ 15817

Last change on this file since 15817 was 15584, checked in by swagner, 7 years ago

#2640: Updated year of copyrights in license headers on stable

File size: 9.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 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 Microsoft.VisualStudio.TestTools.UnitTesting;
23
24namespace HeuristicLab.Problems.TestFunctions.MultiObjective.Tests {
25  [TestClass]
26  public class HypervolumeTest {
27
28    /// <summary>
29    ///  /*
30    /// +-----+
31    /// |     |
32    /// |  x  |
33    /// |     |
34    /// +-----+
35    ///
36    /// box between(0,0) and(1,1) with singular point pareto front at(0.5,0.5)
37    /// Hypervolume to each of the corners should be 0.25; 
38    ///
39    /// </summary>
40    [TestMethod]
41    [TestCategory("Problems.TestFunctions.MultiObjective")]
42    [TestProperty("Time", "short")]
43    public void HypervolumeTestSinglePoint() {
44
45      //Front with a single Point
46      double[] point = new double[2];
47      point[0] = 0.5;
48      point[1] = 0.5;
49      double[][] front = { point };
50
51      double[] referencePoint = new double[2];
52      bool[] maximization;
53
54      //Northeast
55      maximization = new bool[] { false, false };
56      referencePoint[0] = 1;
57      referencePoint[1] = 1;
58      double ne = Hypervolume.Calculate(front, referencePoint, maximization);
59      Assert.AreEqual(0.25, ne);
60
61      //NorthWest
62      maximization = new bool[] { true, false };
63      referencePoint[0] = 0;
64      referencePoint[1] = 1;
65      double nw = Hypervolume.Calculate(front, referencePoint, maximization);
66      Assert.AreEqual(0.25, nw);
67
68      //SouthWest
69      maximization = new bool[] { true, true };
70      referencePoint[0] = 0;
71      referencePoint[1] = 0;
72      double sw = Hypervolume.Calculate(front, referencePoint, maximization);
73      Assert.AreEqual(0.25, sw);
74
75      //SouthEast
76      maximization = new bool[] { false, true };
77      referencePoint[0] = 1;
78      referencePoint[1] = 0;
79      double se = Hypervolume.Calculate(front, referencePoint, maximization);
80      Assert.AreEqual(0.25, se);
81
82
83    }
84
85    /// <summary>
86    ///  /*
87    /// +-----+
88    /// | x   |
89    /// |     |
90    /// |     |
91    /// +-----+
92    ///
93    /// box between(0,0) and(1,1) with singular point pareto front at a random Location
94    /// Sum of the Hypervolume to each of the corners should be 1; 
95    ///
96    /// </summary>
97    [TestMethod]
98    [TestCategory("Problems.TestFunctions.MultiObjective")]
99    [TestProperty("Time", "short")]
100    public void HypervolumeTestRandomSinglePoint() {
101      //Front with a single Point
102      double[] point = new double[2];
103      var r = new System.Random();
104
105      point[0] = r.NextDouble();
106      point[1] = r.NextDouble();
107      double[][] front = { point };
108
109      double[] referencePoint = new double[2];
110      bool[] maximization;
111
112      //Northeast
113      maximization = new bool[] { false, false };
114      referencePoint[0] = 1;
115      referencePoint[1] = 1;
116      double ne = Hypervolume.Calculate(front, referencePoint, maximization);
117
118      //NorthWest
119      maximization = new bool[] { true, false };
120      referencePoint[0] = 0;
121      referencePoint[1] = 1;
122      double nw = Hypervolume.Calculate(front, referencePoint, maximization);
123
124      //SouthWest
125      maximization = new bool[] { true, true };
126      referencePoint[0] = 0;
127      referencePoint[1] = 0;
128      double sw = Hypervolume.Calculate(front, referencePoint, maximization);
129
130      //SouthEast
131      maximization = new bool[] { false, true };
132      referencePoint[0] = 1;
133      referencePoint[1] = 0;
134      double se = Hypervolume.Calculate(front, referencePoint, maximization);
135      Assert.AreEqual(1.0, ne + se + nw + sw, 1e8);
136    }
137
138    /// <summary>
139    ///  /*
140    /// x-----+
141    /// |     |
142    /// |  X  |
143    /// |     |
144    /// +-----x
145    ///
146    /// box between(0,0) and(1,1) with three point (pareto) front at (1,0), (0.5,0.5)  and (0,1)
147    /// Hypervolume to (1,0) and (0,1) of the corners should be 1 (dominated Points need to be reemoved beforehand and   
148    /// Hypervolume to (0,0) and (1,1) of the corners should be 0.25
149    /// </summary>
150    [TestMethod]
151    [TestCategory("Problems.TestFunctions.MultiObjective")]
152    [TestProperty("Time", "short")]
153    public void HypervolumeTestDiagonalPoint() {
154      //Front with three points
155      double[] point1 = new double[2];
156      point1[0] = 0;
157      point1[1] = 1;
158      double[] point2 = new double[2];
159      point2[0] = 1;
160      point2[1] = 0;
161      double[] point3 = new double[2];
162      point3[0] = 0.5;
163      point3[1] = 0.5;
164      double[][] front = { point1, point2, point3 };
165
166      double[] referencePoint = new double[2];
167      bool[] maximization;
168
169      //Northeast
170      maximization = new bool[] { false, false };
171      referencePoint[0] = 1;
172      referencePoint[1] = 1;
173      double ne = Hypervolume.Calculate(front, referencePoint, maximization);
174      Assert.AreEqual(0.25, ne);
175
176      //NorthWest
177      maximization = new bool[] { true, false };
178      referencePoint[0] = 0;
179      referencePoint[1] = 1;
180      double nw = Hypervolume.Calculate(NonDominatedSelect.SelectNonDominatedVectors(front, maximization, true), referencePoint, maximization);
181      Assert.AreEqual(1, nw);
182
183      //SouthWest
184      maximization = new bool[] { true, true };
185      referencePoint[0] = 0;
186      referencePoint[1] = 0;
187      double sw = Hypervolume.Calculate(front, referencePoint, maximization);
188      Assert.AreEqual(0.25, sw);
189
190      //SouthEast
191      maximization = new bool[] { false, true };
192      referencePoint[0] = 1;
193      referencePoint[1] = 0;
194      double se = Hypervolume.Calculate(NonDominatedSelect.SelectNonDominatedVectors(front, maximization, true), referencePoint, maximization);
195      Assert.AreEqual(1, se);
196
197    }
198
199    [TestMethod()]
200    [ExpectedException(typeof(ArgumentException))]
201    [TestCategory("Problems.TestFunctions.MultiObjective")]
202    [TestProperty("Time", "short")]
203    public void HypervolumeTestReferencePointViolationNE() {
204      //Front with a single Point
205      double[] point = new double[2];
206      point[0] = 0.5;
207      point[1] = 0.5;
208      double[][] front = { point };
209
210      double[] referencePoint = new double[2];
211      bool[] maximization;
212
213      //Northeast
214      maximization = new bool[] { true, true };
215      referencePoint[0] = 1;
216      referencePoint[1] = 1;
217      double ne = Hypervolume.Calculate(front, referencePoint, maximization);
218    }
219
220    [TestMethod()]
221    [ExpectedException(typeof(ArgumentException))]
222    [TestCategory("Problems.TestFunctions.MultiObjective")]
223    [TestProperty("Time", "short")]
224    public void HypervolumeTestReferencePointViolationNW() {
225      //Front with a single Point
226      double[] point = new double[2];
227      point[0] = 0.5;
228      point[1] = 0.5;
229      double[][] front = { point };
230
231      double[] referencePoint = new double[2];
232      bool[] maximization;
233
234      //NorthWest
235      maximization = new bool[] { false, true };
236      referencePoint[0] = 0;
237      referencePoint[1] = 1;
238      double nw = Hypervolume.Calculate(front, referencePoint, maximization);
239      Assert.AreEqual(0.25, nw);
240    }
241
242    [TestMethod()]
243    [ExpectedException(typeof(ArgumentException))]
244    [TestCategory("Problems.TestFunctions.MultiObjective")]
245    [TestProperty("Time", "short")]
246    public void HypervolumeTestReferencePointViolationSW() {
247      //Front with a single Point
248      double[] point = new double[2];
249      point[0] = 0.5;
250      point[1] = 0.5;
251      double[][] front = { point };
252
253      double[] referencePoint = new double[2];
254      bool[] maximization;
255
256      //SouthWest
257      maximization = new bool[] { false, false };
258      referencePoint[0] = 0;
259      referencePoint[1] = 0;
260      double sw = Hypervolume.Calculate(front, referencePoint, maximization);
261      Assert.AreEqual(0.25, sw);
262    }
263
264    [TestMethod()]
265    [ExpectedException(typeof(ArgumentException))]
266    [TestCategory("Problems.TestFunctions.MultiObjective")]
267    [TestProperty("Time", "short")]
268    public void HypervolumeTestReferencePointViolationSE() {
269      //Front with a single Point
270      double[] point = new double[2];
271      point[0] = 0.5;
272      point[1] = 0.5;
273      double[][] front = { point };
274
275      double[] referencePoint = new double[2];
276      bool[] maximization;
277
278      //SouthEast
279      maximization = new bool[] { true, false };
280      referencePoint[0] = 1;
281      referencePoint[1] = 0;
282      double se = Hypervolume.Calculate(front, referencePoint, maximization);
283      Assert.AreEqual(0.25, se);
284    }
285  }
286}
Note: See TracBrowser for help on using the repository browser.