[9945] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Diagnostics;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using System.Windows.Forms;
|
---|
| 26 | using HeuristicLab.Analysis.AlgorithmBehavior.Analyzers;
|
---|
| 27 | using MIConvexHull;
|
---|
| 28 |
|
---|
| 29 | namespace Visualization {
|
---|
| 30 | static class Program {
|
---|
| 31 | /// <summary>
|
---|
| 32 | /// The main entry point for the application.
|
---|
| 33 | /// </summary>
|
---|
| 34 | [STAThread]
|
---|
| 35 | static void Main() {
|
---|
| 36 | Application.EnableVisualStyles();
|
---|
| 37 | Application.SetCompatibleTextRenderingDefault(false);
|
---|
| 38 |
|
---|
| 39 | int nrOfSamples = 100;
|
---|
| 40 | int sampleSize = 100;
|
---|
| 41 | double[][] inputs = CreateRandomData(nrOfSamples, sampleSize);
|
---|
| 42 |
|
---|
| 43 | Stopwatch watch = new Stopwatch();
|
---|
| 44 | watch.Start();
|
---|
[10224] | 45 | var result2 = HyperHull.Calculate(inputs);
|
---|
[9945] | 46 | watch.Stop();
|
---|
| 47 | Console.WriteLine("HyperHull: " + watch.ElapsedMilliseconds);
|
---|
| 48 | watch.Restart();
|
---|
[10224] | 49 | var result1 = ConvexHull.Create(inputs).Points.Select(x => x.Position).ToList();
|
---|
[9945] | 50 | watch.Stop();
|
---|
| 51 | Console.WriteLine("MIConvexHull: " + watch.ElapsedMilliseconds);
|
---|
| 52 |
|
---|
| 53 | int k = 0;
|
---|
| 54 | foreach (var d in result1) {
|
---|
| 55 | bool found = false;
|
---|
| 56 | foreach (var e in result2) {
|
---|
| 57 | int i = 0;
|
---|
| 58 | for (i = 0; i < e.Count(); i++) {
|
---|
| 59 | if (d[i] != e[i]) {
|
---|
| 60 | break;
|
---|
| 61 | }
|
---|
| 62 | }
|
---|
| 63 | if (i == e.Count()) {
|
---|
| 64 | found = true;
|
---|
| 65 | k++;
|
---|
| 66 | break;
|
---|
| 67 | }
|
---|
| 68 | }
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | VisualizationForm vis = new VisualizationForm();
|
---|
| 72 | vis.Text = "Ratio: " + k + "/" + result1.Count;
|
---|
| 73 | vis.Inputs = inputs;
|
---|
| 74 | vis.ConvexHull1 = result1;
|
---|
| 75 | vis.ConvexHull2 = result2;
|
---|
| 76 | Application.Run(vis);
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | private static double[][] CreateRandomData(int n, int m) {
|
---|
| 80 | double[][] result = new double[n][];
|
---|
| 81 | Random rand = new Random();
|
---|
| 82 |
|
---|
| 83 | for (int i = 0; i < n; i++) {
|
---|
| 84 | result[i] = new double[m];
|
---|
| 85 | for (int j = 0; j < m; j++) {
|
---|
| 86 | result[i][j] = (double)rand.Next(1, 240);
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | return result;
|
---|
| 91 | }
|
---|
| 92 | }
|
---|
| 93 | }
|
---|