Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 2431 was 2378, checked in by gkronber, 15 years ago

Added "Set for all" button to simplify CEDMA algorithm configuration. #754

File size: 10.4 KB
Line 
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;
10using System.Diagnostics;
11
12namespace HeuristicLab.CEDMA.Server {
13  public partial class DispatcherView : ViewBase {
14    private SimpleDispatcher dispatcher;
15    private ProblemSpecification selectedSpec;
16    public DispatcherView(SimpleDispatcher dispatcher)
17      : base() {
18      this.dispatcher = dispatcher;
19      InitializeComponent();
20      dispatcher.Changed += (sender, args) => UpdateControls();
21      UpdateControls();
22      this.inputVariableList.CheckOnClick = true;
23    }
24
25    protected override void UpdateControls() {
26      if (InvokeRequired) {
27        Invoke((Action)UpdateControls);
28      } else {
29        base.UpdateControls();
30        algorithmsListBox.Items.Clear();
31        targetVariableList.Items.Clear();
32        inputVariableList.Items.Clear();
33
34        foreach (string targetVar in dispatcher.TargetVariables) {
35          targetVariableList.Items.Add(targetVar, false);
36        }
37
38        foreach (string inputVar in dispatcher.Variables) {
39          inputVariableList.Items.Add(inputVar, false);
40        }
41
42        targetVariableList.ClearSelected();
43        inputVariableList.Enabled = false;
44      }
45    }
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) {
57        selectedSpec.AddInputVariable((string)inputVariableList.Items[e.Index]);
58      } else if (e.NewValue == CheckState.Unchecked) {
59        selectedSpec.RemoveInputVariable((string)inputVariableList.Items[e.Index]);
60      }
61    }
62
63    private void targetVariableList_SelectedValueChanged(object sender, EventArgs e) {
64      string selectedTarget = (string)targetVariableList.SelectedItem;
65      selectedSpec = dispatcher.GetProblemSpecification(selectedTarget);
66      UpdateInputVariableList();
67      UpdateAlgorithms();
68    }
69
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: {
83            timeSeriesRadioButton.Checked = true;
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();
103      minTimeOffsetTextBox.Text = selectedSpec.MinTimeOffset.ToString();
104      maxTimeOffsetTextBox.Text = selectedSpec.MaxTimeOffset.ToString();
105      autoregressiveCheckBox.Checked = selectedSpec.AutoRegressive;
106    }
107
108    private void UpdateInputVariableList() {
109      inputVariableList.Items.Clear();
110      var activatedInputVariables = selectedSpec.InputVariables;
111      foreach (string inputVar in dispatcher.Variables) {
112        inputVariableList.Items.Add(inputVar, activatedInputVariables.Contains(inputVar));
113      }
114      inputVariableList.Enabled = true;
115    }
116
117    private void setAllButton_Click(object sender, EventArgs e) {
118      foreach (string targetVar in dispatcher.TargetVariables) {
119        ProblemSpecification spec = dispatcher.GetProblemSpecification(targetVar);
120        for (int i = 0; i < inputVariableList.Items.Count; i++) {
121          if (inputVariableList.GetItemChecked(i)) {
122            spec.AddInputVariable((string)inputVariableList.Items[i]);
123          } else {
124            spec.RemoveInputVariable((string)inputVariableList.Items[i]);
125          }
126        }
127      }
128    }
129
130   
131    private void setAlgorithmDefault_Click(object sender, EventArgs e) {
132      foreach (string targetVar in dispatcher.TargetVariables) {
133        ProblemSpecification spec = dispatcher.GetProblemSpecification(targetVar);
134        spec.LearningTask = selectedSpec.LearningTask;
135        spec.MinTimeOffset = selectedSpec.MinTimeOffset;
136        spec.MaxTimeOffset = selectedSpec.MaxTimeOffset;
137        spec.AutoRegressive = selectedSpec.AutoRegressive;
138        var allowedAlgos = dispatcher.GetAllowedAlgorithms(selectedSpec.TargetVariable);
139        foreach(var algo in allowedAlgos)
140          dispatcher.EnableAlgorithm(spec.TargetVariable, algo);
141      }
142    }
143
144    private void algorithmsListBox_ItemCheck(object sender, ItemCheckEventArgs e) {
145      if (e.NewValue == CheckState.Checked) {
146        dispatcher.EnableAlgorithm(selectedSpec.TargetVariable, (HeuristicLab.Modeling.IAlgorithm)algorithmsListBox.Items[e.Index]);
147      } else if (e.NewValue == CheckState.Unchecked) {
148        dispatcher.DisableAlgorithm(selectedSpec.TargetVariable, (HeuristicLab.Modeling.IAlgorithm)algorithmsListBox.Items[e.Index]);
149      }
150    }
151
152    private void radioButton_CheckedChanged(object sender, EventArgs e) {
153      minTimeOffsetLabel.Enabled = timeSeriesRadioButton.Checked;
154      minTimeOffsetTextBox.Enabled = timeSeriesRadioButton.Checked;
155      maxTimeOffsetLabel.Enabled = timeSeriesRadioButton.Checked;
156      maxTimeOffsetTextBox.Enabled = timeSeriesRadioButton.Checked;
157      autoregressiveCheckBox.Enabled = timeSeriesRadioButton.Checked;
158      autoregressiveLabel.Enabled = timeSeriesRadioButton.Checked;
159      if (timeSeriesRadioButton.Checked) selectedSpec.LearningTask = LearningTask.TimeSeries;
160      else if (classificationRadioButton.Checked) selectedSpec.LearningTask = LearningTask.Classification;
161      else if (regressionRadioButton.Checked) selectedSpec.LearningTask = LearningTask.Regression;
162      var allowedAlgorithms = dispatcher.GetAllowedAlgorithms(selectedSpec.TargetVariable);
163      foreach (var algo in allowedAlgorithms) {
164        dispatcher.DisableAlgorithm(selectedSpec.TargetVariable, algo);
165      }
166      UpdateAlgorithms();
167    }
168
169    private void timeOffsetTextBox_Validating(object sender, CancelEventArgs e) {
170      int min, max;
171      e.Cancel = !int.TryParse(minTimeOffsetTextBox.Text, out min);
172      e.Cancel = !int.TryParse(maxTimeOffsetTextBox.Text, out max);
173      e.Cancel = min > max;
174    }
175
176    private void timeOffsetTextBox_Validated(object sender, EventArgs e) {
177      selectedSpec.MinTimeOffset = int.Parse(minTimeOffsetTextBox.Text);
178      selectedSpec.MaxTimeOffset = int.Parse(maxTimeOffsetTextBox.Text);
179    }
180
181    private void samplesTextBox_Validated(object sender, EventArgs e) {
182      selectedSpec.TrainingSamplesStart = int.Parse(trainingSamplesStartTextBox.Text);
183      selectedSpec.TrainingSamplesEnd = int.Parse(trainingSamplesEndTextBox.Text);
184      selectedSpec.ValidationSamplesStart = int.Parse(validationSamplesStartTextBox.Text);
185      selectedSpec.ValidationSamplesEnd = int.Parse(validationSamplesEndTextBox.Text);
186      selectedSpec.TestSamplesStart = int.Parse(testSamplesStartTextBox.Text);
187      selectedSpec.TestSamplesEnd = int.Parse(testSamplesEndTextBox.Text);
188    }
189
190    private void ColorSamplesTextBoxes(Color color) {
191      trainingSamplesStartTextBox.BackColor = color;
192      trainingSamplesEndTextBox.BackColor = color;
193      validationSamplesStartTextBox.BackColor = color;
194      validationSamplesEndTextBox.BackColor = color;
195      testSamplesStartTextBox.BackColor = color;
196      testSamplesEndTextBox.BackColor = color;
197    }
198
199    private void samplesTextBox_Validating(object sender, CancelEventArgs e) {
200      try {
201        int trainingStart = int.Parse(trainingSamplesStartTextBox.Text);
202        int trainingEnd = int.Parse(trainingSamplesEndTextBox.Text);
203        int validationStart = int.Parse(validationSamplesStartTextBox.Text);
204        int validationEnd = int.Parse(validationSamplesEndTextBox.Text);
205        int testStart = int.Parse(testSamplesStartTextBox.Text);
206        int testEnd = int.Parse(testSamplesEndTextBox.Text);
207        if (trainingStart < 0 || validationStart < 0 || testStart < 0 ||
208          trainingEnd >= selectedSpec.Dataset.Rows || validationEnd >= selectedSpec.Dataset.Rows || testEnd >= selectedSpec.Dataset.Rows ||
209          trainingStart >= trainingEnd ||
210          validationStart >= validationEnd ||
211          testStart >= testEnd ||
212          IsOverlapping(trainingStart, trainingEnd, validationStart, validationEnd) ||
213          IsOverlapping(trainingStart, trainingEnd, testStart, testEnd) ||
214          IsOverlapping(validationStart, validationEnd, testStart, testEnd))
215          ColorSamplesTextBoxes(Color.Red);
216        else
217          ColorSamplesTextBoxes(Color.White);
218      }
219      catch (FormatException) {
220        ColorSamplesTextBoxes(Color.Red);
221      }
222    }
223
224    private void autoregressiveCheckBox_CheckedChanged(object sender, EventArgs e) {
225      selectedSpec.AutoRegressive = autoregressiveCheckBox.Checked;
226    }
227
228    private bool IsOverlapping(int x0, int y0, int x1, int y1) {
229      Trace.Assert(x0 <= y0 && x1 <= y1);
230      int tmp;
231      // make sure that x0,y0 is the left interval
232      if (x1 < x0) {
233        tmp = x1;
234        x1 = x0;
235        x0 = tmp;
236        tmp = y1;
237        y1 = y0;
238        y0 = tmp;
239      }
240      return y0 > x1;
241    }
242
243  }
244}
Note: See TracBrowser for help on using the repository browser.