- Timestamp:
- 09/21/09 20:23:47 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.CEDMA.Server/3.3/DispatcherView.cs
r2290 r2375 8 8 using System.Windows.Forms; 9 9 using HeuristicLab.Core; 10 using System.Diagnostics; 10 11 11 12 namespace HeuristicLab.CEDMA.Server { 12 13 public partial class DispatcherView : ViewBase { 13 14 private SimpleDispatcher dispatcher; 15 private ProblemSpecification selectedSpec; 14 16 public DispatcherView(SimpleDispatcher dispatcher) 15 17 : base() { 16 18 this.dispatcher = dispatcher; 17 19 InitializeComponent(); 20 dispatcher.Changed += (sender, args) => UpdateControls(); 18 21 UpdateControls(); 19 dispatcher.Changed += (sender, args) => UpdateControls();20 22 this.inputVariableList.CheckOnClick = true; 21 23 } … … 34 36 } 35 37 36 foreach (string inputVar in dispatcher. InputVariables) {38 foreach (string inputVar in dispatcher.Variables) { 37 39 inputVariableList.Items.Add(inputVar, false); 38 40 } 39 41 40 foreach (HeuristicLab.Modeling.IAlgorithm algo in dispatcher.Algorithms) {41 algorithmsListBox.Items.Add(algo, false);42 }43 42 targetVariableList.ClearSelected(); 44 43 inputVariableList.Enabled = false; … … 55 54 56 55 private void inputVariableList_ItemCheck(object sender, ItemCheckEventArgs e) { 57 string selectedTarget = (string)targetVariableList.SelectedItem;58 56 if (e.NewValue == CheckState.Checked) { 59 dispatcher.EnableInputVariable(selectedTarget,(string)inputVariableList.Items[e.Index]);57 selectedSpec.AddInputVariable((string)inputVariableList.Items[e.Index]); 60 58 } else if (e.NewValue == CheckState.Unchecked) { 61 dispatcher.DisableInputVariable(selectedTarget,(string)inputVariableList.Items[e.Index]);59 selectedSpec.RemoveInputVariable((string)inputVariableList.Items[e.Index]); 62 60 } 63 61 } … … 65 63 private void targetVariableList_SelectedValueChanged(object sender, EventArgs e) { 66 64 string selectedTarget = (string)targetVariableList.SelectedItem; 67 UpdateInputVariableList(selectedTarget); 68 } 69 70 private void UpdateInputVariableList(string target) { 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 regressionRadioButton.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 } 104 105 private void UpdateInputVariableList() { 71 106 inputVariableList.Items.Clear(); 72 var activatedInputVariables = dispatcher.GetInputVariables(target);73 foreach (string inputVar in dispatcher. InputVariables) {107 var activatedInputVariables = selectedSpec.InputVariables; 108 foreach (string inputVar in dispatcher.Variables) { 74 109 inputVariableList.Items.Add(inputVar, activatedInputVariables.Contains(inputVar)); 75 110 } … … 77 112 } 78 113 79 private void setAllButton_Click(object sender, EventArgs e) { 114 private void setAllButton_Click(object sender, EventArgs e) { 80 115 foreach (string targetVar in dispatcher.TargetVariables) { 116 ProblemSpecification spec = dispatcher.GetProblemSpecification(targetVar); 81 117 for (int i = 0; i < inputVariableList.Items.Count; i++) { 82 118 if (inputVariableList.GetItemChecked(i)) { 83 dispatcher.EnableInputVariable(targetVar,(string)inputVariableList.Items[i]);119 spec.AddInputVariable((string)inputVariableList.Items[i]); 84 120 } else { 85 dispatcher.DisableInputVariable(targetVar,(string)inputVariableList.Items[i]);121 spec.RemoveInputVariable((string)inputVariableList.Items[i]); 86 122 } 87 123 } … … 90 126 91 127 private void algorithmsListBox_ItemCheck(object sender, ItemCheckEventArgs e) { 92 if(e.NewValue == CheckState.Checked) { 93 dispatcher.EnableAlgorithm((HeuristicLab.Modeling.IAlgorithm)algorithmsListBox.Items[e.Index]); 94 } else if(e.NewValue == CheckState.Unchecked) { 95 dispatcher.DisableAlgorithm((HeuristicLab.Modeling.IAlgorithm)algorithmsListBox.Items[e.Index]); 96 } 128 if (e.NewValue == CheckState.Checked) { 129 dispatcher.EnableAlgorithm(selectedSpec.TargetVariable, (HeuristicLab.Modeling.IAlgorithm)algorithmsListBox.Items[e.Index]); 130 } else if (e.NewValue == CheckState.Unchecked) { 131 dispatcher.DisableAlgorithm(selectedSpec.TargetVariable, (HeuristicLab.Modeling.IAlgorithm)algorithmsListBox.Items[e.Index]); 132 } 133 } 134 135 private void radioButton_CheckedChanged(object sender, EventArgs e) { 136 string selectedTarget = (string)targetVariableList.SelectedItem; 137 minTimeOffsetLabel.Enabled = timeSeriesRadioButton.Checked; 138 minTimeOffsetTextBox.Enabled = timeSeriesRadioButton.Checked; 139 maxTimeOffsetLabel.Enabled = timeSeriesRadioButton.Checked; 140 maxTimeOffsetTextBox.Enabled = timeSeriesRadioButton.Checked; 141 autoregressiveCheckBox.Enabled = timeSeriesRadioButton.Checked; 142 autoregressiveLabel.Enabled = timeSeriesRadioButton.Checked; 143 if (timeSeriesRadioButton.Checked) selectedSpec.LearningTask = LearningTask.TimeSeries; 144 else if (classificationRadioButton.Checked) selectedSpec.LearningTask = LearningTask.Classification; 145 else if (regressionRadioButton.Checked) selectedSpec.LearningTask = LearningTask.Regression; 146 UpdateAlgorithms(); 147 } 148 149 private void timeOffsetTextBox_Validating(object sender, CancelEventArgs e) { 150 int min, max; 151 e.Cancel = !int.TryParse(minTimeOffsetTextBox.Text, out min); 152 e.Cancel = !int.TryParse(maxTimeOffsetTextBox.Text, out max); 153 e.Cancel = min > max; 154 } 155 156 private void timeOffsetTextBox_Validated(object sender, EventArgs e) { 157 selectedSpec.MinTimeOffset = int.Parse(minTimeOffsetTextBox.Text); 158 selectedSpec.MaxTimeOffset = int.Parse(maxTimeOffsetTextBox.Text); 159 } 160 161 private void samplesTextBox_Validated(object sender, EventArgs e) { 162 selectedSpec.TrainingSamplesStart = int.Parse(trainingSamplesStartTextBox.Text); 163 selectedSpec.TrainingSamplesEnd = int.Parse(trainingSamplesEndTextBox.Text); 164 selectedSpec.ValidationSamplesStart = int.Parse(validationSamplesStartTextBox.Text); 165 selectedSpec.ValidationSamplesEnd = int.Parse(validationSamplesEndTextBox.Text); 166 selectedSpec.TestSamplesStart = int.Parse(testSamplesStartTextBox.Text); 167 selectedSpec.TestSamplesEnd = int.Parse(testSamplesEndTextBox.Text); 168 } 169 170 private void ColorSamplesTextBoxes(Color color) { 171 trainingSamplesStartTextBox.BackColor = color; 172 trainingSamplesEndTextBox.BackColor = color; 173 validationSamplesStartTextBox.BackColor = color; 174 validationSamplesEndTextBox.BackColor = color; 175 testSamplesStartTextBox.BackColor = color; 176 testSamplesEndTextBox.BackColor = color; 177 } 178 179 private void samplesTextBox_Validating(object sender, CancelEventArgs e) { 180 try { 181 int trainingStart = int.Parse(trainingSamplesStartTextBox.Text); 182 int trainingEnd = int.Parse(trainingSamplesEndTextBox.Text); 183 int validationStart = int.Parse(validationSamplesStartTextBox.Text); 184 int validationEnd = int.Parse(validationSamplesEndTextBox.Text); 185 int testStart = int.Parse(testSamplesStartTextBox.Text); 186 int testEnd = int.Parse(testSamplesEndTextBox.Text); 187 if (trainingStart < 0 || validationStart < 0 || testStart < 0 || 188 trainingEnd >= selectedSpec.Dataset.Rows || validationEnd >= selectedSpec.Dataset.Rows || testEnd >= selectedSpec.Dataset.Rows || 189 trainingStart >= trainingEnd || 190 validationStart >= validationEnd || 191 testStart >= testEnd || 192 IsOverlapping(trainingStart, trainingEnd, validationStart, validationEnd) || 193 IsOverlapping(trainingStart, trainingEnd, testStart, testEnd) || 194 IsOverlapping(validationStart, validationEnd, testStart, testEnd)) 195 ColorSamplesTextBoxes(Color.Red); 196 else 197 ColorSamplesTextBoxes(Color.White); 198 } 199 catch (FormatException) { 200 ColorSamplesTextBoxes(Color.Red); 201 } 202 } 203 204 private void autoregressiveCheckBox_CheckedChanged(object sender, EventArgs e) { 205 selectedSpec.AutoRegressive = autoregressiveCheckBox.Checked; 206 } 207 208 private bool IsOverlapping(int x0, int y0, int x1, int y1) { 209 Trace.Assert(x0 <= y0 && x1 <= y1); 210 int tmp; 211 // make sure that x0,y0 is the left interval 212 if (x1 < x0) { 213 tmp = x1; 214 x1 = x0; 215 x0 = tmp; 216 tmp = y1; 217 y1 = y0; 218 y0 = tmp; 219 } 220 return y0 > x1; 97 221 } 98 222 }
Note: See TracChangeset
for help on using the changeset viewer.