Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3392 was 2843, checked in by gkronber, 15 years ago

Removed max. and min. time offset constraints as algorithm parameters and from all engines. The time constraints were added to the relevant terminal symbols (variable & differential) instead. The time offset constraint can be changed by editing the symbols in the function library. #880 (Max and min time offsets for variable symbols are not set correctly by FunctionLibraryInjectors)

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