Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1886 added a wrapper for calculating the convex hull using qhull

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