[13673] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17180] | 3 | * Copyright (C) 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 GenerationalDistanceTest {
|
---|
| 27 |
|
---|
| 28 | [TestMethod]
|
---|
| 29 | [ExpectedException(typeof(ArgumentException))]
|
---|
[14121] | 30 | [TestCategory("Problems.TestFunctions.MultiObjective")]
|
---|
[13729] | 31 | [TestProperty("Time", "short")]
|
---|
[14121] | 32 | public void GenerationalDistanceTestEmptyOptimalFront() {
|
---|
[13673] | 33 |
|
---|
| 34 | double[] point = new double[2];
|
---|
| 35 | point[0] = 0.5;
|
---|
| 36 | point[1] = 0.5;
|
---|
| 37 | double[][] front = { point };
|
---|
| 38 | double[][] referencefront = { };
|
---|
| 39 | GenerationalDistance.Calculate(front, referencefront, 1);
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | [TestMethod]
|
---|
| 43 | [ExpectedException(typeof(ArgumentException))]
|
---|
[14121] | 44 | [TestCategory("Problems.TestFunctions.MultiObjective")]
|
---|
[13729] | 45 | [TestProperty("Time", "short")]
|
---|
[14121] | 46 | public void GenerationalDistanceTestEmptyFront() {
|
---|
[13673] | 47 |
|
---|
| 48 | double[] point = new double[2];
|
---|
| 49 | point[0] = 0.5;
|
---|
| 50 | point[1] = 0.5;
|
---|
| 51 | double[][] front = { };
|
---|
| 52 | double[][] referencefront = { point };
|
---|
| 53 | GenerationalDistance.Calculate(front, referencefront, 1);
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | [TestMethod]
|
---|
[14121] | 57 | [TestCategory("Problems.TestFunctions.MultiObjective")]
|
---|
[13729] | 58 | [TestProperty("Time", "short")]
|
---|
[14121] | 59 | public void GenerationalDistanceTestSamePoint() {
|
---|
[13673] | 60 |
|
---|
| 61 | double[] point = new double[2];
|
---|
| 62 | point[0] = 0.5;
|
---|
| 63 | point[1] = 0.5;
|
---|
| 64 | double[][] front = { point };
|
---|
| 65 | double[] point1 = new double[2];
|
---|
| 66 | point1[0] = 0.5;
|
---|
| 67 | point1[1] = 0.5;
|
---|
| 68 | double[][] referencefront = { point1 };
|
---|
| 69 | double dist = GenerationalDistance.Calculate(front, referencefront, 1);
|
---|
| 70 | Assert.AreEqual(0, dist);
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | [TestMethod]
|
---|
[14121] | 74 | [TestCategory("Problems.TestFunctions.MultiObjective")]
|
---|
[13729] | 75 | [TestProperty("Time", "short")]
|
---|
[14121] | 76 | public void GenerationalDistanceTestSinglePoint() {
|
---|
[13673] | 77 | double[] point = new double[2];
|
---|
| 78 | point[0] = 0;
|
---|
| 79 | point[1] = 0;
|
---|
| 80 | double[][] front = { point };
|
---|
| 81 | double[] point2 = new double[2];
|
---|
| 82 | point2[0] = 1;
|
---|
| 83 | point2[1] = 1;
|
---|
| 84 | double[][] referencefront = { point2 };
|
---|
| 85 | double dist = GenerationalDistance.Calculate(front, referencefront, 1);
|
---|
| 86 | Assert.AreEqual(Math.Sqrt(2), dist);
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | [TestMethod]
|
---|
[14121] | 90 | [TestCategory("Problems.TestFunctions.MultiObjective")]
|
---|
[13729] | 91 | [TestProperty("Time", "short")]
|
---|
[14121] | 92 | public void GenerationalDistanceTestDifferentSizes() {
|
---|
[13673] | 93 | double[] point = new double[2];
|
---|
| 94 | point[0] = 0;
|
---|
| 95 | point[1] = 0;
|
---|
| 96 | double[] point1 = new double[2];
|
---|
| 97 | point1[0] = 1;
|
---|
| 98 | point1[1] = 0.5;
|
---|
| 99 | double[][] front = { point, point1 };
|
---|
| 100 | double[] point2 = new double[2];
|
---|
| 101 | point2[0] = 1;
|
---|
| 102 | point2[1] = 0;
|
---|
| 103 | double[][] referencefront = { point2 };
|
---|
| 104 | double dist = GenerationalDistance.Calculate(front, referencefront, 1);
|
---|
| 105 | Assert.AreEqual(0.75, dist);
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | [TestMethod]
|
---|
[14121] | 109 | [TestCategory("Problems.TestFunctions.MultiObjective")]
|
---|
[13729] | 110 | [TestProperty("Time", "short")]
|
---|
[14121] | 111 | public void GenerationalDistanceTestQuadratic() {
|
---|
[13673] | 112 | double[] point = new double[2];
|
---|
| 113 | point[0] = 0;
|
---|
| 114 | point[1] = 0;
|
---|
| 115 | double[] point1 = new double[2];
|
---|
| 116 | point1[0] = 0;
|
---|
| 117 | point1[1] = 1;
|
---|
| 118 | double[][] front = { point, point1 };
|
---|
| 119 | double[] point2 = new double[2];
|
---|
| 120 | point2[0] = 1;
|
---|
| 121 | point2[1] = 0;
|
---|
| 122 | double[] point3 = new double[2];
|
---|
| 123 | point3[0] = 1;
|
---|
| 124 | point3[1] = 1;
|
---|
| 125 | double[][] referencefront = { point2, point3 };
|
---|
| 126 | double dist = GenerationalDistance.Calculate(front, referencefront, 1);
|
---|
| 127 | Assert.AreEqual(1, dist);
|
---|
| 128 | }
|
---|
| 129 | }
|
---|
| 130 | }
|
---|