#region License Information /* HeuristicLab * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using HeuristicLab.Analysis.AlgorithmBehavior.Analyzers; using MIConvexHull; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace AlgorithmBehaviorUnitTests { [TestClass] public class ConvexHullTest { [TestMethod] public void TestMethod1() { int nrOfSamples = 50; int sampleSize = 120; double[][] inputs = CreateRandomData(nrOfSamples, sampleSize); var convAlgData = ConvertPermutationToVertex(inputs); Stopwatch watch = new Stopwatch(); watch.Start(); var result2 = HyperHull.CalculateUsingSMO(inputs); watch.Stop(); Console.WriteLine("HyperHull: " + watch.ElapsedMilliseconds); watch.Restart(); var result1 = ConvexHull.Create(convAlgData).Points.Select(x => x.Position).ToList(); watch.Stop(); Console.WriteLine("MIConvexHull: " + watch.ElapsedMilliseconds); int k = 0; foreach (var d in result1) { bool found = false; foreach (var e in result2) { int i = 0; for (i = 0; i < e.Count(); i++) { if (d[i] != e[i]) { break; } } if (i == e.Count()) { found = true; k++; break; } } Assert.IsTrue(found); } Console.WriteLine("Ratio: " + k + "/" + result1.Count); Assert.AreEqual(k, result1.Count); } private List ConvertPermutationToVertex(double[][] data) { List result = new List(); for (int i = 0; i < data.Count(); i++) { double[] d = data[i]; DefaultVertex vertex = new DefaultVertex(); vertex.Position = d; result.Add(vertex); } return result; } public static double[][] CreateRandomData(int n, int m) { double[][] result = new double[n][]; Random rand = new Random(); for (int i = 0; i < n; i++) { result[i] = new double[m]; for (int j = 0; j < m; j++) { result[i][j] = (double)rand.Next(1, 60); } } return result; } } }