[13673] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[16711] | 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 HypervolumeTest {
|
---|
| 27 |
|
---|
| 28 | /// <summary>
|
---|
| 29 | /// /*
|
---|
| 30 | /// +-----+
|
---|
| 31 | /// | |
|
---|
| 32 | /// | x |
|
---|
| 33 | /// | |
|
---|
| 34 | /// +-----+
|
---|
| 35 | ///
|
---|
| 36 | /// box between(0,0) and(1,1) with singular point pareto front at(0.5,0.5)
|
---|
| 37 | /// Hypervolume to each of the corners should be 0.25;
|
---|
| 38 | ///
|
---|
| 39 | /// </summary>
|
---|
| 40 | [TestMethod]
|
---|
[14121] | 41 | [TestCategory("Problems.TestFunctions.MultiObjective")]
|
---|
[13729] | 42 | [TestProperty("Time", "short")]
|
---|
[14121] | 43 | public void HypervolumeTestSinglePoint() {
|
---|
[13673] | 44 |
|
---|
| 45 | //Front with a single Point
|
---|
| 46 | double[] point = new double[2];
|
---|
| 47 | point[0] = 0.5;
|
---|
| 48 | point[1] = 0.5;
|
---|
| 49 | double[][] front = { point };
|
---|
| 50 |
|
---|
| 51 | double[] referencePoint = new double[2];
|
---|
| 52 | bool[] maximization;
|
---|
| 53 |
|
---|
| 54 | //Northeast
|
---|
| 55 | maximization = new bool[] { false, false };
|
---|
| 56 | referencePoint[0] = 1;
|
---|
| 57 | referencePoint[1] = 1;
|
---|
| 58 | double ne = Hypervolume.Calculate(front, referencePoint, maximization);
|
---|
| 59 | Assert.AreEqual(0.25, ne);
|
---|
| 60 |
|
---|
| 61 | //NorthWest
|
---|
| 62 | maximization = new bool[] { true, false };
|
---|
| 63 | referencePoint[0] = 0;
|
---|
| 64 | referencePoint[1] = 1;
|
---|
| 65 | double nw = Hypervolume.Calculate(front, referencePoint, maximization);
|
---|
| 66 | Assert.AreEqual(0.25, nw);
|
---|
| 67 |
|
---|
| 68 | //SouthWest
|
---|
| 69 | maximization = new bool[] { true, true };
|
---|
| 70 | referencePoint[0] = 0;
|
---|
| 71 | referencePoint[1] = 0;
|
---|
| 72 | double sw = Hypervolume.Calculate(front, referencePoint, maximization);
|
---|
| 73 | Assert.AreEqual(0.25, sw);
|
---|
| 74 |
|
---|
| 75 | //SouthEast
|
---|
| 76 | maximization = new bool[] { false, true };
|
---|
| 77 | referencePoint[0] = 1;
|
---|
| 78 | referencePoint[1] = 0;
|
---|
| 79 | double se = Hypervolume.Calculate(front, referencePoint, maximization);
|
---|
| 80 | Assert.AreEqual(0.25, se);
|
---|
| 81 |
|
---|
| 82 |
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | /// <summary>
|
---|
| 86 | /// /*
|
---|
| 87 | /// +-----+
|
---|
| 88 | /// | x |
|
---|
| 89 | /// | |
|
---|
| 90 | /// | |
|
---|
| 91 | /// +-----+
|
---|
| 92 | ///
|
---|
| 93 | /// box between(0,0) and(1,1) with singular point pareto front at a random Location
|
---|
| 94 | /// Sum of the Hypervolume to each of the corners should be 1;
|
---|
| 95 | ///
|
---|
| 96 | /// </summary>
|
---|
| 97 | [TestMethod]
|
---|
[14121] | 98 | [TestCategory("Problems.TestFunctions.MultiObjective")]
|
---|
[13729] | 99 | [TestProperty("Time", "short")]
|
---|
[14121] | 100 | public void HypervolumeTestRandomSinglePoint() {
|
---|
[13673] | 101 | //Front with a single Point
|
---|
| 102 | double[] point = new double[2];
|
---|
[14121] | 103 | var r = new System.Random();
|
---|
[13673] | 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);
|
---|
[13729] | 135 | Assert.AreEqual(1.0, ne + se + nw + sw, 1e8);
|
---|
[13673] | 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]
|
---|
[14121] | 151 | [TestCategory("Problems.TestFunctions.MultiObjective")]
|
---|
[13729] | 152 | [TestProperty("Time", "short")]
|
---|
[14121] | 153 | public void HypervolumeTestDiagonalPoint() {
|
---|
[13673] | 154 | //Front with three points
|
---|
| 155 | double[] point1 = new double[2];
|
---|
| 156 | point1[0] = 0;
|
---|
| 157 | point1[1] = 1;
|
---|
| 158 | double[] point2 = new double[2];
|
---|
| 159 | point2[0] = 1;
|
---|
| 160 | point2[1] = 0;
|
---|
| 161 | double[] point3 = new double[2];
|
---|
| 162 | point3[0] = 0.5;
|
---|
| 163 | point3[1] = 0.5;
|
---|
| 164 | double[][] front = { point1, point2, point3 };
|
---|
| 165 |
|
---|
| 166 | double[] referencePoint = new double[2];
|
---|
| 167 | bool[] maximization;
|
---|
| 168 |
|
---|
| 169 | //Northeast
|
---|
| 170 | maximization = new bool[] { false, false };
|
---|
| 171 | referencePoint[0] = 1;
|
---|
| 172 | referencePoint[1] = 1;
|
---|
| 173 | double ne = Hypervolume.Calculate(front, referencePoint, maximization);
|
---|
| 174 | Assert.AreEqual(0.25, ne);
|
---|
| 175 |
|
---|
| 176 | //NorthWest
|
---|
| 177 | maximization = new bool[] { true, false };
|
---|
| 178 | referencePoint[0] = 0;
|
---|
| 179 | referencePoint[1] = 1;
|
---|
[14081] | 180 | double nw = Hypervolume.Calculate(NonDominatedSelect.SelectNonDominatedVectors(front, maximization, true), referencePoint, maximization);
|
---|
[13673] | 181 | Assert.AreEqual(1, nw);
|
---|
| 182 |
|
---|
| 183 | //SouthWest
|
---|
| 184 | maximization = new bool[] { true, true };
|
---|
| 185 | referencePoint[0] = 0;
|
---|
| 186 | referencePoint[1] = 0;
|
---|
| 187 | double sw = Hypervolume.Calculate(front, referencePoint, maximization);
|
---|
| 188 | Assert.AreEqual(0.25, sw);
|
---|
| 189 |
|
---|
| 190 | //SouthEast
|
---|
| 191 | maximization = new bool[] { false, true };
|
---|
| 192 | referencePoint[0] = 1;
|
---|
| 193 | referencePoint[1] = 0;
|
---|
[14081] | 194 | double se = Hypervolume.Calculate(NonDominatedSelect.SelectNonDominatedVectors(front, maximization, true), referencePoint, maximization);
|
---|
[13673] | 195 | Assert.AreEqual(1, se);
|
---|
| 196 |
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 | [TestMethod()]
|
---|
| 200 | [ExpectedException(typeof(ArgumentException))]
|
---|
[14121] | 201 | [TestCategory("Problems.TestFunctions.MultiObjective")]
|
---|
[13729] | 202 | [TestProperty("Time", "short")]
|
---|
[14121] | 203 | public void HypervolumeTestReferencePointViolationNE() {
|
---|
[13673] | 204 | //Front with a single Point
|
---|
| 205 | double[] point = new double[2];
|
---|
| 206 | point[0] = 0.5;
|
---|
| 207 | point[1] = 0.5;
|
---|
| 208 | double[][] front = { point };
|
---|
| 209 |
|
---|
| 210 | double[] referencePoint = new double[2];
|
---|
| 211 | bool[] maximization;
|
---|
| 212 |
|
---|
| 213 | //Northeast
|
---|
| 214 | maximization = new bool[] { true, true };
|
---|
| 215 | referencePoint[0] = 1;
|
---|
| 216 | referencePoint[1] = 1;
|
---|
| 217 | double ne = Hypervolume.Calculate(front, referencePoint, maximization);
|
---|
| 218 | }
|
---|
| 219 |
|
---|
| 220 | [TestMethod()]
|
---|
| 221 | [ExpectedException(typeof(ArgumentException))]
|
---|
[14121] | 222 | [TestCategory("Problems.TestFunctions.MultiObjective")]
|
---|
[13729] | 223 | [TestProperty("Time", "short")]
|
---|
[14121] | 224 | public void HypervolumeTestReferencePointViolationNW() {
|
---|
[13673] | 225 | //Front with a single Point
|
---|
| 226 | double[] point = new double[2];
|
---|
| 227 | point[0] = 0.5;
|
---|
| 228 | point[1] = 0.5;
|
---|
| 229 | double[][] front = { point };
|
---|
| 230 |
|
---|
| 231 | double[] referencePoint = new double[2];
|
---|
| 232 | bool[] maximization;
|
---|
| 233 |
|
---|
| 234 | //NorthWest
|
---|
| 235 | maximization = new bool[] { false, true };
|
---|
| 236 | referencePoint[0] = 0;
|
---|
| 237 | referencePoint[1] = 1;
|
---|
| 238 | double nw = Hypervolume.Calculate(front, referencePoint, maximization);
|
---|
| 239 | Assert.AreEqual(0.25, nw);
|
---|
| 240 | }
|
---|
| 241 |
|
---|
| 242 | [TestMethod()]
|
---|
| 243 | [ExpectedException(typeof(ArgumentException))]
|
---|
[14121] | 244 | [TestCategory("Problems.TestFunctions.MultiObjective")]
|
---|
[13729] | 245 | [TestProperty("Time", "short")]
|
---|
[14121] | 246 | public void HypervolumeTestReferencePointViolationSW() {
|
---|
[13673] | 247 | //Front with a single Point
|
---|
| 248 | double[] point = new double[2];
|
---|
| 249 | point[0] = 0.5;
|
---|
| 250 | point[1] = 0.5;
|
---|
| 251 | double[][] front = { point };
|
---|
| 252 |
|
---|
| 253 | double[] referencePoint = new double[2];
|
---|
| 254 | bool[] maximization;
|
---|
| 255 |
|
---|
| 256 | //SouthWest
|
---|
| 257 | maximization = new bool[] { false, false };
|
---|
| 258 | referencePoint[0] = 0;
|
---|
| 259 | referencePoint[1] = 0;
|
---|
| 260 | double sw = Hypervolume.Calculate(front, referencePoint, maximization);
|
---|
| 261 | Assert.AreEqual(0.25, sw);
|
---|
| 262 | }
|
---|
| 263 |
|
---|
| 264 | [TestMethod()]
|
---|
| 265 | [ExpectedException(typeof(ArgumentException))]
|
---|
[14121] | 266 | [TestCategory("Problems.TestFunctions.MultiObjective")]
|
---|
[13729] | 267 | [TestProperty("Time", "short")]
|
---|
[14121] | 268 | public void HypervolumeTestReferencePointViolationSE() {
|
---|
[13673] | 269 | //Front with a single Point
|
---|
| 270 | double[] point = new double[2];
|
---|
| 271 | point[0] = 0.5;
|
---|
| 272 | point[1] = 0.5;
|
---|
| 273 | double[][] front = { point };
|
---|
| 274 |
|
---|
| 275 | double[] referencePoint = new double[2];
|
---|
| 276 | bool[] maximization;
|
---|
| 277 |
|
---|
| 278 | //SouthEast
|
---|
| 279 | maximization = new bool[] { true, false };
|
---|
| 280 | referencePoint[0] = 1;
|
---|
| 281 | referencePoint[1] = 0;
|
---|
| 282 | double se = Hypervolume.Calculate(front, referencePoint, maximization);
|
---|
| 283 | Assert.AreEqual(0.25, se);
|
---|
| 284 | }
|
---|
| 285 | }
|
---|
| 286 | }
|
---|