Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 13673 was 13673, checked in by bwerth, 9 years ago

#1087 fixed bug in DTLZ1, DTLZ3 and DTLZ7

File size: 8.5 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
30
31
32    /// <summary>
33    ///  /*
34    /// +-----+
35    /// |     |
36    /// |  x  |
37    /// |     |
38    /// +-----+
39    ///
40    /// box between(0,0) and(1,1) with singular point pareto front at(0.5,0.5)
41    /// Hypervolume to each of the corners should be 0.25; 
42    ///
43    /// </summary>
44    [TestMethod]
45    public void SinglePointTest() {
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 = Hypervolume.Calculate(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 = Hypervolume.Calculate(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 = Hypervolume.Calculate(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 = Hypervolume.Calculate(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    public void RandomSinglePointTest() {
101      //Front with a single Point
102      double[] point = new double[2];
103      Random r = new 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);
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    public void DiagonalPointTest() {
152      //Front with three points
153      double[] point1 = new double[2];
154      point1[0] = 0;
155      point1[1] = 1;
156      double[] point2 = new double[2];
157      point2[0] = 1;
158      point2[1] = 0;
159      double[] point3 = new double[2];
160      point3[0] = 0.5;
161      point3[1] = 0.5;
162      double[][] front = { point1, point2, point3 };
163
164      double[] referencePoint = new double[2];
165      bool[] maximization;
166
167      //Northeast
168      maximization = new bool[] { false, false };
169      referencePoint[0] = 1;
170      referencePoint[1] = 1;
171      double ne = Hypervolume.Calculate(front, referencePoint, maximization);
172      Assert.AreEqual(0.25, ne);
173
174      //NorthWest
175      maximization = new bool[] { true, false };
176      referencePoint[0] = 0;
177      referencePoint[1] = 1;
178      double nw = Hypervolume.Calculate(NonDominatedSelect.selectNonDominatedVectors(front, maximization, true), referencePoint, maximization);
179      Assert.AreEqual(1, nw);
180
181      //SouthWest
182      maximization = new bool[] { true, true };
183      referencePoint[0] = 0;
184      referencePoint[1] = 0;
185      double sw = Hypervolume.Calculate(front, referencePoint, maximization);
186      Assert.AreEqual(0.25, sw);
187
188      //SouthEast
189      maximization = new bool[] { false, true };
190      referencePoint[0] = 1;
191      referencePoint[1] = 0;
192      double se = Hypervolume.Calculate(NonDominatedSelect.selectNonDominatedVectors(front, maximization, true), referencePoint, maximization);
193      Assert.AreEqual(1, se);
194
195    }
196
197    [TestMethod()]
198    [ExpectedException(typeof(ArgumentException))]
199    public void ReferencePointViolationNE() {
200      //Front with a single Point
201      double[] point = new double[2];
202      point[0] = 0.5;
203      point[1] = 0.5;
204      double[][] front = { point };
205
206      double[] referencePoint = new double[2];
207      bool[] maximization;
208
209      //Northeast
210      maximization = new bool[] { true, true };
211      referencePoint[0] = 1;
212      referencePoint[1] = 1;
213      double ne = Hypervolume.Calculate(front, referencePoint, maximization);
214    }
215
216    [TestMethod()]
217    [ExpectedException(typeof(ArgumentException))]
218    public void ReferencePointViolationNW() {
219      //Front with a single Point
220      double[] point = new double[2];
221      point[0] = 0.5;
222      point[1] = 0.5;
223      double[][] front = { point };
224
225      double[] referencePoint = new double[2];
226      bool[] maximization;
227
228      //NorthWest
229      maximization = new bool[] { false, true };
230      referencePoint[0] = 0;
231      referencePoint[1] = 1;
232      double nw = Hypervolume.Calculate(front, referencePoint, maximization);
233      Assert.AreEqual(0.25, nw);
234    }
235
236    [TestMethod()]
237    [ExpectedException(typeof(ArgumentException))]
238    public void ReferencePointViolationSW() {
239      //Front with a single Point
240      double[] point = new double[2];
241      point[0] = 0.5;
242      point[1] = 0.5;
243      double[][] front = { point };
244
245      double[] referencePoint = new double[2];
246      bool[] maximization;
247
248      //SouthWest
249      maximization = new bool[] { false, false };
250      referencePoint[0] = 0;
251      referencePoint[1] = 0;
252      double sw = Hypervolume.Calculate(front, referencePoint, maximization);
253      Assert.AreEqual(0.25, sw);
254    }
255
256    [TestMethod()]
257    [ExpectedException(typeof(ArgumentException))]
258    public void ReferencePointViolationSE() {
259      //Front with a single Point
260      double[] point = new double[2];
261      point[0] = 0.5;
262      point[1] = 0.5;
263      double[][] front = { point };
264
265      double[] referencePoint = new double[2];
266      bool[] maximization;
267
268      //SouthEast
269      maximization = new bool[] { true, false };
270      referencePoint[0] = 1;
271      referencePoint[1] = 0;
272      double se = Hypervolume.Calculate(front, referencePoint, maximization);
273      Assert.AreEqual(0.25, se);
274    }
275
276  }
277
278
279}
Note: See TracBrowser for help on using the repository browser.