[13673] | 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
|
---|
| 21 | using System;
|
---|
| 22 | using System.Collections.Generic;
|
---|
| 23 | using HeuristicLab.Problems.MultiObjectiveTestFunctions;
|
---|
| 24 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
| 25 |
|
---|
| 26 | namespace MultiObjectiveTestfunctionTests {
|
---|
| 27 | [TestClass]
|
---|
| 28 | public class FastHypervolumeTest {
|
---|
| 29 | /// <summary>
|
---|
| 30 | /// /*
|
---|
| 31 | /// +-----+
|
---|
| 32 | /// | |
|
---|
| 33 | /// | x |
|
---|
| 34 | /// | |
|
---|
| 35 | /// +-----+
|
---|
| 36 | ///
|
---|
| 37 | /// box between(0,0,0) and(1,1,1) with singular point pareto front at(0.5,0.5,0.5)
|
---|
| 38 | /// Hypervolume should be 0.125;
|
---|
| 39 | ///
|
---|
| 40 | /// </summary>
|
---|
| 41 | [TestMethod]
|
---|
[13729] | 42 | [TestCategory("Problems.TestFunctions")]
|
---|
| 43 | [TestProperty("Time", "short")]
|
---|
[13673] | 44 | public void SinglePointTest() {
|
---|
| 45 | double[] point = new double[] { 0.5, 0.5, 0.5 };
|
---|
| 46 | double[][] front = { point };
|
---|
| 47 | double[] referencePoint = new double[] { 1, 1, 1 };
|
---|
[13726] | 48 | double hv = MultiDimensionalHypervolume.Calculate(front, referencePoint);
|
---|
[13673] | 49 | Assert.AreEqual(0.125, hv);
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | /// <summary>
|
---|
| 53 | /// /*
|
---|
| 54 | /// +-----+
|
---|
| 55 | /// | x |
|
---|
| 56 | /// | |
|
---|
| 57 | /// | |
|
---|
| 58 | /// +-----+
|
---|
| 59 | ///
|
---|
| 60 | /// box between(0,0) and(1,1) with singular point pareto front at a random Location
|
---|
| 61 | /// Sum of the Hypervolume to each of the corners should be 1;
|
---|
| 62 | ///
|
---|
| 63 | /// </summary>
|
---|
| 64 | [TestMethod]
|
---|
[13729] | 65 | [TestCategory("Problems.TestFunctions")]
|
---|
| 66 | [TestProperty("Time", "short")]
|
---|
[13673] | 67 | public void RandomSinglePointTest() {
|
---|
| 68 | //Front with a single Point
|
---|
| 69 | double[] point = new double[3];
|
---|
| 70 | Random r = new Random();
|
---|
| 71 |
|
---|
| 72 | point[0] = r.NextDouble();
|
---|
| 73 | point[1] = r.NextDouble();
|
---|
| 74 | point[2] = r.NextDouble();
|
---|
| 75 | double[][] front = { point };
|
---|
| 76 |
|
---|
| 77 | double[] referencePoint = new double[3];
|
---|
| 78 |
|
---|
| 79 | //Northeast
|
---|
| 80 | referencePoint[0] = 1;
|
---|
| 81 | referencePoint[1] = 1;
|
---|
| 82 | referencePoint[2] = 1;
|
---|
[13726] | 83 | double hv = MultiDimensionalHypervolume.Calculate(front, referencePoint);
|
---|
[13673] | 84 | double hv2 = 1;
|
---|
| 85 | foreach (double d in point) {
|
---|
| 86 | hv2 *= Math.Abs(d - 1);
|
---|
| 87 | }
|
---|
| 88 | Assert.AreEqual(hv2, hv);
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | /// <summary>
|
---|
| 92 | /// /*
|
---|
| 93 | /// x-----+
|
---|
| 94 | /// | |
|
---|
| 95 | /// | X |
|
---|
| 96 | /// | |
|
---|
| 97 | /// +-----x
|
---|
| 98 | ///
|
---|
| 99 | /// 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)
|
---|
| 100 | /// Hypervolume should be 0.25
|
---|
| 101 | /// </summary>
|
---|
| 102 | //[TestMethod]
|
---|
| 103 | public void DiagonalPointTest() {
|
---|
| 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 };
|
---|
[13726] | 111 | double hv = MultiDimensionalHypervolume.Calculate(front, referencePoint);
|
---|
[13673] | 112 | Assert.AreEqual(0.25, hv);
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 |
|
---|
| 116 | public void HypervolumeConsistencyTest() {
|
---|
| 117 | double[] referencePoint = new double[] { 1, 1, 1 };
|
---|
| 118 | bool[] maximization = new bool[3];
|
---|
| 119 | List<double[]> points = new List<double[]>();
|
---|
| 120 | Random r = new Random();
|
---|
| 121 | for (int i = 0; i < 100; i++) {
|
---|
| 122 | double[] p = new double[3];
|
---|
| 123 | p[0] = r.NextDouble();
|
---|
| 124 | p[1] = r.NextDouble();
|
---|
| 125 | points.Add(p);
|
---|
| 126 | }
|
---|
| 127 | var front = NonDominatedSelect.selectNonDominatedVectors(points, maximization, true);
|
---|
| 128 |
|
---|
[13726] | 129 | double dim3hv = MultiDimensionalHypervolume.Calculate(front, referencePoint);
|
---|
[13673] | 130 | double dim2hv = Hypervolume.Calculate(front, referencePoint, maximization);
|
---|
| 131 |
|
---|
| 132 |
|
---|
| 133 |
|
---|
| 134 |
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 |
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 |
|
---|
| 141 | }
|
---|