Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/04/19 14:45:47 (5 years ago)
Author:
mkommend
Message:

#2845: Merged 16430 into stable.

Location:
stable
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Views

  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs

    r15584 r17062  
    2424using System.Drawing;
    2525using System.Linq;
     26using System.Threading;
    2627using System.Threading.Tasks;
    2728using System.Windows.Forms;
     
    4041    private readonly ISymbolicDataAnalysisSolutionImpactValuesCalculator impactCalculator;
    4142
    42     private readonly IProgress progress = new Progress();
     43    private readonly Progress progress = new Progress();
     44    private CancellationTokenSource cancellationTokenSource;
    4345
    4446    private enum TreeState { Valid, Invalid }
     
    152154      Content.ProblemDataChanged += Content_Changed;
    153155      treeChart.Repainted += treeChart_Repainted;
    154       MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(grpSimplify, progress);
     156      Progress.ShowOnControl(grpSimplify, progress);
     157      progress.StopRequested += progress_StopRequested;
    155158    }
    156159    protected override void DeregisterContentEvents() {
     
    159162      Content.ProblemDataChanged -= Content_Changed;
    160163      treeChart.Repainted -= treeChart_Repainted;
    161       MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(grpSimplify, false);
     164      Progress.HideFromControl(grpSimplify, false);
     165      progress.StopRequested -= progress_StopRequested;
    162166    }
    163167
     
    178182    }
    179183
     184    private void progress_StopRequested(object sender, EventArgs e) {
     185      cancellationTokenSource.Cancel();
     186    }
     187
    180188    private async void UpdateView() {
    181189      if (Content == null || Content.Model == null || Content.ProblemData == null) return;
     
    184192
    185193      progress.Start("Calculate Impact and Replacement Values ...");
     194      progress.CanBeStopped = true;
     195      cancellationTokenSource = new CancellationTokenSource();
    186196      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) { }
    188200      var replacementValues = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item2);
    189201      foreach (var pair in replacementValues.Where(pair => !(pair.Key is ConstantTreeNode))) {
     
    192204      nodeImpacts = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item1);
    193205      progress.Finish();
     206      progress.CanBeStopped = false;
    194207      PaintNodeImpacts();
    195208    }
     
    198211      var impactAndReplacementValues = new Dictionary<ISymbolicExpressionTreeNode, Tuple<double, double>>();
    199212      foreach (var node in tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix()) {
     213        if (progress.ProgressState == ProgressState.StopRequested) continue;
    200214        double impactValue, replacementValue, newQualityForImpactsCalculation;
    201215        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.