Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2913_MatlabScriptProblemInstanceProvider/HeuristicLab.Problems.Instances.DataAnalysis.Views/3.3/RegressionInstanceProviderView.cs @ 16752

Last change on this file since 16752 was 15912, checked in by rhanghof, 7 years ago

#2913:

  • Added a RegressionInstanceProvider for Matlab instances.
  • Added an import dialog for importing Matlab data.
  • Added some classes which represents different Matlab specific datatypes.
  • Added a Matlab connector which contains a set of commands for interacting with the Matlab bridge.
File size: 4.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 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.Threading.Tasks;
24using System.Windows.Forms;
25using HeuristicLab.MainForm;
26using HeuristicLab.Problems.DataAnalysis;
27using HeuristicLab.Problems.Instances.DataAnalysis.Regression.Matlab;
28using HeuristicLab.Problems.Instances.DataAnalysis.Views.Regression.Matlab;
29
30namespace HeuristicLab.Problems.Instances.DataAnalysis.Views {
31  [View("Regression InstanceProvider View")]
32  [Content(typeof(RegressionInstanceProvider), IsDefaultView = true)]
33  public partial class RegressionInstanceProviderView : DataAnalysisInstanceProviderView<IRegressionProblemData> {
34
35    public new RegressionInstanceProvider Content {
36      get { return (RegressionInstanceProvider)base.Content; }
37      set { base.Content = value; }
38    }
39
40    public RegressionInstanceProviderView() {
41      InitializeComponent();
42    }
43
44    protected override void importButton_Click(object sender, EventArgs e) {
45      if (Content is RegressionMatlabInstanceProvider) {
46        ImportMatlabData();
47      } else {
48        ImportCSVData();
49      }
50    }
51
52    private void ImportCSVData() {
53      var importTypeDialog = new RegressionImportDialog();
54      if (importTypeDialog.ShowDialog() == DialogResult.OK) {
55        IRegressionProblemData instance = null;
56
57        Task.Factory.StartNew(() => {
58          var mainForm = (MainForm.WindowsForms.MainForm)MainFormManager.MainForm;
59          // lock active view and show progress bar
60          IContentView activeView = (IContentView)MainFormManager.MainForm.ActiveView;
61
62          try {
63            var progress = mainForm.AddOperationProgressToContent(activeView.Content,
64              "Loading problem instance.");
65
66            Content.ProgressChanged +=
67              (o, args) => { progress.ProgressValue = args.ProgressPercentage / 100.0; };
68
69            instance = Content.ImportData(importTypeDialog.Path, importTypeDialog.ImportType,
70              importTypeDialog.CSVFormat);
71          } catch (Exception ex) {
72            ErrorWhileParsing(ex);
73            return;
74          } finally {
75            mainForm.RemoveOperationProgressFromContent(activeView.Content);
76          }
77
78          try {
79            GenericConsumer.Load(instance);
80          } catch (Exception ex) {
81            ErrorWhileLoading(ex, importTypeDialog.Path);
82          } finally {
83            Invoke((Action)(() => instancesComboBox.SelectedIndex = -1));
84          }
85        });
86      }
87    }
88
89
90    private void ImportMatlabData() {
91      var importTypeDialog = new RegressionMatlabImportDialog();
92      if (importTypeDialog.ShowDialog() == DialogResult.OK) {
93        IRegressionProblemData instance = null;
94
95        Task.Factory.StartNew(() => {
96          var mainForm = (MainForm.WindowsForms.MainForm)MainFormManager.MainForm;
97          // lock active view and show progress bar
98          IContentView activeView = (IContentView)MainFormManager.MainForm.ActiveView;
99
100          try {
101            var progress = mainForm.AddOperationProgressToContent(activeView.Content,
102              "Loading problem instance.");
103
104            Content.ProgressChanged +=
105              (o, args) => { progress.ProgressValue = args.ProgressPercentage / 100.0; };
106
107            instance = (Content as RegressionMatlabInstanceProvider).ImportData(importTypeDialog.Path, importTypeDialog.ImportType, importTypeDialog.SelectedVariables);
108          } catch (Exception ex) {
109            ErrorWhileParsing(ex);
110            return;
111          } finally {
112            mainForm.RemoveOperationProgressFromContent(activeView.Content);
113          }
114
115          try {
116            GenericConsumer.Load(instance);
117          } catch (Exception ex) {
118            ErrorWhileLoading(ex, importTypeDialog.Path);
119          } finally {
120            Invoke((Action)(() => instancesComboBox.SelectedIndex = -1));
121          }
122        });
123      }
124    }   
125  }
126}
Note: See TracBrowser for help on using the repository browser.