Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Analysis.AlgorithmBehavior/PerformanceTests/Program.cs @ 11512

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

#1886

  • added more performance tests
  • tried to mute qhull
File size: 5.9 KB
RevLine 
[10208]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.Collections.Generic;
[10200]24using System.Diagnostics;
25using System.Linq;
26using HeuristicLab.Analysis.AlgorithmBehavior.Analyzers;
[10224]27using MIConvexHull;
[10200]28
29namespace PerformanceTests {
30  class Program {
31
[10224]32    static int nrOfPoints = 1000;
33    static int dimension = 10;
[10208]34
[10224]35    static void Main(string[] args) {
36      //TestConvexHullPerformance();
37      //TestVolumeCalculationPerformance();
[10211]38
[10224]39      TestMDSPerformance();
[10208]40    }
41
[10224]42    public static void TestMDSPerformance() {
43      double[][] orgPoints = new double[nrOfPoints][];
44      double[][] orgDm = new double[nrOfPoints][];
45      double[][] newPoints = null;
[10200]46      Stopwatch watch = new Stopwatch();
47
[10224]48      AllocArray(orgPoints, dimension);
49      AllocArray(orgDm, nrOfPoints);
50      SamplePoints(orgPoints);
51      CalculateDistanceMatrix(orgDm, orgPoints);
[10200]52
53      watch.Start();
[10224]54      newPoints = DistanceMatrixToPoints.MetricMDS(orgDm, dimension);
[10200]55      watch.Stop();
[10224]56      Console.WriteLine("Runtime of MetricMDS (in sec): " + watch.Elapsed.TotalSeconds);
[10200]57
[10224]58      Console.ReadLine();
59    }
[10200]60
[10224]61    public static void TestConvexHullPerformance() {
62      List<double[]> result = null;
63      Stopwatch watch = new Stopwatch();
64
65      var data = CreateRandomData(nrOfPoints, dimension);
66      var dataList = data.ToList();
67
68      //calculate convex hull with LP
[10200]69      watch.Start();
[10224]70      result = LPHull.Calculate(data);
[10200]71      watch.Stop();
[10224]72      Console.WriteLine("Runtime of LPHull (in sec): " + watch.Elapsed.TotalSeconds);
[10200]73
[10224]74      //calculate convex hull with SMO
75      watch.Restart();
76      result = HyperHull.Calculate(data);
77      watch.Stop();
78      Console.WriteLine("Runtime of HyperHull (in sec): " + watch.Elapsed.TotalSeconds);
[10200]79
[10224]80      //calculate convex hull with MIConvexHull
81      watch.Restart();
82      result = ConvexHull.Create(data).Points.Select(x => x.Position).ToList();
[10200]83      watch.Stop();
[10224]84      Console.WriteLine("Runtime of MIConvexHull (in sec): " + watch.Elapsed.TotalSeconds);
[10200]85
[10224]86      //calculate convex hull with QHull
87      watch.Restart();
88      result = QhullWrapper.Calculate(dataList);
89      watch.Stop();
90      Console.WriteLine("Runtime of QHull (in sec): " + watch.Elapsed.TotalSeconds);
[10208]91
[10224]92      Console.ReadLine();
93    }
[10208]94
[10224]95    public static void TestVolumeCalculationPerformance() {
96      var data = CreateRandomData(nrOfPoints, dimension);
97      var dataList = data.ToList();
98      List<double[]> convexHull = null;
99      double volume = 0.0;
[10208]100      Stopwatch watch = new Stopwatch();
101
102
[10224]103      //calculate volume with LP and then use QHull
[10208]104      watch.Start();
[10224]105      convexHull = LPHull.Calculate(data);
106      volume = QhullWrapper.CalculateVolume(convexHull);
[10208]107      watch.Stop();
[10224]108      Console.WriteLine(Environment.NewLine + "## Runtime of LPHull/QHull (sec): " + watch.Elapsed.TotalSeconds);
109      //Console.WriteLine("Volume of convex hull is: " + volume);
[10208]110
[10224]111      //calculate volume with QHull
112      watch.Restart();
113      volume = QhullWrapper.CalculateVolume(dataList);
114      watch.Stop();
115      Console.WriteLine(Environment.NewLine + "## Runtime of QHull (sec): " + watch.Elapsed.TotalSeconds);
116      //Console.WriteLine("Volume of convex hull is: " + volume);
[10208]117
[10224]118      //calculate volume of data with delauny triangulation
119      watch.Restart();
120      volume = ConvexHullMeasures.CalculateVolume(dataList);
[10208]121      watch.Stop();
[10224]122      Console.WriteLine(Environment.NewLine + "## Runtime using all data with delauny (sec): " + watch.Elapsed.TotalSeconds);
123      //Console.WriteLine("Volume of convex hull is: " + volume);
[10208]124
[10224]125      //calculate volume with convex hull (LPHull) and delauny triangulation
126      watch.Restart();
127      convexHull = LPHull.Calculate(data);
128      volume = ConvexHullMeasures.CalculateVolume(convexHull);
129      watch.Stop();
130      Console.WriteLine(Environment.NewLine + "## Runtime using convex hull and delauny (sec): " + watch.Elapsed.TotalSeconds);
131      //Console.WriteLine("Volume of convex hull is: " + volume);
[10208]132
[10224]133      Console.ReadLine();
[10208]134    }
135
[10200]136    private static double[][] CreateRandomData(int n, int m) {
137      double[][] result = new double[n][];
138      Random rand = new Random();
139
140      for (int i = 0; i < n; i++) {
141        result[i] = new double[m];
142        for (int j = 0; j < m; j++) {
143          result[i][j] = (double)rand.Next(1, 60);
144        }
145      }
146      return result;
147    }
[10224]148
149    private static void CalculateDistanceMatrix(double[][] dm, double[][] points) {
150      for (int i = 0; i < points.Length; i++) {
151        for (int j = 0; j < points.Length; j++) {
152          dm[i][j] = points[i].EuclideanDistance(points[j]);
153        }
154      }
155    }
156
157    private static void AllocArray(double[][] arr, int size) {
158      for (int i = 0; i < arr.Length; i++) {
159        arr[i] = new double[size];
160      }
161    }
162
163    private static void SamplePoints(double[][] points) {
164      Random rand = new Random();
165
166      for (int i = 0; i < points.Length; i++) {
167        for (int j = 0; j < points[i].Length; j++) {
168          points[i][j] = rand.NextDouble() * 100;
169        }
170      }
171    }
[10200]172  }
173}
Note: See TracBrowser for help on using the repository browser.