Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/07/17 15:32:26 (7 years ago)
Author:
pfleck
Message:

#1666:

  • Changed Progress interface (single parameterless ctor, overloads for Start-method).
  • Passed Impact-Calculator per ctor argument instead of virtual properties.
  • Created virtual OptimizeConstants-method instead of making the button-click event-handler virtual.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/SimplifierViewsProgress/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs

    r15321 r15353  
    3838    private Dictionary<ISymbolicExpressionTreeNode, double> nodeImpacts;
    3939
    40     protected IProgress Progress = new Progress();
     40    private readonly ISymbolicDataAnalysisSolutionImpactValuesCalculator impactCalculator;
     41
     42    private readonly IProgress progress = new Progress();
    4143
    4244    private enum TreeState { Valid, Invalid }
    4345    private TreeState treeState;
    4446
    45     protected InteractiveSymbolicDataAnalysisSolutionSimplifierView() {
     47    protected InteractiveSymbolicDataAnalysisSolutionSimplifierView(ISymbolicDataAnalysisSolutionImpactValuesCalculator impactCalculator) {
    4648      InitializeComponent();
    4749      foldedNodes = new Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>();
     
    4951      nodeImpacts = new Dictionary<ISymbolicExpressionTreeNode, double>();
    5052      this.Caption = "Interactive Solution Simplifier";
     53      this.impactCalculator = impactCalculator;
    5154
    5255      // initialize the tree modifier that will be used to perform edit operations over the tree
     
    149152      Content.ProblemDataChanged += Content_Changed;
    150153      treeChart.Repainted += treeChart_Repainted;
    151       MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(grpSimplify, Progress);
     154      MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(grpSimplify, progress);
    152155    }
    153156    protected override void DeregisterContentEvents() {
     
    180183      treeChart.Tree = tree.Root.SubtreeCount > 1 ? new SymbolicExpressionTree(tree.Root) : new SymbolicExpressionTree(tree.Root.GetSubtree(0).GetSubtree(0));
    181184
    182       Progress.Start("Calculate Impact and Replacement Values ...", 0);
     185      progress.Start("Calculate Impact and Replacement Values ...", 0);
    183186      var impactAndReplacementValues = await Task.Run(() => CalculateImpactAndReplacementValues(tree));
    184187      var replacementValues = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item2);
     
    187190      }
    188191      nodeImpacts = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item1);
    189       Progress.Finish();
     192      progress.Finish();
    190193      PaintNodeImpacts();
    191194    }
     
    195198      foreach (var node in tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix()) {
    196199        double impactValue, replacementValue, newQualityForImpactsCalculation;
    197         ImpactCalculator.CalculateImpactAndReplacementValues(Content.Model, node, Content.ProblemData, Content.ProblemData.TrainingIndices, out impactValue, out replacementValue, out newQualityForImpactsCalculation);
    198         Progress.ProgressValue += 1.0 / (tree.Length - 2);
     200        impactCalculator.CalculateImpactAndReplacementValues(Content.Model, node, Content.ProblemData, Content.ProblemData.TrainingIndices, out impactValue, out replacementValue, out newQualityForImpactsCalculation);
     201        progress.ProgressValue += 1.0 / (tree.Length - 2);
    199202        impactAndReplacementValues.Add(node, new Tuple<double, double>(impactValue, replacementValue));
    200203      }
     
    204207    protected abstract void UpdateModel(ISymbolicExpressionTree tree);
    205208
    206     protected abstract ISymbolicDataAnalysisSolutionImpactValuesCalculator ImpactCalculator { get; }
     209    protected virtual ISymbolicExpressionTree OptimizeConstants(ISymbolicDataAnalysisModel model, IDataAnalysisProblemData problemData, IProgress progress) {
     210      return model.SymbolicExpressionTree;
     211    }
    207212
    208213    private static ConstantTreeNode MakeConstantTreeNode(double value) {
     
    290295    }
    291296
    292     protected abstract void btnOptimizeConstants_Click(object sender, EventArgs e);
     297    private async void btnOptimizeConstants_Click(object sender, EventArgs e) {
     298      progress.Start("Optimizing Constants ...", 0);
     299      var newTree = await Task.Run(() => OptimizeConstants(Content.Model, Content.ProblemData, progress));
     300      UpdateModel(newTree); // UpdateModel calls Progress.Finish (via Content_Changed)
     301    }
    293302  }
    294303}
Note: See TracChangeset for help on using the changeset viewer.