[5829] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[7259] | 3 | * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[5829] | 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 |
|
---|
[7338] | 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
[7347] | 24 | using System.Linq;
|
---|
| 25 | using System.Text;
|
---|
[5829] | 26 | using System.Windows.Forms;
|
---|
[6666] | 27 | using HeuristicLab.Core;
|
---|
[5829] | 28 | using HeuristicLab.MainForm;
|
---|
[7487] | 29 | using HeuristicLab.Persistence.Core;
|
---|
[7338] | 30 | using HeuristicLab.Persistence.Default.Xml;
|
---|
| 31 | using HeuristicLab.PluginInfrastructure;
|
---|
[7487] | 32 | using ICSharpCode.SharpZipLib.Zip;
|
---|
[5829] | 33 |
|
---|
| 34 | namespace HeuristicLab.Problems.DataAnalysis.Views {
|
---|
[5834] | 35 | [View("RegressionSolution View")]
|
---|
[6652] | 36 | [Content(typeof(RegressionSolutionBase), false)]
|
---|
[5829] | 37 | public partial class RegressionSolutionView : DataAnalysisSolutionView {
|
---|
| 38 | public RegressionSolutionView() {
|
---|
| 39 | InitializeComponent();
|
---|
| 40 | }
|
---|
| 41 |
|
---|
[6597] | 42 | public new RegressionSolutionBase Content {
|
---|
| 43 | get { return (RegressionSolutionBase)base.Content; }
|
---|
[5829] | 44 | set { base.Content = value; }
|
---|
| 45 | }
|
---|
[6653] | 46 |
|
---|
| 47 | #region drag and drop
|
---|
| 48 | protected override void itemsListView_DragEnter(object sender, DragEventArgs e) {
|
---|
| 49 | validDragOperation = false;
|
---|
[6666] | 50 | if (ReadOnly) return;
|
---|
| 51 |
|
---|
| 52 | var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
|
---|
| 53 | if (dropData is RegressionProblemData) validDragOperation = true;
|
---|
| 54 | else if (dropData is IValueParameter) {
|
---|
| 55 | var param = (IValueParameter)dropData;
|
---|
| 56 | if (param.Value is RegressionProblemData) validDragOperation = true;
|
---|
[6653] | 57 | }
|
---|
| 58 | }
|
---|
| 59 | #endregion
|
---|
[7338] | 60 |
|
---|
[7487] | 61 | protected void importButton_Click(object sender, EventArgs e) {
|
---|
[8032] | 62 | if (Locked || ReadOnly || Content == null) {
|
---|
| 63 | MessageBox.Show("The Regression Solution is read-only or locked. Save the solution and open it again or use " +
|
---|
| 64 | "the 'Simplify' button to get a copy of the current solution. Import will then be enabled.");
|
---|
| 65 | return;
|
---|
| 66 | }
|
---|
[7468] | 67 | if (openFileDialog.ShowDialog(this) != DialogResult.OK) return;
|
---|
[7487] | 68 | ImportProblemData(openFileDialog.FileName);
|
---|
| 69 | }
|
---|
[7347] | 70 |
|
---|
[7487] | 71 | protected void ImportProblemData(string filename) {
|
---|
[7468] | 72 | object hlFile = null;
|
---|
| 73 | try {
|
---|
[7487] | 74 | hlFile = XmlParser.Deserialize(filename);
|
---|
[7468] | 75 | }
|
---|
[7487] | 76 | catch (PersistenceException ex) {
|
---|
[7468] | 77 | ErrorHandling.ShowErrorDialog(this, ex);
|
---|
| 78 | return;
|
---|
| 79 | }
|
---|
[7487] | 80 | catch (ZipException ex) {
|
---|
| 81 | ErrorHandling.ShowErrorDialog(this, ex);
|
---|
| 82 | return;
|
---|
| 83 | }
|
---|
[7338] | 84 |
|
---|
[7468] | 85 | IRegressionProblemData problemData = null;
|
---|
| 86 | if (hlFile is IRegressionProblemData) {
|
---|
| 87 | problemData = (IRegressionProblemData)hlFile;
|
---|
| 88 | } else if (hlFile is IRegressionProblem) {
|
---|
| 89 | problemData = ((IRegressionProblem)hlFile).ProblemData;
|
---|
| 90 | } else if (hlFile is IRegressionSolution) {
|
---|
| 91 | problemData = ((IRegressionSolution)hlFile).ProblemData;
|
---|
| 92 | }
|
---|
[7338] | 93 |
|
---|
[7468] | 94 | if (problemData == null) {
|
---|
[7487] | 95 | ErrorHandling.ShowErrorDialog(this, new NullReferenceException("The problem data is null." + Environment.NewLine
|
---|
| 96 | + "The .hl-file is no RegressionProblemData or RegressionProblem."));
|
---|
[7468] | 97 | return;
|
---|
| 98 | }
|
---|
[7399] | 99 |
|
---|
[7487] | 100 | if (CheckCompatibilityOfProblemData(Content.ProblemData, problemData))
|
---|
| 101 | Content.ProblemData = problemData;
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | protected virtual bool CheckCompatibilityOfProblemData(IRegressionProblemData iRegressionProblemData, IRegressionProblemData problemData) {
|
---|
[7468] | 105 | StringBuilder message = new StringBuilder();
|
---|
| 106 | if (!problemData.TargetVariable.Equals(Content.ProblemData.TargetVariable))
|
---|
| 107 | message.AppendLine("The target variables are not matching. Old target variable: '"
|
---|
| 108 | + Content.ProblemData.TargetVariable
|
---|
| 109 | + "'. New targetvariable: '" + problemData.TargetVariable + "'");
|
---|
[7399] | 110 |
|
---|
[7468] | 111 | List<string> variables = problemData.InputVariables.Select(x => x.Value).ToList();
|
---|
| 112 | foreach (var item in Content.ProblemData.InputVariables.CheckedItems) {
|
---|
| 113 | if (!variables.Contains(item.Value.Value))
|
---|
| 114 | message.AppendLine("Input variable '" + item.Value.Value + "' is not in the new problem data.");
|
---|
[7338] | 115 | }
|
---|
[7468] | 116 |
|
---|
[7487] | 117 | if (message.Length != 0) {
|
---|
| 118 | ErrorHandling.ShowErrorDialog(this, new InvalidOperationException(message.ToString()));
|
---|
| 119 | return false;
|
---|
| 120 | }
|
---|
| 121 | return true;
|
---|
[7338] | 122 | }
|
---|
[5829] | 123 | }
|
---|
| 124 | }
|
---|