Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Analysis.AlgorithmBehavior/Visualization/Program.cs @ 10198

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

#1886

  • added liblrs and c# wrapper for vertex enumeration/volume calculation
  • use MIConvexHull for triangulation and volume calculation
  • fixed vertex conversion code for MIConvexHull lib
  • added a unit test for measuring performance of convex hull/volume calculation
File size: 3.3 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 System.Windows.Forms;
27using HeuristicLab.Analysis.AlgorithmBehavior.Analyzers;
28using MIConvexHull;
29
30namespace 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        DefaultVertex vertex = new DefaultVertex();
88        vertex.Position = d;
89        result.Add(vertex);
90
91      }
92      return result;
93    }
94
95    private static double[][] CreateRandomData(int n, int m) {
96      double[][] result = new double[n][];
97      Random rand = new Random();
98
99      for (int i = 0; i < n; i++) {
100        result[i] = new double[m];
101        for (int j = 0; j < m; j++) {
102          result[i][j] = (double)rand.Next(1, 240);
103        }
104      }
105
106      return result;
107    }
108  }
109}
Note: See TracBrowser for help on using the repository browser.