[13673] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[16565] | 3 | * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[13673] | 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
|
---|
| 21 | using System;
|
---|
| 22 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
| 23 |
|
---|
[14121] | 24 | namespace HeuristicLab.Problems.TestFunctions.MultiObjective.Tests {
|
---|
[13673] | 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]
|
---|
[14121] | 40 | [TestCategory("Problems.TestFunctions.MultiObjective")]
|
---|
[13729] | 41 | [TestProperty("Time", "short")]
|
---|
[14121] | 42 | public void FastHypervolumeTestSinglePoint() {
|
---|
[13673] | 43 | double[] point = new double[] { 0.5, 0.5, 0.5 };
|
---|
| 44 | double[][] front = { point };
|
---|
| 45 | double[] referencePoint = new double[] { 1, 1, 1 };
|
---|
[14030] | 46 | double hv = Hypervolume.Calculate(front, referencePoint, new bool[3]);
|
---|
[13673] | 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]
|
---|
[14121] | 63 | [TestCategory("Problems.TestFunctions.MultiObjective")]
|
---|
[13729] | 64 | [TestProperty("Time", "short")]
|
---|
[14121] | 65 | public void FastHypervolumeTestRandomSinglePoint() {
|
---|
[13673] | 66 | //Front with a single Point
|
---|
| 67 | double[] point = new double[3];
|
---|
[14121] | 68 | var r = new System.Random();
|
---|
[13673] | 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;
|
---|
[14030] | 81 | double hv = Hypervolume.Calculate(front, referencePoint, new bool[3]);
|
---|
[13673] | 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>
|
---|
[14121] | 100 | [TestMethod]
|
---|
| 101 | [TestCategory("Problems.TestFunctions.MultiObjective")]
|
---|
| 102 | [TestProperty("Time", "short")]
|
---|
| 103 | public void FastHypervolumeTestDiagonalPoint() {
|
---|
[13673] | 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 };
|
---|
[14030] | 111 | double hv = Hypervolume.Calculate(front, referencePoint, new bool[3]);
|
---|
[14121] | 112 | Assert.AreEqual(0.5, hv);
|
---|
[13673] | 113 | }
|
---|
| 114 | }
|
---|
| 115 | }
|
---|