Free cookie consent management tool by TermsFeed Policy Generator

source: branches/RegressionBenchmarks/HeuristicLab.Problems.DataAnalysis.Views/3.4/BenchmarkGeneratorDialog.cs @ 7308

Last change on this file since 7308 was 7308, checked in by sforsten, 12 years ago

#1669: added a dialog to select benchmark problems

File size: 4.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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;
24using System.Collections.Generic;
25using System.Linq;
26using System.Windows.Forms;
27using HeuristicLab.Common;
28using HeuristicLab.PluginInfrastructure;
29
30namespace HeuristicLab.Problems.DataAnalysis.Views {
31  internal partial class BenchmarkGeneratorDialog : Form {
32    private bool initialized;
33
34    private IDataAnalysisProblem Content;
35
36    private IDataAnalysisProblemData problemData;
37    public IDataAnalysisProblemData ProblemData {
38      get {
39        return problemData;
40      }
41    }
42
43    public BenchmarkGeneratorDialog(IDataAnalysisProblem Content) {
44      initialized = false;
45      InitializeComponent();
46      this.Content = Content;
47    }
48
49    private void NewItemDialog_Load(object sender, EventArgs e) {
50      if (!initialized) {
51        IEnumerable<IDataAnalysisBenchmarkProblemDataGenerator> generators = new List<IDataAnalysisBenchmarkProblemDataGenerator>();
52        if (Content is IRegressionProblem)
53          generators = ApplicationManager.Manager.GetInstances<IRegressionBenchmarkProblemDataGenerator>();
54        else if (Content is IClassificationProblem)
55          generators = ApplicationManager.Manager.GetInstances<IClassificationBenchmarkProblemDataGenerator>();
56        else if (Content is IClusteringProblem)
57          generators = ApplicationManager.Manager.GetInstances<IClusteringBenchmarkProblemDataGenerator>();
58
59        IOrderedEnumerable<IDataAnalysisBenchmarkProblemDataGenerator> bla = generators.OrderBy(b => b.Name, new NaturalStringComparer());
60
61        foreach (var generator in bla) {
62          ListViewItem item = new ListViewItem(new string[] { generator.Name, generator.Description });
63          item.Tag = generator;
64          BenchmarkGeneratorListView.Items.Add(item);
65        }
66
67        BenchmarkGeneratorListView.ListViewItemSorter = new ListViewItemComparer();
68
69        for (int i = 0; i < BenchmarkGeneratorListView.Columns.Count; i++)
70          BenchmarkGeneratorListView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
71
72        initialized = true;
73      }
74    }
75
76    private void NewItemDialog_Shown(object sender, EventArgs e) {
77      problemData = null;
78    }
79
80    private void BenchmarkGeneratorListView_SelectedIndexChanged(object sender, EventArgs e) {
81      okButton.Enabled = BenchmarkGeneratorListView.SelectedItems.Count == 1;
82    }
83
84    private void okButton_Click(object sender, EventArgs e) {
85      if (BenchmarkGeneratorListView.SelectedItems.Count == 1) {
86        problemData = ((IDataAnalysisBenchmarkProblemDataGenerator)BenchmarkGeneratorListView.SelectedItems[0].Tag).GenerateProblemData();
87        DialogResult = DialogResult.OK;
88        Close();
89      }
90    }
91
92    private void BenchmarkGeneratorListView_DoubleClick(object sender, EventArgs e) {
93      if (BenchmarkGeneratorListView.SelectedItems.Count == 1) {
94        problemData = ((IDataAnalysisBenchmarkProblemDataGenerator)BenchmarkGeneratorListView.SelectedItems[0].Tag).GenerateProblemData();
95        DialogResult = DialogResult.OK;
96        Close();
97      }
98    }
99
100    private class ListViewItemComparer : IComparer {
101      private NaturalStringComparer comp = new NaturalStringComparer();
102
103      public int Compare(object x, object y) {
104        return comp.Compare(((ListViewItem)x).SubItems[0].Text, ((ListViewItem)y).SubItems[0].Text);
105      }
106    }
107  }
108}
Note: See TracBrowser for help on using the repository browser.