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