Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.StructureIdentification/StructIdProblemInjectorView.cs @ 123

Last change on this file since 123 was 2, checked in by swagner, 17 years ago

Added HeuristicLab 3.0 sources from former SVN repository at revision 52

File size: 4.1 KB
RevLine 
[2]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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.ComponentModel;
25using System.Drawing;
26using System.Data;
27using System.Text;
28using System.Windows.Forms;
29using HeuristicLab.Core;
30using HeuristicLab.Data;
31using HeuristicLab.Operators;
32using HeuristicLab.DataAnalysis;
33
34namespace HeuristicLab.StructureIdentification {
35  public partial class StructIdProblemInjectorView : ViewBase {
36    public StructIdProblemInjector StructIdProblemInjector {
37      get { return (StructIdProblemInjector)Item; }
38      set { base.Item = value; }
39    }
40
41    public StructIdProblemInjectorView() {
42      InitializeComponent();
43    }
44    public StructIdProblemInjectorView(StructIdProblemInjector structIdProblemInjector)
45      : this() {
46      StructIdProblemInjector = structIdProblemInjector;
47    }
48
49    protected override void RemoveItemEvents() {
50      operatorBaseVariableInfosView.Operator = null;
51      operatorBaseDescriptionView.Operator = null;
52      base.RemoveItemEvents();
53    }
54    protected override void AddItemEvents() {
55      base.AddItemEvents();
56      operatorBaseVariableInfosView.Operator = StructIdProblemInjector;
57      operatorBaseDescriptionView.Operator = StructIdProblemInjector;
58    }
59
60    protected override void UpdateControls() {
61      base.UpdateControls();
62      if (StructIdProblemInjector == null) {
63        nameTextBox.Text = "-";
64        variablesTextBox.Text = "-";
65        samplesTextBox.Text = "-";
66        importInstanceButton.Enabled = false;
67      } else {
68        Dataset dataset = (Dataset)StructIdProblemInjector.GetVariable("Dataset").Value;
69        nameTextBox.Text = dataset.Name;
70        samplesTextBox.Text = dataset.Rows+"";
71        variablesTextBox.Text = dataset.Columns+"";
72        importInstanceButton.Enabled = true;
73      }
74    }
75
76    private void importInstanceButton_Click(object sender, EventArgs e) {
77      if (openFileDialog.ShowDialog(this) == DialogResult.OK) {
78        DatasetParser parser = new DatasetParser();
79        bool success = false;
80        try {
81          parser.Import(openFileDialog.FileName, true);
82          success = true;
83        } catch (Exception) {
84          // not possible to parse strictly => try to parse non-strict
85          parser.Import(openFileDialog.FileName, false);
86          success = true;
87        }
88        if (success) {
89          Dataset dataset = (Dataset)StructIdProblemInjector.GetVariable("Dataset").Value;
90          dataset.Rows = parser.Rows;
91          dataset.Columns = parser.Columns;
92          dataset.VariableNames = parser.VariableNames;
93          dataset.Name = parser.ProblemName;
94          dataset.Samples = parser.Samples;
95
96          ((IntData)StructIdProblemInjector.GetVariable("TargetVariable").Value).Data = parser.TargetVariable;
97          ((IntData)StructIdProblemInjector.GetVariable("MaxTreeHeight").Value).Data = parser.MaxTreeHeight;
98          ((IntData)StructIdProblemInjector.GetVariable("MaxTreeSize").Value).Data = parser.MaxTreeSize;
99          ((IntData)StructIdProblemInjector.GetVariable("TrainingSamplesStart").Value).Data = parser.TrainingSamplesStart;
100          ((IntData)StructIdProblemInjector.GetVariable("TrainingSamplesEnd").Value).Data = parser.TrainingSamplesEnd;
101          Refresh();
102        }
103      }
104    }
105  }
106}
Note: See TracBrowser for help on using the repository browser.