[13673] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[15584] | 3 | * Copyright (C) 2002-2018 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]
|
---|
[14030] | 26 | public class CrowdingTest {
|
---|
[13673] | 27 |
|
---|
| 28 | [TestMethod]
|
---|
| 29 | [ExpectedException(typeof(ArgumentException))]
|
---|
[14121] | 30 | [TestCategory("Problems.TestFunctions.MultiObjective")]
|
---|
[13729] | 31 | [TestProperty("Time", "short")]
|
---|
[14121] | 32 | public void CrowdingTestEmptyFront() {
|
---|
[13673] | 33 | double[][] front = { };
|
---|
| 34 |
|
---|
[14030] | 35 | Crowding.Calculate(front, null);
|
---|
[13673] | 36 | }
|
---|
| 37 |
|
---|
| 38 | [TestMethod]
|
---|
[14121] | 39 | [TestCategory("Problems.TestFunctions.MultiObjective")]
|
---|
[13729] | 40 | [TestProperty("Time", "short")]
|
---|
[14121] | 41 | public void CrowdingTestSamePoint() {
|
---|
[13673] | 42 |
|
---|
| 43 | double[] point = new double[2];
|
---|
| 44 | point[0] = 0.5;
|
---|
| 45 | point[1] = 0.5;
|
---|
| 46 |
|
---|
| 47 | double[] point1 = new double[2];
|
---|
| 48 | point1[0] = 0.5;
|
---|
| 49 | point1[1] = 0.5;
|
---|
| 50 | double[][] front = { point, point1 };
|
---|
[14030] | 51 | double dist = Crowding.Calculate(front, new double[,] { { 0, 1 }, { 0, 1 } });
|
---|
| 52 | Assert.AreEqual(double.PositiveInfinity, dist);
|
---|
[13673] | 53 | }
|
---|
| 54 |
|
---|
| 55 | [TestMethod]
|
---|
[14121] | 56 | [TestCategory("Problems.TestFunctions.MultiObjective")]
|
---|
[13729] | 57 | [TestProperty("Time", "short")]
|
---|
[14121] | 58 | public void CrowdingTestSinglePoint() {
|
---|
[13673] | 59 | double[] point = new double[2];
|
---|
| 60 | point[0] = 0;
|
---|
| 61 | point[1] = 0;
|
---|
| 62 | double[][] front = { point };
|
---|
[14030] | 63 | double dist = Crowding.Calculate(front, new double[,] { { 0, 1 }, { 0, 1 } });
|
---|
| 64 | Assert.AreEqual(double.PositiveInfinity, dist);
|
---|
[13673] | 65 | }
|
---|
| 66 |
|
---|
| 67 | [TestMethod]
|
---|
[14121] | 68 | [TestCategory("Problems.TestFunctions.MultiObjective")]
|
---|
[13729] | 69 | [TestProperty("Time", "short")]
|
---|
[14121] | 70 | public void CrowdingTestDiagonal() {
|
---|
[13673] | 71 | double[] point = new double[2];
|
---|
| 72 | point[0] = 0;
|
---|
| 73 | point[1] = 0;
|
---|
| 74 | double[] point1 = new double[2];
|
---|
[14030] | 75 | point1[0] = 0.5;
|
---|
| 76 | point1[1] = 0.5;
|
---|
[13673] | 77 |
|
---|
| 78 | double[] point2 = new double[2];
|
---|
| 79 | point2[0] = 1;
|
---|
[14030] | 80 | point2[1] = 1;
|
---|
| 81 | double[][] front = { point, point1, point2 };
|
---|
| 82 | double dist = Crowding.Calculate(front, new double[,] { { 0, 1 }, { 0, 1 } });
|
---|
| 83 | Assert.AreEqual(2, dist);
|
---|
[13673] | 84 | }
|
---|
| 85 |
|
---|
| 86 | [TestMethod]
|
---|
[14121] | 87 | [TestCategory("Problems.TestFunctions.MultiObjective")]
|
---|
[13729] | 88 | [TestProperty("Time", "short")]
|
---|
[14121] | 89 | public void CrowdingTestDiamond() {
|
---|
[13673] | 90 | double[] point = new double[2];
|
---|
| 91 | point[0] = 0;
|
---|
| 92 | point[1] = 0;
|
---|
| 93 | double[] point1 = new double[2];
|
---|
[14030] | 94 | point1[0] = 1;
|
---|
| 95 | point1[1] = 1.5;
|
---|
[13673] | 96 |
|
---|
| 97 | double[] point2 = new double[2];
|
---|
[14030] | 98 | point2[0] = 3;
|
---|
| 99 | point2[1] = 0.5;
|
---|
[13673] | 100 | double[] point3 = new double[2];
|
---|
[14030] | 101 | point3[0] = 4;
|
---|
| 102 | point3[1] = 2;
|
---|
[13673] | 103 | double[][] front = { point, point1, point2, point3 };
|
---|
[14090] | 104 | double dist = Crowding.Calculate(front, new double[,] { { 0, 4 }, { 0, 2 } });
|
---|
| 105 | Assert.AreEqual(1.5, dist);
|
---|
[13673] | 106 | }
|
---|
| 107 |
|
---|
| 108 | /// <summary>
|
---|
[14030] | 109 | /// deltoid with 4 points of the 1-unit-square and the northeastern point at 4,4
|
---|
| 110 | ///
|
---|
[13673] | 111 | /// </summary>
|
---|
| 112 | [TestMethod]
|
---|
[14121] | 113 | [TestCategory("Problems.TestFunctions.MultiObjective")]
|
---|
[13729] | 114 | [TestProperty("Time", "short")]
|
---|
[14121] | 115 | public void CrowdingTestDeltoid() {
|
---|
[13673] | 116 | double[] point = new double[2];
|
---|
| 117 | point[0] = 0;
|
---|
| 118 | point[1] = 0;
|
---|
| 119 | double[] point1 = new double[2];
|
---|
[14030] | 120 | point1[0] = 0.00000001; //points should not be exactly equal because sorting behaviour could change result
|
---|
| 121 | point1[1] = 1.00000001;
|
---|
[13673] | 122 |
|
---|
| 123 | double[] point2 = new double[2];
|
---|
| 124 | point2[0] = 1;
|
---|
| 125 | point2[1] = 0;
|
---|
| 126 | double[] point3 = new double[2];
|
---|
| 127 | point3[0] = 4;
|
---|
| 128 | point3[1] = 4;
|
---|
[14030] | 129 |
|
---|
| 130 |
|
---|
| 131 | double[][] front = { point, point1, point2, point3, };
|
---|
| 132 | double dist = Crowding.Calculate(front, new double[,] { { 0, 4 }, { 0, 4 } });
|
---|
| 133 | Assert.AreEqual(1.25, dist);
|
---|
[13673] | 134 | }
|
---|
| 135 |
|
---|
| 136 |
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 |
|
---|
| 140 | }
|
---|