#region License Information
/* HeuristicLab
* Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections.Generic;
using HeuristicLab.Problems.MultiObjectiveTestFunctions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace MultiObjectiveTestfunctionTests {
[TestClass]
public class FastHypervolumeTest {
///
/// /*
/// +-----+
/// | |
/// | x |
/// | |
/// +-----+
///
/// box between(0,0,0) and(1,1,1) with singular point pareto front at(0.5,0.5,0.5)
/// Hypervolume should be 0.125;
///
///
[TestMethod]
[TestCategory("Problems.TestFunctions")]
[TestProperty("Time", "short")]
public void SinglePointTest() {
double[] point = new double[] { 0.5, 0.5, 0.5 };
double[][] front = { point };
double[] referencePoint = new double[] { 1, 1, 1 };
double hv = MultiDimensionalHypervolume.Calculate(front, referencePoint);
Assert.AreEqual(0.125, hv);
}
///
/// /*
/// +-----+
/// | x |
/// | |
/// | |
/// +-----+
///
/// box between(0,0) and(1,1) with singular point pareto front at a random Location
/// Sum of the Hypervolume to each of the corners should be 1;
///
///
[TestMethod]
[TestCategory("Problems.TestFunctions")]
[TestProperty("Time", "short")]
public void RandomSinglePointTest() {
//Front with a single Point
double[] point = new double[3];
Random r = new Random();
point[0] = r.NextDouble();
point[1] = r.NextDouble();
point[2] = r.NextDouble();
double[][] front = { point };
double[] referencePoint = new double[3];
//Northeast
referencePoint[0] = 1;
referencePoint[1] = 1;
referencePoint[2] = 1;
double hv = MultiDimensionalHypervolume.Calculate(front, referencePoint);
double hv2 = 1;
foreach (double d in point) {
hv2 *= Math.Abs(d - 1);
}
Assert.AreEqual(hv2, hv);
}
///
/// /*
/// x-----+
/// | |
/// | X |
/// | |
/// +-----x
///
/// 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)
/// Hypervolume should be 0.25
///
//[TestMethod]
public void DiagonalPointTest() {
//Front with three points
double[] point1 = new double[] { 1, 0, 0 };
double[] point2 = new double[] { 0, 1, 0 };
double[] point3 = new double[] { 0.5, 0.5, 0 };
double[][] front = { point1, point2, point3 };
double[] referencePoint = new double[] { 1, 1, 1 };
double hv = MultiDimensionalHypervolume.Calculate(front, referencePoint);
Assert.AreEqual(0.25, hv);
}
public void HypervolumeConsistencyTest() {
double[] referencePoint = new double[] { 1, 1, 1 };
bool[] maximization = new bool[3];
List points = new List();
Random r = new Random();
for (int i = 0; i < 100; i++) {
double[] p = new double[3];
p[0] = r.NextDouble();
p[1] = r.NextDouble();
points.Add(p);
}
var front = NonDominatedSelect.selectNonDominatedVectors(points, maximization, true);
double dim3hv = MultiDimensionalHypervolume.Calculate(front, referencePoint);
double dim2hv = Hypervolume.Calculate(front, referencePoint, maximization);
}
}
}