Changeset 16723 for branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs
- Timestamp:
- 03/28/19 16:54:20 (6 years ago)
- Location:
- branches/2521_ProblemRefactoring
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring
- Property svn:mergeinfo changed
-
branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Views
- Property svn:mergeinfo changed
-
branches/2521_ProblemRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs
r16692 r16723 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 8Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 24 24 using System.Drawing; 25 25 using System.Linq; 26 using System.Threading; 26 27 using System.Threading.Tasks; 27 28 using System.Windows.Forms; … … 40 41 private readonly ISymbolicDataAnalysisSolutionImpactValuesCalculator impactCalculator; 41 42 42 private readonly IProgress progress = new Progress(); 43 private readonly Progress progress = new Progress(); 44 private CancellationTokenSource cancellationTokenSource; 43 45 44 46 private enum TreeState { Valid, Invalid } … … 152 154 Content.ProblemDataChanged += Content_Changed; 153 155 treeChart.Repainted += treeChart_Repainted; 154 MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(grpSimplify, progress); 156 Progress.ShowOnControl(grpSimplify, progress); 157 progress.StopRequested += progress_StopRequested; 155 158 } 156 159 protected override void DeregisterContentEvents() { … … 159 162 Content.ProblemDataChanged -= Content_Changed; 160 163 treeChart.Repainted -= treeChart_Repainted; 161 MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(grpSimplify, false); 164 Progress.HideFromControl(grpSimplify, false); 165 progress.StopRequested -= progress_StopRequested; 162 166 } 163 167 … … 178 182 } 179 183 184 private void progress_StopRequested(object sender, EventArgs e) { 185 cancellationTokenSource.Cancel(); 186 } 187 180 188 private async void UpdateView() { 181 189 if (Content == null || Content.Model == null || Content.ProblemData == null) return; … … 184 192 185 193 progress.Start("Calculate Impact and Replacement Values ..."); 194 progress.CanBeStopped = true; 195 cancellationTokenSource = new CancellationTokenSource(); 186 196 var impactAndReplacementValues = await Task.Run(() => CalculateImpactAndReplacementValues(tree)); 187 await Task.Delay(500); // wait for progressbar to finish animation 197 try { 198 await Task.Delay(500, cancellationTokenSource.Token); // wait for progressbar to finish animation 199 } catch (OperationCanceledException) { } 188 200 var replacementValues = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item2); 189 201 foreach (var pair in replacementValues.Where(pair => !(pair.Key is ConstantTreeNode))) { … … 192 204 nodeImpacts = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item1); 193 205 progress.Finish(); 206 progress.CanBeStopped = false; 194 207 PaintNodeImpacts(); 195 208 } … … 198 211 var impactAndReplacementValues = new Dictionary<ISymbolicExpressionTreeNode, Tuple<double, double>>(); 199 212 foreach (var node in tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix()) { 213 if (progress.ProgressState == ProgressState.StopRequested) continue; 200 214 double impactValue, replacementValue, newQualityForImpactsCalculation; 201 215 impactCalculator.CalculateImpactAndReplacementValues(Content.Model, node, Content.ProblemData, Content.ProblemData.TrainingIndices, out impactValue, out replacementValue, out newQualityForImpactsCalculation);
Note: See TracChangeset
for help on using the changeset viewer.