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