[9945] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Linq;
|
---|
| 24 | using HeuristicLab.Analysis.AlgorithmBehavior.Analyzers;
|
---|
[10222] | 25 | using HeuristicLab.Common;
|
---|
[9945] | 26 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
| 27 |
|
---|
[10081] | 28 | namespace AlgorithmBehaviorUnitTests {
|
---|
[9945] | 29 | [TestClass]
|
---|
| 30 | public class ConvexHullTest {
|
---|
| 31 | [TestMethod]
|
---|
[10222] | 32 | public void TestConvexHullAlgorithms() {
|
---|
[9945] | 33 | int nrOfSamples = 50;
|
---|
[10222] | 34 | int dimension = 4;
|
---|
| 35 | double[][] inputs = CreateRandomData(nrOfSamples, dimension);
|
---|
[9945] | 36 |
|
---|
[10222] | 37 | var lpResult = LPHull.Calculate(inputs);
|
---|
| 38 | var qhResult = QhullWrapper.Calculate(inputs.ToList());
|
---|
[9945] | 39 |
|
---|
[10222] | 40 | foreach (var qhr in qhResult) {
|
---|
[9945] | 41 | bool found = false;
|
---|
[10222] | 42 | foreach (var lpr in lpResult) {
|
---|
[9945] | 43 | int i = 0;
|
---|
[10222] | 44 | for (i = 0; i < lpr.Count(); i++) {
|
---|
| 45 | if (!qhr[i].IsAlmost(lpr[i])) {
|
---|
[9945] | 46 | break;
|
---|
| 47 | }
|
---|
| 48 | }
|
---|
[10222] | 49 | if (i == lpr.Count()) {
|
---|
[9945] | 50 | found = true;
|
---|
| 51 | break;
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 | Assert.IsTrue(found);
|
---|
| 55 | }
|
---|
| 56 | }
|
---|
| 57 |
|
---|
[10207] | 58 | public static double[][] CreateRandomData(int n, int m) {
|
---|
[9945] | 59 | double[][] result = new double[n][];
|
---|
| 60 | Random rand = new Random();
|
---|
| 61 |
|
---|
| 62 | for (int i = 0; i < n; i++) {
|
---|
| 63 | result[i] = new double[m];
|
---|
| 64 | for (int j = 0; j < m; j++) {
|
---|
| 65 | result[i][j] = (double)rand.Next(1, 60);
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 | return result;
|
---|
| 69 | }
|
---|
| 70 | }
|
---|
| 71 | }
|
---|