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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.ComponentModel;
|
---|
25 | using System.Drawing;
|
---|
26 | using System.Data;
|
---|
27 | using System.Text;
|
---|
28 | using System.Windows.Forms;
|
---|
29 | using HeuristicLab.Core;
|
---|
30 | using HeuristicLab.Data;
|
---|
31 | using HeuristicLab.Operators;
|
---|
32 | using HeuristicLab.DataAnalysis;
|
---|
33 |
|
---|
34 | namespace 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;
|
---|
66 | datasetView.Dataset = dataset;
|
---|
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;
|
---|
85 | dataset.Rows = parser.TrainingSamplesEnd - parser.TrainingSamplesStart;
|
---|
86 | dataset.Columns = parser.Columns;
|
---|
87 | dataset.VariableNames = parser.VariableNames;
|
---|
88 | dataset.Name = parser.ProblemName;
|
---|
89 | dataset.Samples = new double[dataset.Rows * dataset.Columns];
|
---|
90 | Array.Copy(parser.Samples, dataset.Samples, dataset.Columns * dataset.Rows);
|
---|
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 | }
|
---|