Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Analysis.AlgorithmBehavior/AlgorithmBehaviorUnitTests/LPConvexHullTest.cs @ 10224

Last change on this file since 10224 was 10224, checked in by ascheibe, 10 years ago

#1886

  • added more performance tests
  • tried to mute qhull
File size: 4.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 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
22using System;
23using System.Diagnostics;
24using System.Linq;
25using HeuristicLab.Analysis.AlgorithmBehavior.Analyzers;
26using MIConvexHull;
27using Microsoft.VisualStudio.TestTools.UnitTesting;
28
29namespace AlgorithmBehaviorUnitTests {
30  [TestClass]
31  public class LPConvexHullTest {
32    [TestMethod]
33    public void TestMethod1() {
34      int nrOfSamples = 70;
35      int sampleSize = 2;
36      double[][] inputs = ConvexHullTest.CreateRandomData(nrOfSamples, sampleSize);
37
38      Stopwatch watch = new Stopwatch();
39      watch.Start();
40      var result2 = LPHull.Calculate(inputs);
41      watch.Stop();
42      Console.WriteLine("LPHull: " + watch.ElapsedMilliseconds);
43      watch.Restart();
44      var result1 = ConvexHull.Create(inputs).Points.Select(x => x.Position).ToList();
45      watch.Stop();
46      Console.WriteLine("MIConvexHull: " + watch.ElapsedMilliseconds);
47
48      int k = 0;
49      foreach (var d in result1) {
50        bool found = false;
51        foreach (var e in result2) {
52          int i = 0;
53          for (i = 0; i < e.Count(); i++) {
54            if (d[i] != e[i]) {
55              break;
56            }
57          }
58          if (i == e.Count()) {
59            found = true;
60            k++;
61            break;
62          }
63        }
64        Assert.IsTrue(found);
65      }
66      Console.WriteLine("Ratio: " + k + "/" + result1.Count);
67      Assert.AreEqual(k, result1.Count);
68    }
69
70    [TestMethod]
71    public void TestExt() {
72      var inputs = CreateDataExtremePoint1().ToList();
73      double[] alpha = inputs.Last();
74      bool result = LPHull.EXT(inputs, alpha, inputs.Count() - 1);
75      Assert.IsTrue(result);
76
77      inputs = CreateDataExtremePoint2().ToList();
78      alpha = inputs.Last();
79      result = LPHull.EXT(inputs, alpha, inputs.Count() - 1);
80      Assert.IsTrue(result);
81
82      inputs = CreateDataNonExtremePoint1().ToList();
83      alpha = inputs.Last();
84      result = LPHull.EXT(inputs, alpha, inputs.Count() - 1);
85      Assert.IsFalse(result);
86
87      inputs = CreateDataOnHull().ToList();
88      alpha = inputs.Last();
89      result = LPHull.EXT(inputs, alpha, inputs.Count() - 1);
90      Assert.IsFalse(result);
91    }
92
93    private double[][] CreateDataExtremePoint1() {
94      double[][] result = new double[5][];
95
96      result[0] = new double[] { 0.1, 0.1 };
97      result[1] = new double[] { 1, 1 };
98      result[2] = new double[] { 1, 0 };
99      result[3] = new double[] { 0, 1 };
100      result[4] = new double[] { 2.0, 1.4 };
101
102      return result;
103    }
104
105    private double[][] CreateDataExtremePoint2() {
106      double[][] result = new double[5][];
107
108      result[0] = new double[] { 0.1, 0.1 };
109      result[1] = new double[] { 1, 1 };
110      result[2] = new double[] { 1, 0 };
111      result[3] = new double[] { 0, 1 };
112      result[4] = new double[] { 1.0, 1.4 };
113
114      return result;
115    }
116
117    private double[][] CreateDataNonExtremePoint1() {
118      double[][] result = new double[5][];
119
120      result[0] = new double[] { 0.1, 0.1 };
121      result[1] = new double[] { 1, 1 };
122      result[2] = new double[] { 1, 0 };
123      result[3] = new double[] { 0, 1 };
124      result[4] = new double[] { 0.8, 0.4 };
125
126      return result;
127    }
128
129    private double[][] CreateDataOnHull() {
130      double[][] result = new double[5][];
131
132      result[0] = new double[] { 0.1, 0.1 };
133      result[1] = new double[] { 1, 1 };
134      result[2] = new double[] { 1, 0 };
135      result[3] = new double[] { 0, 1 };
136      result[4] = new double[] { 1.0, 0.5 };
137
138      return result;
139    }
140  }
141}
Note: See TracBrowser for help on using the repository browser.