Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Tests/HeuristicLab.Problems.TestFunctions.MultiObjective-3.3/CrowdingTest.cs @ 14429

Last change on this file since 14429 was 14121, checked in by mkommend, 8 years ago

#1087: Copied unit tests from branch and adapted path of multi-objective test function project file.

File size: 4.4 KB
Line 
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
21using System;
22using Microsoft.VisualStudio.TestTools.UnitTesting;
23
24namespace HeuristicLab.Problems.TestFunctions.MultiObjective.Tests {
25  [TestClass]
26  public class CrowdingTest {
27
28    [TestMethod]
29    [ExpectedException(typeof(ArgumentException))]
30    [TestCategory("Problems.TestFunctions.MultiObjective")]
31    [TestProperty("Time", "short")]
32    public void CrowdingTestEmptyFront() {
33      double[][] front = { };
34
35      Crowding.Calculate(front, null);
36    }
37
38    [TestMethod]
39    [TestCategory("Problems.TestFunctions.MultiObjective")]
40    [TestProperty("Time", "short")]
41    public void CrowdingTestSamePoint() {
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 };
51      double dist = Crowding.Calculate(front, new double[,] { { 0, 1 }, { 0, 1 } });
52      Assert.AreEqual(double.PositiveInfinity, dist);
53    }
54
55    [TestMethod]
56    [TestCategory("Problems.TestFunctions.MultiObjective")]
57    [TestProperty("Time", "short")]
58    public void CrowdingTestSinglePoint() {
59      double[] point = new double[2];
60      point[0] = 0;
61      point[1] = 0;
62      double[][] front = { point };
63      double dist = Crowding.Calculate(front, new double[,] { { 0, 1 }, { 0, 1 } });
64      Assert.AreEqual(double.PositiveInfinity, dist);
65    }
66
67    [TestMethod]
68    [TestCategory("Problems.TestFunctions.MultiObjective")]
69    [TestProperty("Time", "short")]
70    public void CrowdingTestDiagonal() {
71      double[] point = new double[2];
72      point[0] = 0;
73      point[1] = 0;
74      double[] point1 = new double[2];
75      point1[0] = 0.5;
76      point1[1] = 0.5;
77
78      double[] point2 = new double[2];
79      point2[0] = 1;
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);
84    }
85
86    [TestMethod]
87    [TestCategory("Problems.TestFunctions.MultiObjective")]
88    [TestProperty("Time", "short")]
89    public void CrowdingTestDiamond() {
90      double[] point = new double[2];
91      point[0] = 0;
92      point[1] = 0;
93      double[] point1 = new double[2];
94      point1[0] = 1;
95      point1[1] = 1.5;
96
97      double[] point2 = new double[2];
98      point2[0] = 3;
99      point2[1] = 0.5;
100      double[] point3 = new double[2];
101      point3[0] = 4;
102      point3[1] = 2;
103      double[][] front = { point, point1, point2, point3 };
104      double dist = Crowding.Calculate(front, new double[,] { { 0, 4 }, { 0, 2 } });
105      Assert.AreEqual(1.5, dist);
106    }
107
108    /// <summary>
109    /// deltoid with 4 points of the 1-unit-square and the northeastern point at 4,4
110    ///
111    /// </summary>
112    [TestMethod]
113    [TestCategory("Problems.TestFunctions.MultiObjective")]
114    [TestProperty("Time", "short")]
115    public void CrowdingTestDeltoid() {
116      double[] point = new double[2];
117      point[0] = 0;
118      point[1] = 0;
119      double[] point1 = new double[2];
120      point1[0] = 0.00000001;         //points should not be exactly equal because sorting behaviour could change result
121      point1[1] = 1.00000001;
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;
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);
134    }
135
136
137  }
138
139
140}
Note: See TracBrowser for help on using the repository browser.