[2088] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.ComponentModel;
|
---|
| 4 | using System.Drawing;
|
---|
| 5 | using System.Data;
|
---|
| 6 | using System.Linq;
|
---|
| 7 | using System.Text;
|
---|
| 8 | using System.Windows.Forms;
|
---|
| 9 | using HeuristicLab.Core;
|
---|
[2375] | 10 | using System.Diagnostics;
|
---|
[2088] | 11 |
|
---|
| 12 | namespace 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();
|
---|
[2824] | 20 | editEngineButton.Enabled = false;
|
---|
[2375] | 21 | dispatcher.Changed += (sender, args) => UpdateControls();
|
---|
[2088] | 22 | UpdateControls();
|
---|
[2223] | 23 | this.inputVariableList.CheckOnClick = true;
|
---|
[2088] | 24 | }
|
---|
| 25 |
|
---|
| 26 | protected override void UpdateControls() {
|
---|
[2153] | 27 | if (InvokeRequired) {
|
---|
| 28 | Invoke((Action)UpdateControls);
|
---|
| 29 | } else {
|
---|
| 30 | base.UpdateControls();
|
---|
[2290] | 31 | algorithmsListBox.Items.Clear();
|
---|
[2153] | 32 | targetVariableList.Items.Clear();
|
---|
| 33 | inputVariableList.Items.Clear();
|
---|
[2088] | 34 |
|
---|
[2153] | 35 | foreach (string targetVar in dispatcher.TargetVariables) {
|
---|
| 36 | targetVariableList.Items.Add(targetVar, false);
|
---|
| 37 | }
|
---|
[2088] | 38 |
|
---|
[2375] | 39 | foreach (string inputVar in dispatcher.Variables) {
|
---|
[2153] | 40 | inputVariableList.Items.Add(inputVar, false);
|
---|
| 41 | }
|
---|
[2290] | 42 |
|
---|
[2153] | 43 | targetVariableList.ClearSelected();
|
---|
| 44 | inputVariableList.Enabled = false;
|
---|
[2088] | 45 | }
|
---|
| 46 | }
|
---|
[2119] | 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) {
|
---|
[2375] | 58 | selectedSpec.AddInputVariable((string)inputVariableList.Items[e.Index]);
|
---|
[2119] | 59 | } else if (e.NewValue == CheckState.Unchecked) {
|
---|
[2375] | 60 | selectedSpec.RemoveInputVariable((string)inputVariableList.Items[e.Index]);
|
---|
[2119] | 61 | }
|
---|
| 62 | }
|
---|
[2153] | 63 |
|
---|
| 64 | private void targetVariableList_SelectedValueChanged(object sender, EventArgs e) {
|
---|
| 65 | string selectedTarget = (string)targetVariableList.SelectedItem;
|
---|
[2375] | 66 | selectedSpec = dispatcher.GetProblemSpecification(selectedTarget);
|
---|
| 67 | UpdateInputVariableList();
|
---|
| 68 | UpdateAlgorithms();
|
---|
[2153] | 69 | }
|
---|
| 70 |
|
---|
[2375] | 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: {
|
---|
[2376] | 84 | timeSeriesRadioButton.Checked = true;
|
---|
[2375] | 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();
|
---|
[2377] | 104 | autoregressiveCheckBox.Checked = selectedSpec.AutoRegressive;
|
---|
[2375] | 105 | }
|
---|
| 106 |
|
---|
| 107 | private void UpdateInputVariableList() {
|
---|
[2153] | 108 | inputVariableList.Items.Clear();
|
---|
[2375] | 109 | var activatedInputVariables = selectedSpec.InputVariables;
|
---|
| 110 | foreach (string inputVar in dispatcher.Variables) {
|
---|
[2153] | 111 | inputVariableList.Items.Add(inputVar, activatedInputVariables.Contains(inputVar));
|
---|
| 112 | }
|
---|
| 113 | inputVariableList.Enabled = true;
|
---|
| 114 | }
|
---|
[2258] | 115 |
|
---|
[2375] | 116 | private void setAllButton_Click(object sender, EventArgs e) {
|
---|
[2258] | 117 | foreach (string targetVar in dispatcher.TargetVariables) {
|
---|
[2375] | 118 | ProblemSpecification spec = dispatcher.GetProblemSpecification(targetVar);
|
---|
[2258] | 119 | for (int i = 0; i < inputVariableList.Items.Count; i++) {
|
---|
| 120 | if (inputVariableList.GetItemChecked(i)) {
|
---|
[2375] | 121 | spec.AddInputVariable((string)inputVariableList.Items[i]);
|
---|
[2258] | 122 | } else {
|
---|
[2375] | 123 | spec.RemoveInputVariable((string)inputVariableList.Items[i]);
|
---|
[2258] | 124 | }
|
---|
| 125 | }
|
---|
| 126 | }
|
---|
| 127 | }
|
---|
[2290] | 128 |
|
---|
[2471] | 129 |
|
---|
[2378] | 130 | private void setAlgorithmDefault_Click(object sender, EventArgs e) {
|
---|
[2471] | 131 | var newAllowedAlgos = dispatcher.GetAllowedAlgorithms(selectedSpec.TargetVariable).ToList();
|
---|
[2378] | 132 | foreach (string targetVar in dispatcher.TargetVariables) {
|
---|
[2471] | 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 | }
|
---|
[2378] | 143 | }
|
---|
| 144 | }
|
---|
| 145 |
|
---|
[2290] | 146 | private void algorithmsListBox_ItemCheck(object sender, ItemCheckEventArgs e) {
|
---|
[2375] | 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]);
|
---|
[2290] | 151 | }
|
---|
| 152 | }
|
---|
[2375] | 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;
|
---|
[2377] | 160 | var allowedAlgorithms = dispatcher.GetAllowedAlgorithms(selectedSpec.TargetVariable);
|
---|
| 161 | foreach (var algo in allowedAlgorithms) {
|
---|
| 162 | dispatcher.DisableAlgorithm(selectedSpec.TargetVariable, algo);
|
---|
| 163 | }
|
---|
[2375] | 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 | }
|
---|
[2378] | 228 |
|
---|
[2824] | 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 | }
|
---|
[2088] | 237 | }
|
---|
| 238 | }
|
---|