Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 10208 was 10208, checked in by ascheibe, 10 years ago

#1886

  • added x64 configurations for qhull
  • added a wrapper for qhull volume calculation
  • removed old volume calculation code
File size: 6.6 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;
27
28namespace PerformanceTests {
29  class Program {
30    static void Main(string[] args) {
31      // TestSimpleVolumeCalculation();
32      //   TestVolCalc();
33      //TestQHullVolumeCalculation();
34      TestQhull();
35    }
36
37    public static void TestQhull() {
38      var points = new List<double[]>();
39      points.Add(new double[] { -0.72045174, 1.44667601, -1.75159125 });
40      points.Add(new double[] { -0.67521503, 0.61127293, -0.33962646 });
41      points.Add(new double[] { 2.02392510, -0.41962562, -1.12211942 });
42      points.Add(new double[] { 0.02647963, -0.24983950, -0.47038916 });
43      points.Add(new double[] { 0.61548803, -0.25039511, 0.97745744 });
44      points.Add(new double[] { -1.65142294, -0.09537136, 1.93154268 });
45      points.Add(new double[] { 1.12618422, 0.49384888, 0.05286691 });
46      points.Add(new double[] { -0.12506782, -2.29161965, -0.09710301 });
47
48      double volume = QhullWrapper.CalculateVolume(points);
49      volume = Math.Round(volume, 6);
50      Console.WriteLine("Volume is: " + volume);
51    }
52
53
54    public static void TestVolCalc() {
55      int dim = 3;
56      int size = 8;
57      var data = CreateRandomData(size, dim);
58      var dataList = data.ToList();
59      Stopwatch watch = new Stopwatch();
60
61
62      //calculate convex hull
63      watch.Start();
64      var convexHull = LPHull.Calculate(data);
65      watch.Stop();
66      Console.WriteLine("Convex hull calculation took : " + watch.Elapsed.TotalSeconds + " seconds.");
67
68
69      //calculate volume of convex hull
70      watch.Start();
71      double volume = ConvexHullMeasures.CalculateVolume(convexHull);
72      watch.Stop();
73      Console.WriteLine("Volume calculation of convex hull took : " + watch.Elapsed.TotalSeconds + " seconds.");
74      Console.WriteLine("Volume of convex hull is: " + volume);
75
76
77      //do volume calculation from the whole data set
78      watch.Start();
79      volume = ConvexHullMeasures.CalculateVolume(dataList);
80      watch.Stop();
81      Console.WriteLine("Volume calculation of whole data set took : " + watch.Elapsed.TotalSeconds + " seconds.");
82      Console.WriteLine("Volume of whole data is: " + volume);
83
84
85      //do volume calculation with lrs
86      watch.Start();
87      volume = LiblrsWrapper.CalculateVolume(dataList);
88      watch.Stop();
89      Console.WriteLine("Volume calculation of whole data set with lrs took : " + watch.Elapsed.TotalSeconds + " seconds.");
90      Console.WriteLine("Volume of whole data with lrs is: " + volume);
91    }
92
93    private static void TestQHullVolumeCalculation() {
94      const int numPoints = 8;
95      const int dimension = 3;
96
97      var points = new List<double[]>();
98
99      points.Add(new double[] { -0.72045174, 1.44667601, -1.75159125 });
100      points.Add(new double[] { -0.67521503, 0.61127293, -0.33962646 });
101      points.Add(new double[] { 2.02392510, -0.41962562, -1.12211942 });
102      points.Add(new double[] { 0.02647963, -0.24983950, -0.47038916 });
103      points.Add(new double[] { 0.61548803, -0.25039511, 0.97745744 });
104      points.Add(new double[] { -1.65142294, -0.09537136, 1.93154268 });
105      points.Add(new double[] { 1.12618422, 0.49384888, 0.05286691 });
106      points.Add(new double[] { -0.12506782, -2.29161965, -0.09710301 });
107
108      Stopwatch watch = new Stopwatch();
109      //calculate convex hull
110      watch.Start();
111      var convexHull = LPHull.Calculate(points.ToArray());
112      watch.Stop();
113      Console.WriteLine("Convex hull calculation took : " + watch.Elapsed.TotalSeconds + " seconds.");
114
115
116      //calculate volume of convex hull
117      watch.Start();
118      double volume = ConvexHullMeasures.CalculateVolume(convexHull);
119      watch.Stop();
120      Console.WriteLine("Volume calculation of convex hull took : " + watch.Elapsed.TotalSeconds + " seconds.");
121      Console.WriteLine("Volume of convex hull is: " + volume);  //7.960698
122
123
124      //do volume calculation from the whole data set
125      watch.Start();
126      volume = ConvexHullMeasures.CalculateVolume(points);
127      watch.Stop();
128      Console.WriteLine("Volume calculation of whole data set took : " + watch.Elapsed.TotalSeconds + " seconds.");
129      Console.WriteLine("Volume of whole data is: " + volume);
130
131
132      //do volume calculation with lrs
133      watch = new Stopwatch();
134      watch.Start();
135      volume = LiblrsWrapper.CalculateVolume(points);
136      watch.Stop();
137      Console.WriteLine("Volume calculation of whole data set with lrs took : " + watch.Elapsed.TotalSeconds + " seconds.");
138      Console.WriteLine("Volume of whole data with lrs is: " + volume);
139    }
140
141    private static void TestSimpleVolumeCalculation() {
142      const int numPoints = 4;
143      const int dimension = 3;
144
145      double[] num1 = new double[dimension];
146      double[] num2 = new double[dimension];
147      double[] num3 = new double[dimension];
148      double[] num4 = new double[dimension];
149
150      num1[0] = 1;
151      num1[1] = 2;
152      num1[2] = 2;
153
154      num2[0] = 3;
155      num2[1] = 4;
156      num2[2] = 3;
157
158      num3[0] = 3;
159      num3[1] = 6;
160      num3[2] = 3;
161
162      num4[0] = 7;
163      num4[1] = 8;
164      num4[2] = 3;
165
166      var points = new List<double[]>();
167      points.Add(num1);
168      points.Add(num2);
169      points.Add(num3);
170      points.Add(num4);
171
172
173      double volume = ConvexHullMeasures.CalculateSimplexVolume(points);
174
175    }
176
177    private static double[][] CreateRandomData(int n, int m) {
178      double[][] result = new double[n][];
179      Random rand = new Random();
180
181      for (int i = 0; i < n; i++) {
182        result[i] = new double[m];
183        for (int j = 0; j < m; j++) {
184          result[i][j] = (double)rand.Next(1, 60);
185        }
186      }
187      return result;
188    }
189  }
190}
Note: See TracBrowser for help on using the repository browser.