Changeset 10222
- Timestamp:
- 12/11/13 23:36:52 (11 years ago)
- Location:
- branches/HeuristicLab.Analysis.AlgorithmBehavior
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Analysis.AlgorithmBehavior/AlgorithmBehaviorUnitTests/AlgorithmBehaviorUnitTests.csproj
r10207 r10222 26 26 <ErrorReport>prompt</ErrorReport> 27 27 <WarningLevel>4</WarningLevel> 28 <AllowUnsafeBlocks>true</AllowUnsafeBlocks> 28 29 </PropertyGroup> 29 30 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> -
branches/HeuristicLab.Analysis.AlgorithmBehavior/AlgorithmBehaviorUnitTests/ConvexHullTest.cs
r10207 r10222 21 21 22 22 using System; 23 using System.Collections.Generic;24 using System.Diagnostics;25 23 using System.Linq; 26 24 using HeuristicLab.Analysis.AlgorithmBehavior.Analyzers; 27 using MIConvexHull;25 using HeuristicLab.Common; 28 26 using Microsoft.VisualStudio.TestTools.UnitTesting; 29 27 … … 32 30 public class ConvexHullTest { 33 31 [TestMethod] 34 public void Test Method1() {32 public void TestConvexHullAlgorithms() { 35 33 int nrOfSamples = 50; 36 int sampleSize = 120; 37 double[][] inputs = CreateRandomData(nrOfSamples, sampleSize); 38 var convAlgData = ConvertPermutationToVertex(inputs); 34 int dimension = 4; 35 double[][] inputs = CreateRandomData(nrOfSamples, dimension); 39 36 40 Stopwatch watch = new Stopwatch(); 41 watch.Start(); 42 var result2 = HyperHull.CalculateUsingSMO(inputs); 43 watch.Stop(); 44 Console.WriteLine("HyperHull: " + watch.ElapsedMilliseconds); 45 watch.Restart(); 46 var result1 = ConvexHull.Create(convAlgData).Points.Select(x => x.Position).ToList(); 47 watch.Stop(); 48 Console.WriteLine("MIConvexHull: " + watch.ElapsedMilliseconds); 37 var lpResult = LPHull.Calculate(inputs); 38 var qhResult = QhullWrapper.Calculate(inputs.ToList()); 49 39 50 int k = 0; 51 foreach (var d in result1) { 40 foreach (var qhr in qhResult) { 52 41 bool found = false; 53 foreach (var e in result2) {42 foreach (var lpr in lpResult) { 54 43 int i = 0; 55 for (i = 0; i < e.Count(); i++) {56 if ( d[i] != e[i]) {44 for (i = 0; i < lpr.Count(); i++) { 45 if (!qhr[i].IsAlmost(lpr[i])) { 57 46 break; 58 47 } 59 48 } 60 if (i == e.Count()) {49 if (i == lpr.Count()) { 61 50 found = true; 62 k++;63 51 break; 64 52 } … … 66 54 Assert.IsTrue(found); 67 55 } 68 Console.WriteLine("Ratio: " + k + "/" + result1.Count);69 Assert.AreEqual(k, result1.Count);70 }71 72 private List<DefaultVertex> ConvertPermutationToVertex(double[][] data) {73 List<DefaultVertex> result = new List<DefaultVertex>();74 for (int i = 0; i < data.Count(); i++) {75 double[] d = data[i];76 77 DefaultVertex vertex = new DefaultVertex();78 vertex.Position = d;79 result.Add(vertex);80 81 }82 return result;83 56 } 84 57 -
branches/HeuristicLab.Analysis.AlgorithmBehavior/AlgorithmBehaviorUnitTests/LPConvexHullTest.cs
r10198 r10222 35 35 int nrOfSamples = 70; 36 36 int sampleSize = 2; 37 double[][] inputs = C reateRandomData(nrOfSamples, sampleSize);37 double[][] inputs = ConvexHullTest.CreateRandomData(nrOfSamples, sampleSize); 38 38 var convAlgData = ConvertPermutationToVertex(inputs); 39 39 … … 151 151 return result; 152 152 } 153 154 private double[][] CreateRandomData(int n, int m) {155 double[][] result = new double[n][];156 Random rand = new Random();157 158 for (int i = 0; i < n; i++) {159 result[i] = new double[m];160 for (int j = 0; j < m; j++) {161 result[i][j] = (double)rand.Next(1, 60);162 }163 }164 return result;165 }166 153 } 167 154 } -
branches/HeuristicLab.Analysis.AlgorithmBehavior/AlgorithmBehaviorUnitTests/VolumeCalculationTest.cs
r10208 r10222 31 31 [TestMethod] 32 32 public void TestVolumeCalculation() { 33 const int numPoints = 8;34 const int dimension = 3;35 36 33 var points = new List<double[]>(); 37 34 points.Add(new double[] { -0.72045174, 1.44667601, -1.75159125 }); … … 54 51 } 55 52 56 57 53 [TestMethod] 58 54 public void TestVolumeCalculationQhull() { 59 const int numPoints = 8;60 const int dimension = 3;61 62 55 var points = new List<double[]>(); 63 56 points.Add(new double[] { -0.72045174, 1.44667601, -1.75159125 }); -
branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/QhullWrapper.cs
r10211 r10222 27 27 namespace HeuristicLab.Analysis.AlgorithmBehavior.Analyzers { 28 28 public static class QhullWrapper { 29 [System.Runtime.InteropServices.DllImportAttribute("HeuristicLab.qhull.dll", EntryPoint = "qhull_volume", CallingConvention = CallingConvention.Cdecl)] 30 public static extern double qhull_volume(int dim, int numpoints, [In]double[] data); 31 32 [System.Runtime.InteropServices.DllImportAttribute("HeuristicLab.qhull.dll", EntryPoint = "qhull_convex_hull", CallingConvention = CallingConvention.Cdecl)] 33 public unsafe static extern IntPtr qhull_convex_hull(int dim, int numpoints, [In]double[] data, [Out] Int32* retCode, [Out] Int32* nrOfFacets); 34 35 [System.Runtime.InteropServices.DllImportAttribute("HeuristicLab.qhull.dll", EntryPoint = "qhull_free", CallingConvention = CallingConvention.Cdecl)] 36 public static extern void qhull_free(IntPtr data); 37 29 38 public static double CalculateVolume(List<double[]> points) { 30 39 double result = 0.0; … … 43 52 } 44 53 45 public unsafe static List<int> CalculateConvexHull (List<double[]> points) {54 public unsafe static List<int> CalculateConvexHullIndices(List<double[]> points) { 46 55 int dimension = points.First().Length; 47 56 int numPoints = points.Count(); … … 73 82 } 74 83 75 [System.Runtime.InteropServices.DllImportAttribute("HeuristicLab.qhull.dll", EntryPoint = "qhull_volume", CallingConvention = CallingConvention.Cdecl)]76 public static extern double qhull_volume(int dim, int numpoints, [In]double[] data);77 78 [System.Runtime.InteropServices.DllImportAttribute("HeuristicLab.qhull.dll", EntryPoint = "qhull_convex_hull", CallingConvention = CallingConvention.Cdecl)]79 public unsafe static extern IntPtr qhull_convex_hull(int dim, int numpoints, [In]double[] data, [Out] Int32* retCode, [Out] Int32* nrOfFacets);80 81 [System.Runtime.InteropServices.DllImportAttribute("HeuristicLab.qhull.dll", EntryPoint = "qhull_free", CallingConvention = CallingConvention.Cdecl)]82 public static extern void qhull_free(IntPtr data);84 public static List<double[]> Calculate(List<double[]> points) { 85 var ret = new List<double[]>(); 86 List<int> indices = CalculateConvexHullIndices(points); 87 foreach (var d in indices) { 88 ret.Add(points[d]); 89 } 90 return ret; 91 } 83 92 } 84 93 } -
branches/HeuristicLab.Analysis.AlgorithmBehavior/PerformanceTests/Program.cs
r10211 r10222 30 30 static void Main(string[] args) { 31 31 // TestSimpleVolumeCalculation(); 32 // 32 // TestVolCalc(); 33 33 //TestQHullVolumeCalculation(); 34 34 TestQhull(); … … 50 50 Console.WriteLine("Volume is: " + volume); 51 51 52 QhullWrapper.CalculateConvexHull(points);52 var result = QhullWrapper.Calculate(points); 53 53 } 54 54
Note: See TracChangeset
for help on using the changeset viewer.