Changeset 4542
- Timestamp:
- 09/30/10 14:35:21 (14 years ago)
- Location:
- branches/HeuristicLab.Classification
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Classification/HeuristicLab.Algorithms.DataAnalysis.Views/3.3/CrossValidationView.Designer.cs
r4536 r4542 73 73 this.openAlgorithmButton = new System.Windows.Forms.Button(); 74 74 this.newAlgorithmButton = new System.Windows.Forms.Button(); 75 this. workerTabPage = new System.Windows.Forms.TabPage();75 this.foldsTabPage = new System.Windows.Forms.TabPage(); 76 76 this.algorithmResultsCollectionView = new HeuristicLab.Algorithms.DataAnalysis.Views.AlgorithmResultsCollectionView(); 77 77 this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); … … 84 84 this.algorithmProblemTabPage.SuspendLayout(); 85 85 this.algorithmParametersTabPage.SuspendLayout(); 86 this. workerTabPage.SuspendLayout();86 this.foldsTabPage.SuspendLayout(); 87 87 this.SuspendLayout(); 88 88 // … … 284 284 | System.Windows.Forms.AnchorStyles.Right))); 285 285 this.tabControl.Controls.Add(this.algorithmTabPage); 286 this.tabControl.Controls.Add(this. workerTabPage);286 this.tabControl.Controls.Add(this.foldsTabPage); 287 287 this.tabControl.Location = new System.Drawing.Point(0, 157); 288 288 this.tabControl.Name = "tabControl"; … … 431 431 this.newAlgorithmButton.Click += new System.EventHandler(this.newAlgorithmButton_Click); 432 432 // 433 // workerTabPage434 // 435 this. workerTabPage.Controls.Add(this.algorithmResultsCollectionView);436 this. workerTabPage.Location = new System.Drawing.Point(4, 22);437 this. workerTabPage.Name = "workerTabPage";438 this. workerTabPage.Padding = new System.Windows.Forms.Padding(3);439 this. workerTabPage.Size = new System.Drawing.Size(649, 325);440 this. workerTabPage.TabIndex = 1;441 this. workerTabPage.Text = "Worker";442 this. workerTabPage.UseVisualStyleBackColor = true;433 // foldsTabPage 434 // 435 this.foldsTabPage.Controls.Add(this.algorithmResultsCollectionView); 436 this.foldsTabPage.Location = new System.Drawing.Point(4, 22); 437 this.foldsTabPage.Name = "foldsTabPage"; 438 this.foldsTabPage.Padding = new System.Windows.Forms.Padding(3); 439 this.foldsTabPage.Size = new System.Drawing.Size(649, 325); 440 this.foldsTabPage.TabIndex = 1; 441 this.foldsTabPage.Text = "Folds"; 442 this.foldsTabPage.UseVisualStyleBackColor = true; 443 443 // 444 444 // algorithmResultsCollectionView … … 508 508 this.algorithmProblemTabPage.ResumeLayout(false); 509 509 this.algorithmParametersTabPage.ResumeLayout(false); 510 this. workerTabPage.ResumeLayout(false);510 this.foldsTabPage.ResumeLayout(false); 511 511 this.ResumeLayout(false); 512 512 this.PerformLayout(); … … 533 533 private System.Windows.Forms.TabControl tabControl; 534 534 private System.Windows.Forms.TabPage algorithmTabPage; 535 private System.Windows.Forms.TabPage workerTabPage;535 private System.Windows.Forms.TabPage foldsTabPage; 536 536 private System.Windows.Forms.Button openAlgorithmButton; 537 537 private System.Windows.Forms.Button newAlgorithmButton; -
branches/HeuristicLab.Classification/HeuristicLab.Algorithms.DataAnalysis.Views/3.3/CrossValidationView.cs
r4536 r4542 31 31 32 32 namespace HeuristicLab.Algorithms.DataAnalysis.Views { 33 [View("Cross Validation View")] 33 34 [Content(typeof(CrossValidation), true)] 34 public partial class CrossValidationView : NamedItemView {35 public sealed partial class CrossValidationView : NamedItemView { 35 36 private TypeSelectorDialog algorithmTypeSelectorDialog; 36 37 private TypeSelectorDialog problemTypeSelectorDialog; … … 38 39 public CrossValidationView() { 39 40 InitializeComponent(); 41 workersNumericUpDown.Maximum = Environment.ProcessorCount * 2; 40 42 } 41 43 … … 57 59 algorithmResultsCollectionView.Content = null; 58 60 } else { 61 Locked = ReadOnly = Content.ExecutionState == ExecutionState.Started; 59 62 workersNumericUpDown.Value = Content.NumberOfWorkers.Value; 60 63 foldsNumericUpDown.Value = Content.Folds.Value; … … 78 81 Content.ExecutionStateChanged += new EventHandler(Content_ExecutionStateChanged); 79 82 Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged); 80 Content.Prepared += new EventHandler(Content_Prepared);81 Content.Started += new EventHandler(Content_Started);82 Content.Paused += new EventHandler(Content_Paused);83 Content.Stopped += new EventHandler(Content_Stopped);84 83 } 85 84 … … 93 92 Content.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred); 94 93 Content.ExecutionStateChanged -= new EventHandler(Content_ExecutionStateChanged); 95 Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged); 96 Content.Prepared -= new EventHandler(Content_Prepared); 97 Content.Started -= new EventHandler(Content_Started); 98 Content.Paused -= new EventHandler(Content_Paused); 99 Content.Stopped -= new EventHandler(Content_Stopped); 94 Content.ExecutionTimeChanged -= new EventHandler(Content_ExecutionTimeChanged); 100 95 } 101 96 … … 111 106 samplesEndStringConvertibleValueView.Enabled = Content.Problem != null; 112 107 } 108 SetEnabledStateOfExecutableButtons(); 109 } 110 } 111 private void SetEnabledStateOfExecutableButtons() { 112 if (Content == null) { 113 startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false; 114 foldsNumericUpDown.Enabled = workersNumericUpDown.Enabled = false; 115 samplesStartStringConvertibleValueView.Enabled = samplesEndStringConvertibleValueView.Enabled = false; 116 } else { 117 startButton.Enabled = (Content.ExecutionState == ExecutionState.Prepared) || (Content.ExecutionState == ExecutionState.Paused); 118 pauseButton.Enabled = Content.ExecutionState == ExecutionState.Started; 119 stopButton.Enabled = (Content.ExecutionState == ExecutionState.Started) || (Content.ExecutionState == ExecutionState.Paused); 120 resetButton.Enabled = Content.ExecutionState != ExecutionState.Started; 121 foldsNumericUpDown.Enabled = Content.ExecutionState == ExecutionState.Prepared; 122 samplesStartStringConvertibleValueView.Enabled = Content.ExecutionState == ExecutionState.Prepared; 123 samplesEndStringConvertibleValueView.Enabled = Content.ExecutionState == ExecutionState.Prepared; 124 workersNumericUpDown.Enabled = (Content.ExecutionState == ExecutionState.Prepared) || (Content.ExecutionState == ExecutionState.Paused); 113 125 } 114 126 } … … 145 157 if (InvokeRequired) 146 158 Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e); 147 else148 startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false;149 }150 private void Content_Prepared(object sender, EventArgs e) {151 if (InvokeRequired)152 Invoke(new EventHandler(Content_Prepared), sender, e);153 159 else { 154 ReadOnly = Locked = false;160 Locked = ReadOnly = Content.ExecutionState == ExecutionState.Started; 155 161 SetEnabledStateOfExecutableButtons(); 156 162 } 157 163 } 158 private void Content_Started(object sender, EventArgs e) { 159 if (InvokeRequired) 160 Invoke(new EventHandler(Content_Started), sender, e); 161 else { 162 ReadOnly = Locked = true; 163 SetEnabledStateOfExecutableButtons(); 164 } 165 } 166 private void Content_Paused(object sender, EventArgs e) { 167 if (InvokeRequired) 168 Invoke(new EventHandler(Content_Paused), sender, e); 169 else { 170 ReadOnly = Locked = false; 171 SetEnabledStateOfExecutableButtons(); 172 } 173 } 174 private void Content_Stopped(object sender, EventArgs e) { 175 if (InvokeRequired) 176 Invoke(new EventHandler(Content_Stopped), sender, e); 177 else { 178 ReadOnly = Locked = false; 179 SetEnabledStateOfExecutableButtons(); 180 } 181 } 164 182 165 private void Content_ExecutionTimeChanged(object sender, EventArgs e) { 183 166 if (InvokeRequired) … … 296 279 if (error != null) throw error; 297 280 IDataAnalysisProblem problem = content as IDataAnalysisProblem; 298 if (problem == null )281 if (problem == null && (Content.Algorithm.ProblemType.IsAssignableFrom(content.GetType()))) 299 282 Invoke(new Action(() => 300 283 MessageBox.Show(this, "The selected file does not contain a DataAnalysisProblem problem.", "Invalid File", MessageBoxButtons.OK, MessageBoxIcon.Error))); … … 336 319 } 337 320 338 pr otected virtualvoid algorithmProblemTabPage_DragEnterOver(object sender, DragEventArgs e) {321 private void algorithmProblemTabPage_DragEnterOver(object sender, DragEventArgs e) { 339 322 e.Effect = DragDropEffects.None; 340 323 Type type = e.Data.GetData("Type") as Type; 341 if ((type != null) && (typeof(IDataAnalysisProblem).IsAssignableFrom(type))) { 324 if ((type != null) && (typeof(IDataAnalysisProblem).IsAssignableFrom(type)) && 325 (Content.Algorithm.ProblemType.IsAssignableFrom(type))) { 342 326 if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link; // ALT key 343 327 else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move; // SHIFT key … … 347 331 } 348 332 } 349 pr otected virtualvoid algorithmProblemTabPage_DragDrop(object sender, DragEventArgs e) {333 private void algorithmProblemTabPage_DragDrop(object sender, DragEventArgs e) { 350 334 if (e.Effect != DragDropEffects.None) { 351 335 IDataAnalysisProblem problem = e.Data.GetData("Value") as IDataAnalysisProblem; … … 355 339 } 356 340 #endregion 357 358 #region Helpers359 private void SetEnabledStateOfExecutableButtons() {360 if (Content == null) {361 startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false;362 } else {363 startButton.Enabled = (Content.ExecutionState == ExecutionState.Prepared) || (Content.ExecutionState == ExecutionState.Paused);364 pauseButton.Enabled = Content.ExecutionState == ExecutionState.Started;365 stopButton.Enabled = (Content.ExecutionState == ExecutionState.Started) || (Content.ExecutionState == ExecutionState.Paused);366 resetButton.Enabled = Content.ExecutionState != ExecutionState.Started;367 }368 }369 #endregion370 341 } 371 342 } -
branches/HeuristicLab.Classification/HeuristicLab.Algorithms.DataAnalysis.Views/3.3/CrossValidationView.resx
r4536 r4542 121 121 <value>107, 17</value> 122 122 </metadata> 123 <metadata name="errorProvider.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">124 <value>107, 17</value>125 </metadata>126 123 <metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> 127 124 <value>17, 17</value> -
branches/HeuristicLab.Classification/HeuristicLab.Algorithms.DataAnalysis.Views/3.3/HeuristicLabAlgorithmsDataAnalysisViewsPlugin.cs.frame
r4472 r4542 26 26 /// Plugin class for HeuristicLab.Algorithms.DataAnalysis.Views plugin. 27 27 /// </summary> 28 [Plugin("HeuristicLab.Algorithms.DataAnalysis.Views", "3.3. 0.$WCREV$")]28 [Plugin("HeuristicLab.Algorithms.DataAnalysis.Views", "3.3.1.$WCREV$")] 29 29 [PluginFile("HeuristicLab.Algorithms.DataAnalysis.Views-3.3.dll", PluginFileType.Assembly)] 30 30 public class HeuristicLabAlgorithmsDataAnalysisViewsPlugin : PluginBase { -
branches/HeuristicLab.Classification/HeuristicLab.Algorithms.DataAnalysis.Views/3.3/Properties/AssemblyInfo.frame
r4472 r4542 52 52 // You can specify all the values or you can default the Revision and Build Numbers 53 53 // by using the '*' as shown below: 54 [assembly: AssemblyVersion("3.3. 0.0")]55 [assembly: AssemblyFileVersion("3.3. 0.$WCREV$")]54 [assembly: AssemblyVersion("3.3.1.0")] 55 [assembly: AssemblyFileVersion("3.3.1.$WCREV$")] -
branches/HeuristicLab.Classification/HeuristicLab.Algorithms.DataAnalysis/3.3/CrossValidation.cs
r4536 r4542 36 36 [StorableClass] 37 37 public sealed class CrossValidation : NamedItem, IOptimizer { 38 //TODO cloning, persistence, creation of clonedAlgs, execution logic, ...39 38 public CrossValidation() 40 39 : base() { … … 44 43 executionState = ExecutionState.Stopped; 45 44 executionTime = TimeSpan.Zero; 46 Runs = new RunCollection();45 runs = new RunCollection(); 47 46 48 47 algorithm = null; 49 48 clonedAlgorithms = new ItemCollection<IAlgorithm>(); 50 RegisterClonedAlgorithmEvents();51 49 readOnlyClonedAlgorithms = null; 52 50 53 51 folds = new IntValue(1); 52 numberOfWorkers = new IntValue(1); 54 53 samplesStart = new IntValue(0); 55 54 samplesEnd = new IntValue(0); 56 numberOfWorkers = new IntValue(1); 57 } 55 56 57 RegisterEvents(); 58 } 59 60 #region persistence and cloning 61 [StorableConstructor] 62 private CrossValidation(bool deserializing) 63 : base(deserializing) { 64 } 65 [StorableHook(HookType.AfterDeserialization)] 66 private void AfterDeserialization() { 67 RegisterEvents(); 68 } 69 70 public override IDeepCloneable Clone(Cloner cloner) { 71 if (ExecutionState == ExecutionState.Started) throw new InvalidOperationException(string.Format("Clone not allowed in execution state \"{0}\".", ExecutionState)); 72 CrossValidation clone = new CrossValidation(false); 73 cloner.RegisterClonedObject(this, clone); 74 clone.name = name; 75 clone.description = description; 76 clone.executionState = executionState; 77 clone.executionTime = executionTime; 78 clone.runs = (RunCollection)cloner.Clone(runs); 79 clone.algorithm = (IAlgorithm)cloner.Clone(algorithm); 80 clone.clonedAlgorithms = (ItemCollection<IAlgorithm>)cloner.Clone(clonedAlgorithms); 81 clone.folds = (IntValue)cloner.Clone(folds); 82 clone.numberOfWorkers = (IntValue)cloner.Clone(numberOfWorkers); 83 clone.samplesStart = (IntValue)cloner.Clone(samplesStart); 84 clone.samplesEnd = (IntValue)cloner.Clone(samplesEnd); 85 clone.RegisterEvents(); 86 return clone; 87 } 88 89 #endregion 58 90 59 91 #region properties 92 [Storable] 60 93 private IAlgorithm algorithm; 61 94 public IAlgorithm Algorithm { 62 95 get { return algorithm; } 63 96 set { 97 if (ExecutionState != ExecutionState.Prepared && ExecutionState != ExecutionState.Stopped) 98 throw new InvalidOperationException("Changing the algorithm is only allowed if the CrossValidation is stopped or prepared."); 64 99 if (algorithm != value) { 65 100 if (value != null && value.Problem != null && !(value.Problem is IDataAnalysisProblem)) … … 67 102 if (algorithm != null) DeregisterAlgorithmEvents(); 68 103 algorithm = value; 69 algorithm.Prepare(true); 70 if (algorithm != null) RegisterAlgorithmEvents(); 104 105 if (algorithm != null) { 106 RegisterAlgorithmEvents(); 107 algorithm.Prepare(true); 108 } 71 109 OnAlgorithmChanged(); 72 } 73 } 74 } 110 Prepare(); 111 } 112 } 113 } 114 115 [Storable] 75 116 private IDataAnalysisProblem cachedProblem; 76 117 public IDataAnalysisProblem Problem { … … 81 122 } 82 123 set { 124 if (ExecutionState != ExecutionState.Prepared && ExecutionState != ExecutionState.Stopped) 125 throw new InvalidOperationException("Changing the problem is only allowed if the CrossValidation is stopped or prepared."); 83 126 if (algorithm == null) throw new ArgumentNullException("Could not set a problem before an algorithm was set."); 84 127 algorithm.Problem = value; … … 87 130 } 88 131 132 [Storable] 89 133 private ItemCollection<IAlgorithm> clonedAlgorithms; 90 134 private ReadOnlyItemCollection<IAlgorithm> readOnlyClonedAlgorithms; … … 96 140 } 97 141 142 [Storable] 98 143 private IntValue folds; 99 144 public IntValue Folds { 100 145 get { return folds; } 101 146 } 147 [Storable] 102 148 private IntValue samplesStart; 103 149 public IntValue SamplesStart { 104 150 get { return samplesStart; } 105 151 } 152 [Storable] 106 153 private IntValue samplesEnd; 107 154 public IntValue SamplesEnd { 108 155 get { return samplesEnd; } 109 156 } 157 [Storable] 110 158 private IntValue numberOfWorkers; 111 159 public IntValue NumberOfWorkers { … … 113 161 } 114 162 163 [Storable] 115 164 private RunCollection runs; 116 165 public RunCollection Runs { 117 166 get { return runs; } 118 private set { 119 if (value == null) throw new ArgumentNullException(); 120 if (runs != value) { 121 if (runs != null) DeregisterRunsEvents(); 122 runs = value; 123 if (runs != null) RegisterRunsEvents(); 124 } 125 } 126 } 167 } 168 [Storable] 127 169 private ExecutionState executionState; 128 170 public ExecutionState ExecutionState { … … 146 188 } 147 189 190 [Storable] 148 191 private TimeSpan executionTime; 149 192 public TimeSpan ExecutionTime { … … 162 205 163 206 public void Prepare() { 207 if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused) && (ExecutionState != ExecutionState.Stopped)) 208 throw new InvalidOperationException(string.Format("Prepare not allowed in execution state \"{0}\".", ExecutionState)); 164 209 clonedAlgorithms.Clear(); 165 OnPrepared(); 210 if (Algorithm != null) { 211 Algorithm.Prepare(); 212 if (Algorithm.ExecutionState == ExecutionState.Prepared) OnPrepared(); 213 } 166 214 } 167 215 public void Prepare(bool clearRuns) { … … 169 217 Prepare(); 170 218 } 219 220 private bool startPending; 171 221 public void Start() { 172 for (int i = 0; i < Folds.Value; i++) { 173 IAlgorithm clonedAlgorithm = (IAlgorithm)algorithm.Clone(); 174 clonedAlgorithm.Name = algorithm.Name + " Fold " + i; 175 clonedAlgorithms.Add(clonedAlgorithm); 176 } 177 for (int i = 0; i < NumberOfWorkers.Value && i < clonedAlgorithms.Count; i++) 178 clonedAlgorithms.ElementAt(i).Start(); 179 OnStarted(); 180 } 222 if ((ExecutionState != ExecutionState.Prepared) && (ExecutionState != ExecutionState.Paused)) 223 throw new InvalidOperationException(string.Format("Start not allowed in execution state \"{0}\".", ExecutionState)); 224 225 if (Algorithm != null && !startPending) { 226 startPending = true; 227 //create cloned algorithms 228 if (clonedAlgorithms.Count == 0) { 229 for (int i = 0; i < Folds.Value; i++) { 230 IAlgorithm clonedAlgorithm = (IAlgorithm)algorithm.Clone(); 231 clonedAlgorithm.Name = algorithm.Name + " Fold " + i; 232 clonedAlgorithms.Add(clonedAlgorithm); 233 } 234 } 235 236 //start prepared or paused cloned algorithms 237 int startedAlgorithms = 0; 238 foreach (IAlgorithm clonedAlgorithm in clonedAlgorithms) { 239 if (startedAlgorithms < NumberOfWorkers.Value) { 240 if (clonedAlgorithm.ExecutionState == ExecutionState.Prepared || 241 clonedAlgorithm.ExecutionState == ExecutionState.Paused) { 242 clonedAlgorithm.Start(); 243 startedAlgorithms++; 244 } 245 } 246 } 247 OnStarted(); 248 } 249 } 250 251 private bool pausePending; 181 252 public void Pause() { 182 OnPaused(); 183 } 253 if (ExecutionState != ExecutionState.Started) 254 throw new InvalidOperationException(string.Format("Pause not allowed in execution state \"{0}\".", ExecutionState)); 255 if (!pausePending) { 256 pausePending = true; 257 if (!startPending) PauseAllClonedAlgorithms(); 258 } 259 } 260 private void PauseAllClonedAlgorithms() { 261 foreach (IAlgorithm clonedAlgorithm in ClonedAlgorithms) { 262 if (clonedAlgorithm.ExecutionState == ExecutionState.Started) 263 clonedAlgorithm.Pause(); 264 } 265 } 266 267 private bool stopPending; 184 268 public void Stop() { 185 OnStopped(); 269 if ((ExecutionState != ExecutionState.Started) && (ExecutionState != ExecutionState.Paused)) 270 throw new InvalidOperationException(string.Format("Stop not allowed in execution state \"{0}\".", 271 ExecutionState)); 272 if (!stopPending) { 273 stopPending = true; 274 if (!startPending) StopAllClonedAlgorithms(); 275 } 276 } 277 private void StopAllClonedAlgorithms() { 278 foreach (IAlgorithm clonedAlgorithm in ClonedAlgorithms) { 279 if (clonedAlgorithm.ExecutionState == ExecutionState.Started || 280 clonedAlgorithm.ExecutionState == ExecutionState.Paused) 281 clonedAlgorithm.Stop(); 282 } 186 283 } 187 284 188 285 #region events 286 private void RegisterEvents() { 287 Folds.ValueChanged += new EventHandler(Folds_ValueChanged); 288 NumberOfWorkers.ValueChanged += new EventHandler(NumberOfWorkers_ValueChanged); 289 RegisterClonedAlgorithmsEvents(); 290 RegisterRunsEvents(); 291 } 292 private void Folds_ValueChanged(object sender, EventArgs e) { 293 if (ExecutionState != ExecutionState.Prepared) 294 throw new InvalidOperationException("Can not change number of folds if the execution state is not prepared."); 295 } 296 private void NumberOfWorkers_ValueChanged(object sender, EventArgs e) { 297 if (ExecutionState == ExecutionState.Started) { 298 int workers = numberOfWorkers.Value; 299 int runningWorkers = clonedAlgorithms.Count(alg => alg.ExecutionState == ExecutionState.Started); 300 301 foreach (IAlgorithm algorithm in clonedAlgorithms) { 302 if (algorithm.ExecutionState == ExecutionState.Prepared || 303 algorithm.ExecutionState == ExecutionState.Paused) { 304 if (runningWorkers < workers) { 305 algorithm.Start(); 306 runningWorkers++; 307 } 308 } else if (algorithm.ExecutionState == ExecutionState.Started) { 309 if (runningWorkers > workers) { 310 algorithm.Pause(); 311 runningWorkers--; 312 } 313 } 314 } 315 } 316 } 317 318 #region template algorithms events 189 319 public event EventHandler AlgorithmChanged; 190 320 private void OnAlgorithmChanged() { … … 192 322 if (handler != null) handler(this, EventArgs.Empty); 193 323 OnProblemChanged(); 324 if (Problem == null) ExecutionState = ExecutionState.Stopped; 194 325 } 195 326 private void RegisterAlgorithmEvents() { 196 327 algorithm.ProblemChanged += new EventHandler(Algorithm_ProblemChanged); 328 algorithm.ExecutionStateChanged += new EventHandler(Algorithm_ExecutionStateChanged); 197 329 } 198 330 private void DeregisterAlgorithmEvents() { 199 331 algorithm.ProblemChanged -= new EventHandler(Algorithm_ProblemChanged); 332 algorithm.ExecutionStateChanged -= new EventHandler(Algorithm_ExecutionStateChanged); 200 333 } 201 334 private void Algorithm_ProblemChanged(object sender, EventArgs e) { … … 218 351 } 219 352 220 private void RegisterClonedAlgorithmEvents() { 353 private void Algorithm_ExecutionStateChanged(object sender, EventArgs e) { 354 switch (Algorithm.ExecutionState) { 355 case ExecutionState.Prepared: OnPrepared(); 356 break; 357 case ExecutionState.Started: throw new InvalidOperationException("Algorithm template can not be started."); 358 case ExecutionState.Paused: throw new InvalidOperationException("Algorithm template can not be paused."); 359 case ExecutionState.Stopped: OnStopped(); 360 break; 361 } 362 } 363 #endregion 364 365 #region clonedAlgorithms events 366 private void RegisterClonedAlgorithmsEvents() { 221 367 clonedAlgorithms.ItemsAdded += new CollectionItemsChangedEventHandler<IAlgorithm>(ClonedAlgorithms_ItemsAdded); 222 368 clonedAlgorithms.ItemsRemoved += new CollectionItemsChangedEventHandler<IAlgorithm>(ClonedAlgorithms_ItemsRemoved); 223 369 clonedAlgorithms.CollectionReset += new CollectionItemsChangedEventHandler<IAlgorithm>(ClonedAlgorithms_CollectionReset); 370 foreach (IAlgorithm algorithm in clonedAlgorithms) 371 RegisterClonedAlgorithmEvents(algorithm); 224 372 } 225 373 private void ClonedAlgorithms_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IAlgorithm> e) { … … 232 380 } 233 381 private void ClonedAlgorithms_CollectionReset(object sender, CollectionItemsChangedEventArgs<IAlgorithm> e) { 382 foreach (IAlgorithm algorithm in e.OldItems) 383 DeregisterClonedAlgorithmEvents(algorithm); 234 384 foreach (IAlgorithm algorithm in e.Items) 235 385 RegisterClonedAlgorithmEvents(algorithm); 236 foreach (IAlgorithm algorithm in e.OldItems)237 DeregisterClonedAlgorithmEvents(algorithm);238 386 } 239 387 private void RegisterClonedAlgorithmEvents(IAlgorithm algorithm) { 240 algorithm.ExceptionOccurred += new EventHandler<EventArgs<Exception>>( Algorithm_ExceptionOccurred);241 algorithm.ExecutionTimeChanged += new EventHandler( Algorithm_ExecutionTimeChanged);242 algorithm. Runs.ItemsAdded += new CollectionItemsChangedEventHandler<IRun>(Algorithm_Runs_Added);243 algorithm.Paused += new EventHandler( Algorithm_Paused);244 algorithm.Stopped += new EventHandler( Algorithm_Stopped);388 algorithm.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(ClonedAlgorithm_ExceptionOccurred); 389 algorithm.ExecutionTimeChanged += new EventHandler(ClonedAlgorithm_ExecutionTimeChanged); 390 algorithm.Started += new EventHandler(ClonedAlgorithm_Started); 391 algorithm.Paused += new EventHandler(ClonedAlgorithm_Paused); 392 algorithm.Stopped += new EventHandler(ClonedAlgorithm_Stopped); 245 393 } 246 394 private void DeregisterClonedAlgorithmEvents(IAlgorithm algorithm) { 247 algorithm.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>( Algorithm_ExceptionOccurred);248 algorithm.ExecutionTimeChanged += new EventHandler(Algorithm_ExecutionTimeChanged);249 algorithm. Runs.ItemsAdded -= new CollectionItemsChangedEventHandler<IRun>(Algorithm_Runs_Added);250 algorithm.Paused -= new EventHandler( Algorithm_Paused);251 algorithm.Stopped -= new EventHandler( Algorithm_Stopped);252 } 253 private void Algorithm_ExceptionOccurred(object sender, EventArgs<Exception> e) {395 algorithm.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(ClonedAlgorithm_ExceptionOccurred); 396 algorithm.ExecutionTimeChanged -= new EventHandler(ClonedAlgorithm_ExecutionTimeChanged); 397 algorithm.Started -= new EventHandler(ClonedAlgorithm_Started); 398 algorithm.Paused -= new EventHandler(ClonedAlgorithm_Paused); 399 algorithm.Stopped -= new EventHandler(ClonedAlgorithm_Stopped); 400 } 401 private void ClonedAlgorithm_ExceptionOccurred(object sender, EventArgs<Exception> e) { 254 402 OnExceptionOccurred(e.Value); 255 403 } 256 private void Algorithm_ExecutionTimeChanged(object sender, EventArgs e) {404 private void ClonedAlgorithm_ExecutionTimeChanged(object sender, EventArgs e) { 257 405 OnExecutionTimeChanged(); 258 406 } 259 private void Algorithm_Runs_Added(object sender, CollectionItemsChangedEventArgs<IRun> e) { 260 throw new NotImplementedException("TODO added finished run to actual results if the cross validation is running"); 261 } 262 private void Algorithm_Paused(object sender, EventArgs e) { 263 throw new NotImplementedException("TODO pause the cross validation if an algorithm no algorithm is running."); 264 } 265 private void Algorithm_Stopped(object sender, EventArgs e) { 266 throw new NotImplementedException("TODO stop the cross validation if all algorithms are stopped. and start remaining prepared algs"); 267 } 268 269 public event EventHandler ExecutionStateChanged; 270 private void OnExecutionStateChanged() { 271 EventHandler handler = ExecutionStateChanged; 272 if (handler != null) handler(this, EventArgs.Empty); 273 } 274 public event EventHandler ExecutionTimeChanged; 275 private void OnExecutionTimeChanged() { 276 EventHandler handler = ExecutionTimeChanged; 277 if (handler != null) handler(this, EventArgs.Empty); 278 } 279 public event EventHandler Prepared; 280 private void OnPrepared() { 281 ExecutionState = ExecutionState.Prepared; 282 EventHandler handler = Prepared; 283 if (handler != null) handler(this, EventArgs.Empty); 284 } 285 public event EventHandler Started; 286 private void OnStarted() { 287 ExecutionState = ExecutionState.Started; 288 EventHandler handler = Started; 289 if (handler != null) handler(this, EventArgs.Empty); 290 } 291 public event EventHandler Paused; 292 private void OnPaused() { 293 ExecutionState = ExecutionState.Paused; 294 EventHandler handler = Paused; 295 if (handler != null) handler(this, EventArgs.Empty); 296 } 297 public event EventHandler Stopped; 298 private void OnStopped() { 299 ExecutionState = ExecutionState.Stopped; 300 EventHandler handler = Stopped; 301 if (handler != null) handler(this, EventArgs.Empty); 302 } 303 public event EventHandler<EventArgs<Exception>> ExceptionOccurred; 304 private void OnExceptionOccurred(Exception exception) { 305 EventHandler<EventArgs<Exception>> handler = ExceptionOccurred; 306 if (handler != null) handler(this, new EventArgs<Exception>(exception)); 307 } 308 407 408 private readonly object locker = new object(); 409 private void ClonedAlgorithm_Started(object sender, EventArgs e) { 410 lock (locker) { 411 if (startPending) { 412 int startedAlgorithms = clonedAlgorithms.Count(alg => alg.ExecutionState == ExecutionState.Started); 413 if (startedAlgorithms == NumberOfWorkers.Value || 414 clonedAlgorithms.All(alg => alg.ExecutionState != ExecutionState.Prepared)) 415 startPending = false; 416 417 if (pausePending) PauseAllClonedAlgorithms(); 418 if (stopPending) StopAllClonedAlgorithms(); 419 } 420 } 421 } 422 423 private void ClonedAlgorithm_Paused(object sender, EventArgs e) { 424 lock (locker) { 425 if (pausePending && clonedAlgorithms.All(alg => alg.ExecutionState != ExecutionState.Started)) 426 OnPaused(); 427 } 428 } 429 430 private void ClonedAlgorithm_Stopped(object sender, EventArgs e) { 431 lock (locker) { 432 if (!stopPending && ExecutionState == ExecutionState.Started) { 433 IAlgorithm preparedAlgorithm = clonedAlgorithms.Where(alg => alg.ExecutionState == ExecutionState.Prepared || 434 alg.ExecutionState == ExecutionState.Paused).FirstOrDefault(); 435 if (preparedAlgorithm != null) preparedAlgorithm.Start(); 436 } 437 if (clonedAlgorithms.All(alg => alg.ExecutionState == ExecutionState.Stopped)) 438 OnStopped(); 439 else if (stopPending && clonedAlgorithms.All(alg => alg.ExecutionState == ExecutionState.Prepared || alg.ExecutionState == ExecutionState.Stopped)) 440 OnStopped(); 441 } 442 } 443 #endregion 444 445 #region run events 309 446 private void RegisterRunsEvents() { 310 447 runs.CollectionReset += new CollectionItemsChangedEventHandler<IRun>(Runs_CollectionReset); 311 448 runs.ItemsAdded += new CollectionItemsChangedEventHandler<IRun>(Runs_ItemsAdded); 312 449 runs.ItemsRemoved += new CollectionItemsChangedEventHandler<IRun>(Runs_ItemsRemoved); 313 }314 private void DeregisterRunsEvents() {315 runs.CollectionReset -= new CollectionItemsChangedEventHandler<IRun>(Runs_CollectionReset);316 runs.ItemsAdded -= new CollectionItemsChangedEventHandler<IRun>(Runs_ItemsAdded);317 runs.ItemsRemoved -= new CollectionItemsChangedEventHandler<IRun>(Runs_ItemsRemoved);318 450 } 319 451 private void Runs_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) { … … 348 480 } 349 481 #endregion 482 #endregion 483 484 #region event firing 485 public event EventHandler ExecutionStateChanged; 486 private void OnExecutionStateChanged() { 487 EventHandler handler = ExecutionStateChanged; 488 if (handler != null) handler(this, EventArgs.Empty); 489 } 490 public event EventHandler ExecutionTimeChanged; 491 private void OnExecutionTimeChanged() { 492 EventHandler handler = ExecutionTimeChanged; 493 if (handler != null) handler(this, EventArgs.Empty); 494 } 495 public event EventHandler Prepared; 496 private void OnPrepared() { 497 ExecutionState = ExecutionState.Prepared; 498 EventHandler handler = Prepared; 499 if (handler != null) handler(this, EventArgs.Empty); 500 } 501 public event EventHandler Started; 502 private void OnStarted() { 503 startPending = false; 504 ExecutionState = ExecutionState.Started; 505 EventHandler handler = Started; 506 if (handler != null) handler(this, EventArgs.Empty); 507 } 508 public event EventHandler Paused; 509 private void OnPaused() { 510 pausePending = false; 511 ExecutionState = ExecutionState.Paused; 512 EventHandler handler = Paused; 513 if (handler != null) handler(this, EventArgs.Empty); 514 } 515 public event EventHandler Stopped; 516 private void OnStopped() { 517 stopPending = false; 518 ExecutionState = ExecutionState.Stopped; 519 //TODO create run; 520 EventHandler handler = Stopped; 521 if (handler != null) handler(this, EventArgs.Empty); 522 } 523 public event EventHandler<EventArgs<Exception>> ExceptionOccurred; 524 private void OnExceptionOccurred(Exception exception) { 525 EventHandler<EventArgs<Exception>> handler = ExceptionOccurred; 526 if (handler != null) handler(this, new EventArgs<Exception>(exception)); 527 } 528 #endregion 350 529 } 351 530 } -
branches/HeuristicLab.Classification/HeuristicLab.Algorithms.DataAnalysis/3.3/HeuristicLabAlgorithmsDataAnalysisPlugin.cs.frame
r3877 r4542 26 26 /// Plugin class for HeuristicLab.Algorithms.DataAnalysis plugin. 27 27 /// </summary> 28 [Plugin("HeuristicLab.Algorithms.DataAnalysis", "3.3. 0.$WCREV$")]28 [Plugin("HeuristicLab.Algorithms.DataAnalysis", "3.3.1.$WCREV$")] 29 29 [PluginFile("HeuristicLab.Algorithms.DataAnalysis-3.3.dll", PluginFileType.Assembly)] 30 30 public class HeuristicLabAlgorithmsDataAnalysisPlugin : PluginBase { -
branches/HeuristicLab.Classification/HeuristicLab.Algorithms.DataAnalysis/3.3/Properties/AssemblyInfo.frame
r3877 r4542 53 53 // by using the '*' as shown below: 54 54 [assembly: AssemblyVersion("3.3.0.0")] 55 [assembly: AssemblyFileVersion("3.3. 0.$WCREV$")]55 [assembly: AssemblyFileVersion("3.3.1.$WCREV$")] -
branches/HeuristicLab.Classification/HeuristicLab.Problems.DataAnalysis.Classification.Views/3.3/HeuristicLabProblemsDataAnalysisClassificationViewsPlugin.cs.frame
r4417 r4542 23 23 24 24 namespace HeuristicLab.Problems.DataAnalysis.Classification.Views { 25 [Plugin("HeuristicLab.Problems.DataAnalysis.Classification.Views", "3.3. 0.$WCREV$")]25 [Plugin("HeuristicLab.Problems.DataAnalysis.Classification.Views", "3.3.1.$WCREV$")] 26 26 [PluginFile("HeuristicLab.Problems.DataAnalysis.Classification.Views-3.3.dll", PluginFileType.Assembly)] 27 27 public class HeuristicLabProblemsDataAnalysisClassificationViewsPlugin : PluginBase { -
branches/HeuristicLab.Classification/HeuristicLab.Problems.DataAnalysis.Classification.Views/3.3/Properties/AssemblyInfo.frame
r4417 r4542 52 52 // You can specify all the values or you can default the Build and Revision Numbers 53 53 // by using the '*' as shown below: 54 [assembly: AssemblyVersion("3.3. 0.0")]55 [assembly: AssemblyFileVersion("3.3. 0.$WCREV$")]54 [assembly: AssemblyVersion("3.3.1.0")] 55 [assembly: AssemblyFileVersion("3.3.1.$WCREV$")] -
branches/HeuristicLab.Classification/HeuristicLab.Problems.DataAnalysis.Classification/3.3/HeuristicLabProblemsDataAnalysisClassificationPlugin.cs.frame
r4366 r4542 23 23 24 24 namespace HeuristicLab.Problems.DataAnalysis.Classification { 25 [Plugin("HeuristicLab.Problems.DataAnalysis.Classification", "3.3. 0.$WCREV$")]25 [Plugin("HeuristicLab.Problems.DataAnalysis.Classification", "3.3.1.$WCREV$")] 26 26 [PluginFile("HeuristicLab.Problems.DataAnalysis.Classification-3.3.dll", PluginFileType.Assembly)] 27 27 public class HeuristicLabProblemsDataAnalysisClassificationPlugin : PluginBase { -
branches/HeuristicLab.Classification/HeuristicLab.Problems.DataAnalysis.Classification/3.3/Properties/AssemblyInfo.frame
r4323 r4542 52 52 // You can specify all the values or you can default the Build and Revision Numbers 53 53 // by using the '*' as shown below: 54 [assembly: AssemblyVersion("3.3. 0.0")]55 [assembly: AssemblyFileVersion("3.3. 0.$WCREV$")]54 [assembly: AssemblyVersion("3.3.1.0")] 55 [assembly: AssemblyFileVersion("3.3.1.$WCREV$")]
Note: See TracChangeset
for help on using the changeset viewer.