[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 |
|
---|
| 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 | 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;
|
---|
[131] | 90 | dataset.Rows = parser.TrainingSamplesEnd - parser.TrainingSamplesStart;
|
---|
[2] | 91 | dataset.Columns = parser.Columns;
|
---|
| 92 | dataset.VariableNames = parser.VariableNames;
|
---|
| 93 | dataset.Name = parser.ProblemName;
|
---|
[131] | 94 | dataset.Samples = new double[dataset.Rows * dataset.Columns];
|
---|
| 95 | Array.Copy(parser.Samples, dataset.Samples, dataset.Columns * dataset.Rows);
|
---|
[2] | 96 |
|
---|
| 97 | ((IntData)StructIdProblemInjector.GetVariable("TargetVariable").Value).Data = parser.TargetVariable;
|
---|
| 98 | ((IntData)StructIdProblemInjector.GetVariable("MaxTreeHeight").Value).Data = parser.MaxTreeHeight;
|
---|
| 99 | ((IntData)StructIdProblemInjector.GetVariable("MaxTreeSize").Value).Data = parser.MaxTreeSize;
|
---|
| 100 | Refresh();
|
---|
| 101 | }
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
| 104 | }
|
---|
| 105 | }
|
---|