1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 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;
|
---|
22 | using HeuristicLab.Analysis;
|
---|
23 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
24 |
|
---|
25 | namespace HeuristicLab.Analysis.MultiObjective.Tests {
|
---|
26 | [TestClass]
|
---|
27 | public class GenerationalDistanceTest {
|
---|
28 |
|
---|
29 | [TestMethod]
|
---|
30 | [ExpectedException(typeof(ArgumentException))]
|
---|
31 | [TestCategory("Analysis.MultiObjective")]
|
---|
32 | [TestProperty("Time", "short")]
|
---|
33 | public void GenerationalDistanceTestEmptyOptimalFront() {
|
---|
34 |
|
---|
35 | double[] point = new double[2];
|
---|
36 | point[0] = 0.5;
|
---|
37 | point[1] = 0.5;
|
---|
38 | double[][] front = { point };
|
---|
39 | double[][] referencefront = { };
|
---|
40 | GenerationalDistanceAnalyzer.CalculateGenerationalDistance(front, referencefront, 1);
|
---|
41 | }
|
---|
42 |
|
---|
43 | [TestMethod]
|
---|
44 | [ExpectedException(typeof(ArgumentException))]
|
---|
45 | [TestCategory("Analysis.MultiObjective")]
|
---|
46 | [TestProperty("Time", "short")]
|
---|
47 | public void GenerationalDistanceTestEmptyFront() {
|
---|
48 |
|
---|
49 | double[] point = new double[2];
|
---|
50 | point[0] = 0.5;
|
---|
51 | point[1] = 0.5;
|
---|
52 | double[][] front = { };
|
---|
53 | double[][] referencefront = { point };
|
---|
54 | GenerationalDistanceAnalyzer.CalculateGenerationalDistance(front, referencefront, 1);
|
---|
55 | }
|
---|
56 |
|
---|
57 | [TestMethod]
|
---|
58 | [TestCategory("Analysis.MultiObjective")]
|
---|
59 | [TestProperty("Time", "short")]
|
---|
60 | public void GenerationalDistanceTestSamePoint() {
|
---|
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 };
|
---|
70 | double dist = GenerationalDistanceAnalyzer.CalculateGenerationalDistance(front, referencefront, 1);
|
---|
71 | Assert.AreEqual(0, dist);
|
---|
72 | }
|
---|
73 |
|
---|
74 | [TestMethod]
|
---|
75 | [TestCategory("Analysis.MultiObjective")]
|
---|
76 | [TestProperty("Time", "short")]
|
---|
77 | public void GenerationalDistanceTestSinglePoint() {
|
---|
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 };
|
---|
86 | double dist = GenerationalDistanceAnalyzer.CalculateGenerationalDistance(front, referencefront, 1);
|
---|
87 | Assert.AreEqual(Math.Sqrt(2), dist);
|
---|
88 | }
|
---|
89 |
|
---|
90 | [TestMethod]
|
---|
91 | [TestCategory("Analysis.MultiObjective")]
|
---|
92 | [TestProperty("Time", "short")]
|
---|
93 | public void GenerationalDistanceTestDifferentSizes() {
|
---|
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 };
|
---|
105 | double dist = GenerationalDistanceAnalyzer.CalculateGenerationalDistance(front, referencefront, 1);
|
---|
106 | Assert.AreEqual(0.75, dist);
|
---|
107 | }
|
---|
108 |
|
---|
109 | [TestMethod]
|
---|
110 | [TestCategory("Analysis.MultiObjective")]
|
---|
111 | [TestProperty("Time", "short")]
|
---|
112 | public void GenerationalDistanceTestQuadratic() {
|
---|
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 };
|
---|
127 | double dist = GenerationalDistanceAnalyzer.CalculateGenerationalDistance(front, referencefront, 1);
|
---|
128 | Assert.AreEqual(1, dist);
|
---|
129 | }
|
---|
130 | }
|
---|
131 | }
|
---|