source: trunk/sources/HeuristicLab.Tests/HeuristicLab.Problems.TestFunctions.MultiObjective-3.3/FastHyperVolumeTests.cs @ 14121

Last change on this file since 14121 was 14121, checked in by mkommend, 3 years ago

#1087: Copied unit tests from branch and adapted path of multi-objective test function project file.

File size: 3.7 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 Microsoft.VisualStudio.TestTools.UnitTesting;
23
24namespace HeuristicLab.Problems.TestFunctions.MultiObjective.Tests {
25  [TestClass]
26  public class FastHypervolumeTest {
27    /// <summary>
28    ///  /*
29    /// +-----+
30    /// |     |
31    /// |  x  |
32    /// |     |
33    /// +-----+
34    ///
35    /// box between(0,0,0) and(1,1,1) with singular point pareto front at(0.5,0.5,0.5)
36    /// Hypervolume should be 0.125; 
37    ///
38    /// </summary>
39    [TestMethod]
40    [TestCategory("Problems.TestFunctions.MultiObjective")]
41    [TestProperty("Time", "short")]
42    public void FastHypervolumeTestSinglePoint() {
43      double[] point = new double[] { 0.5, 0.5, 0.5 };
44      double[][] front = { point };
45      double[] referencePoint = new double[] { 1, 1, 1 };
46      double hv = Hypervolume.Calculate(front, referencePoint, new bool[3]);
47      Assert.AreEqual(0.125, hv);
48    }
49
50    /// <summary>
51    ///  /*
52    /// +-----+
53    /// | x   |
54    /// |     |
55    /// |     |
56    /// +-----+
57    ///
58    /// box between(0,0) and(1,1) with singular point pareto front at a random Location
59    /// Sum of the Hypervolume to each of the corners should be 1; 
60    ///
61    /// </summary>
62    [TestMethod]
63    [TestCategory("Problems.TestFunctions.MultiObjective")]
64    [TestProperty("Time", "short")]
65    public void FastHypervolumeTestRandomSinglePoint() {
66      //Front with a single Point
67      double[] point = new double[3];
68      var r = new System.Random();
69
70      point[0] = r.NextDouble();
71      point[1] = r.NextDouble();
72      point[2] = r.NextDouble();
73      double[][] front = { point };
74
75      double[] referencePoint = new double[3];
76
77      //Northeast
78      referencePoint[0] = 1;
79      referencePoint[1] = 1;
80      referencePoint[2] = 1;
81      double hv = Hypervolume.Calculate(front, referencePoint, new bool[3]);
82      double hv2 = 1;
83      foreach (double d in point) {
84        hv2 *= Math.Abs(d - 1);
85      }
86      Assert.AreEqual(hv2, hv);
87    }
88
89    /// <summary>
90    ///  /*
91    /// x-----+
92    /// |     |
93    /// |  X  |
94    /// |     |
95    /// +-----x
96    ///
97    /// box between(0,0,0) and(1,1,1) with three point (pareto) front at (1,0,0), (0.5,0.5,0)  and (0,1,0)
98    /// Hypervolume should be 0.25
99    /// </summary>
100    [TestMethod]
101    [TestCategory("Problems.TestFunctions.MultiObjective")]
102    [TestProperty("Time", "short")]
103    public void FastHypervolumeTestDiagonalPoint() {
104      //Front with three points
105      double[] point1 = new double[] { 1, 0, 0 };
106      double[] point2 = new double[] { 0, 1, 0 };
107      double[] point3 = new double[] { 0.5, 0.5, 0 };
108      double[][] front = { point1, point2, point3 };
109
110      double[] referencePoint = new double[] { 1, 1, 1 };
111      double hv = Hypervolume.Calculate(front, referencePoint, new bool[3]);
112      Assert.AreEqual(0.5, hv);
113    }
114  }
115}
Note: See TracBrowser for help on using the repository browser.