#region License Information /* HeuristicLab * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using HeuristicLab.Analysis.AlgorithmBehavior.Analyzers; using MIConvexHull; namespace PerformanceTests { class Program { static int nrOfPoints = 1000; static int dimension = 10; static void Main(string[] args) { //TestConvexHullPerformance(); //TestVolumeCalculationPerformance(); TestMDSPerformance(); } public static void TestMDSPerformance() { double[][] orgPoints = new double[nrOfPoints][]; double[][] orgDm = new double[nrOfPoints][]; double[][] newPoints = null; Stopwatch watch = new Stopwatch(); AllocArray(orgPoints, dimension); AllocArray(orgDm, nrOfPoints); SamplePoints(orgPoints); CalculateDistanceMatrix(orgDm, orgPoints); watch.Start(); newPoints = DistanceMatrixToPoints.MetricMDS(orgDm, dimension); watch.Stop(); Console.WriteLine("Runtime of MetricMDS (in sec): " + watch.Elapsed.TotalSeconds); Console.ReadLine(); } public static void TestConvexHullPerformance() { List result = null; Stopwatch watch = new Stopwatch(); var data = CreateRandomData(nrOfPoints, dimension); var dataList = data.ToList(); //calculate convex hull with LP watch.Start(); result = LPHull.Calculate(data); watch.Stop(); Console.WriteLine("Runtime of LPHull (in sec): " + watch.Elapsed.TotalSeconds); //calculate convex hull with SMO watch.Restart(); result = HyperHull.Calculate(data); watch.Stop(); Console.WriteLine("Runtime of HyperHull (in sec): " + watch.Elapsed.TotalSeconds); //calculate convex hull with MIConvexHull watch.Restart(); result = ConvexHull.Create(data).Points.Select(x => x.Position).ToList(); watch.Stop(); Console.WriteLine("Runtime of MIConvexHull (in sec): " + watch.Elapsed.TotalSeconds); //calculate convex hull with QHull watch.Restart(); result = QhullWrapper.Calculate(dataList); watch.Stop(); Console.WriteLine("Runtime of QHull (in sec): " + watch.Elapsed.TotalSeconds); Console.ReadLine(); } public static void TestVolumeCalculationPerformance() { var data = CreateRandomData(nrOfPoints, dimension); var dataList = data.ToList(); List convexHull = null; double volume = 0.0; Stopwatch watch = new Stopwatch(); //calculate volume with LP and then use QHull watch.Start(); convexHull = LPHull.Calculate(data); volume = QhullWrapper.CalculateVolume(convexHull); watch.Stop(); Console.WriteLine(Environment.NewLine + "## Runtime of LPHull/QHull (sec): " + watch.Elapsed.TotalSeconds); //Console.WriteLine("Volume of convex hull is: " + volume); //calculate volume with QHull watch.Restart(); volume = QhullWrapper.CalculateVolume(dataList); watch.Stop(); Console.WriteLine(Environment.NewLine + "## Runtime of QHull (sec): " + watch.Elapsed.TotalSeconds); //Console.WriteLine("Volume of convex hull is: " + volume); //calculate volume of data with delauny triangulation watch.Restart(); volume = ConvexHullMeasures.CalculateVolume(dataList); watch.Stop(); Console.WriteLine(Environment.NewLine + "## Runtime using all data with delauny (sec): " + watch.Elapsed.TotalSeconds); //Console.WriteLine("Volume of convex hull is: " + volume); //calculate volume with convex hull (LPHull) and delauny triangulation watch.Restart(); convexHull = LPHull.Calculate(data); volume = ConvexHullMeasures.CalculateVolume(convexHull); watch.Stop(); Console.WriteLine(Environment.NewLine + "## Runtime using convex hull and delauny (sec): " + watch.Elapsed.TotalSeconds); //Console.WriteLine("Volume of convex hull is: " + volume); Console.ReadLine(); } private static double[][] CreateRandomData(int n, int m) { double[][] result = new double[n][]; Random rand = new Random(); for (int i = 0; i < n; i++) { result[i] = new double[m]; for (int j = 0; j < m; j++) { result[i][j] = (double)rand.Next(1, 60); } } return result; } private static void CalculateDistanceMatrix(double[][] dm, double[][] points) { for (int i = 0; i < points.Length; i++) { for (int j = 0; j < points.Length; j++) { dm[i][j] = points[i].EuclideanDistance(points[j]); } } } private static void AllocArray(double[][] arr, int size) { for (int i = 0; i < arr.Length; i++) { arr[i] = new double[size]; } } private static void SamplePoints(double[][] points) { Random rand = new Random(); for (int i = 0; i < points.Length; i++) { for (int j = 0; j < points[i].Length; j++) { points[i][j] = rand.NextDouble() * 100; } } } } }