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