Free cookie consent management tool by TermsFeed Policy Generator

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