Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.0/sources/HeuristicLab.StructureIdentification/StructIdProblemInjectorView.cs @ 942

Last change on this file since 942 was 278, checked in by gkronber, 17 years ago

merged changesets r166 r168 r195:196 r209 from the trunk into the stable branch

File size: 3.8 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        importInstanceButton.Enabled = false;
64      } else {
65        Dataset dataset = (Dataset)StructIdProblemInjector.GetVariable("Dataset").Value;
[278]66        datasetView.Dataset = dataset;
[2]67        importInstanceButton.Enabled = true;
68      }
69    }
70
71    private void importInstanceButton_Click(object sender, EventArgs e) {
72      if (openFileDialog.ShowDialog(this) == DialogResult.OK) {
73        DatasetParser parser = new DatasetParser();
74        bool success = false;
75        try {
76          parser.Import(openFileDialog.FileName, true);
77          success = true;
78        } catch (Exception) {
79          // not possible to parse strictly => try to parse non-strict
80          parser.Import(openFileDialog.FileName, false);
81          success = true;
82        }
83        if (success) {
84          Dataset dataset = (Dataset)StructIdProblemInjector.GetVariable("Dataset").Value;
[131]85          dataset.Rows = parser.TrainingSamplesEnd - parser.TrainingSamplesStart;
[2]86          dataset.Columns = parser.Columns;
87          dataset.VariableNames = parser.VariableNames;
88          dataset.Name = parser.ProblemName;
[131]89          dataset.Samples = new double[dataset.Rows * dataset.Columns];
90          Array.Copy(parser.Samples, dataset.Samples, dataset.Columns * dataset.Rows);
[2]91
92          ((IntData)StructIdProblemInjector.GetVariable("TargetVariable").Value).Data = parser.TargetVariable;
93          ((IntData)StructIdProblemInjector.GetVariable("MaxTreeHeight").Value).Data = parser.MaxTreeHeight;
94          ((IntData)StructIdProblemInjector.GetVariable("MaxTreeSize").Value).Data = parser.MaxTreeSize;
95          Refresh();
96        }
97      }
98    }
99  }
100}
Note: See TracBrowser for help on using the repository browser.