Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.CEDMA.Server/3.3/DispatcherView.cs @ 2601

Last change on this file since 2601 was 2471, checked in by gkronber, 15 years ago

Fixed #786 (Allowed algorithms are not set correctly for all target variables)

File size: 10.6 KB
RevLine 
[2088]1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Drawing;
5using System.Data;
6using System.Linq;
7using System.Text;
8using System.Windows.Forms;
9using HeuristicLab.Core;
[2375]10using System.Diagnostics;
[2088]11
12namespace HeuristicLab.CEDMA.Server {
13  public partial class DispatcherView : ViewBase {
[2290]14    private SimpleDispatcher dispatcher;
[2375]15    private ProblemSpecification selectedSpec;
[2290]16    public DispatcherView(SimpleDispatcher dispatcher)
[2223]17      : base() {
[2088]18      this.dispatcher = dispatcher;
19      InitializeComponent();
[2375]20      dispatcher.Changed += (sender, args) => UpdateControls();
[2088]21      UpdateControls();
[2223]22      this.inputVariableList.CheckOnClick = true;
[2088]23    }
24
25    protected override void UpdateControls() {
[2153]26      if (InvokeRequired) {
27        Invoke((Action)UpdateControls);
28      } else {
29        base.UpdateControls();
[2290]30        algorithmsListBox.Items.Clear();
[2153]31        targetVariableList.Items.Clear();
32        inputVariableList.Items.Clear();
[2088]33
[2153]34        foreach (string targetVar in dispatcher.TargetVariables) {
35          targetVariableList.Items.Add(targetVar, false);
36        }
[2088]37
[2375]38        foreach (string inputVar in dispatcher.Variables) {
[2153]39          inputVariableList.Items.Add(inputVar, false);
40        }
[2290]41
[2153]42        targetVariableList.ClearSelected();
43        inputVariableList.Enabled = false;
[2088]44      }
45    }
[2119]46
47    private void targetVariableList_ItemCheck(object sender, ItemCheckEventArgs e) {
48      if (e.NewValue == CheckState.Checked) {
49        dispatcher.EnableTargetVariable((string)targetVariableList.Items[e.Index]);
50      } else if (e.NewValue == CheckState.Unchecked) {
51        dispatcher.DisableTargetVariable((string)targetVariableList.Items[e.Index]);
52      }
53    }
54
55    private void inputVariableList_ItemCheck(object sender, ItemCheckEventArgs e) {
56      if (e.NewValue == CheckState.Checked) {
[2375]57        selectedSpec.AddInputVariable((string)inputVariableList.Items[e.Index]);
[2119]58      } else if (e.NewValue == CheckState.Unchecked) {
[2375]59        selectedSpec.RemoveInputVariable((string)inputVariableList.Items[e.Index]);
[2119]60      }
61    }
[2153]62
63    private void targetVariableList_SelectedValueChanged(object sender, EventArgs e) {
64      string selectedTarget = (string)targetVariableList.SelectedItem;
[2375]65      selectedSpec = dispatcher.GetProblemSpecification(selectedTarget);
66      UpdateInputVariableList();
67      UpdateAlgorithms();
[2153]68    }
69
[2375]70    private void UpdateAlgorithms() {
71      learningTaskGroupBox.Enabled = true;
72      algorithmsListBox.Enabled = true;
73      switch (selectedSpec.LearningTask) {
74        case LearningTask.Classification: {
75            classificationRadioButton.Checked = true;
76            break;
77          }
78        case LearningTask.Regression: {
79            regressionRadioButton.Checked = true;
80            break;
81          }
82        case LearningTask.TimeSeries: {
[2376]83            timeSeriesRadioButton.Checked = true;
[2375]84            break;
85          }
86        default: { break; }
87      }
88      algorithmsListBox.Items.Clear();
89      foreach (HeuristicLab.Modeling.IAlgorithm algo in dispatcher.GetAlgorithms(selectedSpec.LearningTask)) {
90        algorithmsListBox.Items.Add(algo, dispatcher.GetAllowedAlgorithms(selectedSpec.TargetVariable).Contains(algo));
91      }
92      UpdateAlgorithmConfiguration();
93    }
94
95    private void UpdateAlgorithmConfiguration() {
96      partitioningGroupBox.Enabled = true;
97      trainingSamplesStartTextBox.Text = selectedSpec.TrainingSamplesStart.ToString();
98      trainingSamplesEndTextBox.Text = selectedSpec.TrainingSamplesEnd.ToString();
99      validationSamplesStartTextBox.Text = selectedSpec.ValidationSamplesStart.ToString();
100      validationSamplesEndTextBox.Text = selectedSpec.ValidationSamplesEnd.ToString();
101      testSamplesStartTextBox.Text = selectedSpec.TestSamplesStart.ToString();
102      testSamplesEndTextBox.Text = selectedSpec.TestSamplesEnd.ToString();
[2377]103      minTimeOffsetTextBox.Text = selectedSpec.MinTimeOffset.ToString();
104      maxTimeOffsetTextBox.Text = selectedSpec.MaxTimeOffset.ToString();
105      autoregressiveCheckBox.Checked = selectedSpec.AutoRegressive;
[2375]106    }
107
108    private void UpdateInputVariableList() {
[2153]109      inputVariableList.Items.Clear();
[2375]110      var activatedInputVariables = selectedSpec.InputVariables;
111      foreach (string inputVar in dispatcher.Variables) {
[2153]112        inputVariableList.Items.Add(inputVar, activatedInputVariables.Contains(inputVar));
113      }
114      inputVariableList.Enabled = true;
115    }
[2258]116
[2375]117    private void setAllButton_Click(object sender, EventArgs e) {
[2258]118      foreach (string targetVar in dispatcher.TargetVariables) {
[2375]119        ProblemSpecification spec = dispatcher.GetProblemSpecification(targetVar);
[2258]120        for (int i = 0; i < inputVariableList.Items.Count; i++) {
121          if (inputVariableList.GetItemChecked(i)) {
[2375]122            spec.AddInputVariable((string)inputVariableList.Items[i]);
[2258]123          } else {
[2375]124            spec.RemoveInputVariable((string)inputVariableList.Items[i]);
[2258]125          }
126        }
127      }
128    }
[2290]129
[2471]130
[2378]131    private void setAlgorithmDefault_Click(object sender, EventArgs e) {
[2471]132      var newAllowedAlgos = dispatcher.GetAllowedAlgorithms(selectedSpec.TargetVariable).ToList();
[2378]133      foreach (string targetVar in dispatcher.TargetVariables) {
[2471]134        if (targetVar != selectedSpec.TargetVariable) {
135          ProblemSpecification spec = dispatcher.GetProblemSpecification(targetVar);
136          spec.LearningTask = selectedSpec.LearningTask;
137          spec.MinTimeOffset = selectedSpec.MinTimeOffset;
138          spec.MaxTimeOffset = selectedSpec.MaxTimeOffset;
139          spec.AutoRegressive = selectedSpec.AutoRegressive;
140          var curAllowedAlgos = dispatcher.GetAllowedAlgorithms(targetVar).ToList();
141          foreach (var algo in curAllowedAlgos)
142            dispatcher.DisableAlgorithm(targetVar, algo);
143          foreach (var algo in newAllowedAlgos)
144            dispatcher.EnableAlgorithm(targetVar, algo);
145        }
[2378]146      }
147    }
148
[2290]149    private void algorithmsListBox_ItemCheck(object sender, ItemCheckEventArgs e) {
[2375]150      if (e.NewValue == CheckState.Checked) {
151        dispatcher.EnableAlgorithm(selectedSpec.TargetVariable, (HeuristicLab.Modeling.IAlgorithm)algorithmsListBox.Items[e.Index]);
152      } else if (e.NewValue == CheckState.Unchecked) {
153        dispatcher.DisableAlgorithm(selectedSpec.TargetVariable, (HeuristicLab.Modeling.IAlgorithm)algorithmsListBox.Items[e.Index]);
[2290]154      }
155    }
[2375]156
157    private void radioButton_CheckedChanged(object sender, EventArgs e) {
158      minTimeOffsetLabel.Enabled = timeSeriesRadioButton.Checked;
159      minTimeOffsetTextBox.Enabled = timeSeriesRadioButton.Checked;
160      maxTimeOffsetLabel.Enabled = timeSeriesRadioButton.Checked;
161      maxTimeOffsetTextBox.Enabled = timeSeriesRadioButton.Checked;
162      autoregressiveCheckBox.Enabled = timeSeriesRadioButton.Checked;
163      autoregressiveLabel.Enabled = timeSeriesRadioButton.Checked;
164      if (timeSeriesRadioButton.Checked) selectedSpec.LearningTask = LearningTask.TimeSeries;
165      else if (classificationRadioButton.Checked) selectedSpec.LearningTask = LearningTask.Classification;
166      else if (regressionRadioButton.Checked) selectedSpec.LearningTask = LearningTask.Regression;
[2377]167      var allowedAlgorithms = dispatcher.GetAllowedAlgorithms(selectedSpec.TargetVariable);
168      foreach (var algo in allowedAlgorithms) {
169        dispatcher.DisableAlgorithm(selectedSpec.TargetVariable, algo);
170      }
[2375]171      UpdateAlgorithms();
172    }
173
174    private void timeOffsetTextBox_Validating(object sender, CancelEventArgs e) {
175      int min, max;
176      e.Cancel = !int.TryParse(minTimeOffsetTextBox.Text, out min);
177      e.Cancel = !int.TryParse(maxTimeOffsetTextBox.Text, out max);
178      e.Cancel = min > max;
179    }
180
181    private void timeOffsetTextBox_Validated(object sender, EventArgs e) {
182      selectedSpec.MinTimeOffset = int.Parse(minTimeOffsetTextBox.Text);
183      selectedSpec.MaxTimeOffset = int.Parse(maxTimeOffsetTextBox.Text);
184    }
185
186    private void samplesTextBox_Validated(object sender, EventArgs e) {
187      selectedSpec.TrainingSamplesStart = int.Parse(trainingSamplesStartTextBox.Text);
188      selectedSpec.TrainingSamplesEnd = int.Parse(trainingSamplesEndTextBox.Text);
189      selectedSpec.ValidationSamplesStart = int.Parse(validationSamplesStartTextBox.Text);
190      selectedSpec.ValidationSamplesEnd = int.Parse(validationSamplesEndTextBox.Text);
191      selectedSpec.TestSamplesStart = int.Parse(testSamplesStartTextBox.Text);
192      selectedSpec.TestSamplesEnd = int.Parse(testSamplesEndTextBox.Text);
193    }
194
195    private void ColorSamplesTextBoxes(Color color) {
196      trainingSamplesStartTextBox.BackColor = color;
197      trainingSamplesEndTextBox.BackColor = color;
198      validationSamplesStartTextBox.BackColor = color;
199      validationSamplesEndTextBox.BackColor = color;
200      testSamplesStartTextBox.BackColor = color;
201      testSamplesEndTextBox.BackColor = color;
202    }
203
204    private void samplesTextBox_Validating(object sender, CancelEventArgs e) {
205      try {
206        int trainingStart = int.Parse(trainingSamplesStartTextBox.Text);
207        int trainingEnd = int.Parse(trainingSamplesEndTextBox.Text);
208        int validationStart = int.Parse(validationSamplesStartTextBox.Text);
209        int validationEnd = int.Parse(validationSamplesEndTextBox.Text);
210        int testStart = int.Parse(testSamplesStartTextBox.Text);
211        int testEnd = int.Parse(testSamplesEndTextBox.Text);
212        if (trainingStart < 0 || validationStart < 0 || testStart < 0 ||
213          trainingEnd >= selectedSpec.Dataset.Rows || validationEnd >= selectedSpec.Dataset.Rows || testEnd >= selectedSpec.Dataset.Rows ||
214          trainingStart >= trainingEnd ||
215          validationStart >= validationEnd ||
216          testStart >= testEnd ||
217          IsOverlapping(trainingStart, trainingEnd, validationStart, validationEnd) ||
218          IsOverlapping(trainingStart, trainingEnd, testStart, testEnd) ||
219          IsOverlapping(validationStart, validationEnd, testStart, testEnd))
220          ColorSamplesTextBoxes(Color.Red);
221        else
222          ColorSamplesTextBoxes(Color.White);
223      }
224      catch (FormatException) {
225        ColorSamplesTextBoxes(Color.Red);
226      }
227    }
228
229    private void autoregressiveCheckBox_CheckedChanged(object sender, EventArgs e) {
230      selectedSpec.AutoRegressive = autoregressiveCheckBox.Checked;
231    }
232
233    private bool IsOverlapping(int x0, int y0, int x1, int y1) {
234      Trace.Assert(x0 <= y0 && x1 <= y1);
235      int tmp;
236      // make sure that x0,y0 is the left interval
237      if (x1 < x0) {
238        tmp = x1;
239        x1 = x0;
240        x0 = tmp;
241        tmp = y1;
242        y1 = y0;
243        y0 = tmp;
244      }
245      return y0 > x1;
246    }
[2378]247
[2088]248  }
249}
Note: See TracBrowser for help on using the repository browser.