Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.MultiObjectiveTestFunctions/MultiObjectiveTestfunctionTests/HyperVolumeTests.cs @ 14092

Last change on this file since 14092 was 14081, checked in by mkommend, 8 years ago

#1087: Refactored utility class NonDominatedSelect.

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