Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1886

  • added more performance tests
  • tried to mute qhull
File size: 5.9 KB
Line 
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;
24using System.Diagnostics;
25using System.Linq;
26using HeuristicLab.Analysis.AlgorithmBehavior.Analyzers;
27using MIConvexHull;
28
29namespace PerformanceTests {
30  class Program {
31
32    static int nrOfPoints = 1000;
33    static int dimension = 10;
34
35    static void Main(string[] args) {
36      //TestConvexHullPerformance();
37      //TestVolumeCalculationPerformance();
38
39      TestMDSPerformance();
40    }
41
42    public static void TestMDSPerformance() {
43      double[][] orgPoints = new double[nrOfPoints][];
44      double[][] orgDm = new double[nrOfPoints][];
45      double[][] newPoints = null;
46      Stopwatch watch = new Stopwatch();
47
48      AllocArray(orgPoints, dimension);
49      AllocArray(orgDm, nrOfPoints);
50      SamplePoints(orgPoints);
51      CalculateDistanceMatrix(orgDm, orgPoints);
52
53      watch.Start();
54      newPoints = DistanceMatrixToPoints.MetricMDS(orgDm, dimension);
55      watch.Stop();
56      Console.WriteLine("Runtime of MetricMDS (in sec): " + watch.Elapsed.TotalSeconds);
57
58      Console.ReadLine();
59    }
60
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
69      watch.Start();
70      result = LPHull.Calculate(data);
71      watch.Stop();
72      Console.WriteLine("Runtime of LPHull (in sec): " + watch.Elapsed.TotalSeconds);
73
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);
79
80      //calculate convex hull with MIConvexHull
81      watch.Restart();
82      result = ConvexHull.Create(data).Points.Select(x => x.Position).ToList();
83      watch.Stop();
84      Console.WriteLine("Runtime of MIConvexHull (in sec): " + watch.Elapsed.TotalSeconds);
85
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);
91
92      Console.ReadLine();
93    }
94
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;
100      Stopwatch watch = new Stopwatch();
101
102
103      //calculate volume with LP and then use QHull
104      watch.Start();
105      convexHull = LPHull.Calculate(data);
106      volume = QhullWrapper.CalculateVolume(convexHull);
107      watch.Stop();
108      Console.WriteLine(Environment.NewLine + "## Runtime of LPHull/QHull (sec): " + watch.Elapsed.TotalSeconds);
109      //Console.WriteLine("Volume of convex hull is: " + volume);
110
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);
117
118      //calculate volume of data with delauny triangulation
119      watch.Restart();
120      volume = ConvexHullMeasures.CalculateVolume(dataList);
121      watch.Stop();
122      Console.WriteLine(Environment.NewLine + "## Runtime using all data with delauny (sec): " + watch.Elapsed.TotalSeconds);
123      //Console.WriteLine("Volume of convex hull is: " + volume);
124
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);
132
133      Console.ReadLine();
134    }
135
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    }
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    }
172  }
173}
Note: See TracBrowser for help on using the repository browser.