Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10222 for branches


Ignore:
Timestamp:
12/11/13 23:36:52 (11 years ago)
Author:
ascheibe
Message:

#1886

  • improved qhull wrapper
  • cleaned up unit tests
Location:
branches/HeuristicLab.Analysis.AlgorithmBehavior
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/AlgorithmBehaviorUnitTests/AlgorithmBehaviorUnitTests.csproj

    r10207 r10222  
    2626    <ErrorReport>prompt</ErrorReport>
    2727    <WarningLevel>4</WarningLevel>
     28    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
    2829  </PropertyGroup>
    2930  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/AlgorithmBehaviorUnitTests/ConvexHullTest.cs

    r10207 r10222  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Diagnostics;
    2523using System.Linq;
    2624using HeuristicLab.Analysis.AlgorithmBehavior.Analyzers;
    27 using MIConvexHull;
     25using HeuristicLab.Common;
    2826using Microsoft.VisualStudio.TestTools.UnitTesting;
    2927
     
    3230  public class ConvexHullTest {
    3331    [TestMethod]
    34     public void TestMethod1() {
     32    public void TestConvexHullAlgorithms() {
    3533      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);
    3936
    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());
    4939
    50       int k = 0;
    51       foreach (var d in result1) {
     40      foreach (var qhr in qhResult) {
    5241        bool found = false;
    53         foreach (var e in result2) {
     42        foreach (var lpr in lpResult) {
    5443          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])) {
    5746              break;
    5847            }
    5948          }
    60           if (i == e.Count()) {
     49          if (i == lpr.Count()) {
    6150            found = true;
    62             k++;
    6351            break;
    6452          }
     
    6654        Assert.IsTrue(found);
    6755      }
    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;
    8356    }
    8457
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/AlgorithmBehaviorUnitTests/LPConvexHullTest.cs

    r10198 r10222  
    3535      int nrOfSamples = 70;
    3636      int sampleSize = 2;
    37       double[][] inputs = CreateRandomData(nrOfSamples, sampleSize);
     37      double[][] inputs = ConvexHullTest.CreateRandomData(nrOfSamples, sampleSize);
    3838      var convAlgData = ConvertPermutationToVertex(inputs);
    3939
     
    151151      return result;
    152152    }
    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     }
    166153  }
    167154}
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/AlgorithmBehaviorUnitTests/VolumeCalculationTest.cs

    r10208 r10222  
    3131    [TestMethod]
    3232    public void TestVolumeCalculation() {
    33       const int numPoints = 8;
    34       const int dimension = 3;
    35 
    3633      var points = new List<double[]>();
    3734      points.Add(new double[] { -0.72045174, 1.44667601, -1.75159125 });
     
    5451    }
    5552
    56 
    5753    [TestMethod]
    5854    public void TestVolumeCalculationQhull() {
    59       const int numPoints = 8;
    60       const int dimension = 3;
    61 
    6255      var points = new List<double[]>();
    6356      points.Add(new double[] { -0.72045174, 1.44667601, -1.75159125 });
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/QhullWrapper.cs

    r10211 r10222  
    2727namespace HeuristicLab.Analysis.AlgorithmBehavior.Analyzers {
    2828  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
    2938    public static double CalculateVolume(List<double[]> points) {
    3039      double result = 0.0;
     
    4352    }
    4453
    45     public unsafe static List<int> CalculateConvexHull(List<double[]> points) {
     54    public unsafe static List<int> CalculateConvexHullIndices(List<double[]> points) {
    4655      int dimension = points.First().Length;
    4756      int numPoints = points.Count();
     
    7382    }
    7483
    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    }
    8392  }
    8493}
  • branches/HeuristicLab.Analysis.AlgorithmBehavior/PerformanceTests/Program.cs

    r10211 r10222  
    3030    static void Main(string[] args) {
    3131      // TestSimpleVolumeCalculation();
    32       //   TestVolCalc();
     32      // TestVolCalc();
    3333      //TestQHullVolumeCalculation();
    3434      TestQhull();
     
    5050      Console.WriteLine("Volume is: " + volume);
    5151
    52       QhullWrapper.CalculateConvexHull(points);
     52      var result = QhullWrapper.Calculate(points);
    5353    }
    5454
Note: See TracChangeset for help on using the changeset viewer.