Changeset 15406 for stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 15371-15372,15390,15400,15402
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Views
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs
r15145 r15406 24 24 using System.Drawing; 25 25 using System.Linq; 26 using System.Threading.Tasks; 26 27 using System.Windows.Forms; 27 28 using HeuristicLab.Common; 28 29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 29 30 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views; 31 using HeuristicLab.MainForm; 30 32 using HeuristicLab.MainForm.WindowsForms; 31 33 … … 36 38 private Dictionary<ISymbolicExpressionTreeNode, double> nodeImpacts; 37 39 40 private readonly ISymbolicDataAnalysisSolutionImpactValuesCalculator impactCalculator; 41 42 private readonly IProgress progress = new Progress(); 43 38 44 private enum TreeState { Valid, Invalid } 39 45 private TreeState treeState; 40 46 41 protected InteractiveSymbolicDataAnalysisSolutionSimplifierView( ) {47 protected InteractiveSymbolicDataAnalysisSolutionSimplifierView(ISymbolicDataAnalysisSolutionImpactValuesCalculator impactCalculator) { 42 48 InitializeComponent(); 43 49 foldedNodes = new Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>(); … … 45 51 nodeImpacts = new Dictionary<ISymbolicExpressionTreeNode, double>(); 46 52 this.Caption = "Interactive Solution Simplifier"; 53 this.impactCalculator = impactCalculator; 47 54 48 55 // initialize the tree modifier that will be used to perform edit operations over the tree … … 145 152 Content.ProblemDataChanged += Content_Changed; 146 153 treeChart.Repainted += treeChart_Repainted; 154 MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(grpSimplify, progress); 147 155 } 148 156 protected override void DeregisterContentEvents() { … … 151 159 Content.ProblemDataChanged -= Content_Changed; 152 160 treeChart.Repainted -= treeChart_Repainted; 161 MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(grpSimplify, false); 153 162 } 154 163 … … 169 178 } 170 179 171 private void UpdateView() {180 private async void UpdateView() { 172 181 if (Content == null || Content.Model == null || Content.ProblemData == null) return; 173 182 var tree = Content.Model.SymbolicExpressionTree; 174 183 treeChart.Tree = tree.Root.SubtreeCount > 1 ? new SymbolicExpressionTree(tree.Root) : new SymbolicExpressionTree(tree.Root.GetSubtree(0).GetSubtree(0)); 175 184 176 var impactAndReplacementValues = CalculateImpactAndReplacementValues(tree); 185 progress.Start("Calculate Impact and Replacement Values ..."); 186 var impactAndReplacementValues = await Task.Run(() => CalculateImpactAndReplacementValues(tree)); 187 await Task.Delay(500); // wait for progressbar to finish animation 177 188 var replacementValues = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item2); 178 189 foreach (var pair in replacementValues.Where(pair => !(pair.Key is ConstantTreeNode))) { … … 180 191 } 181 192 nodeImpacts = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item1); 193 progress.Finish(); 182 194 PaintNodeImpacts(); 183 195 } 184 196 185 protected abstract Dictionary<ISymbolicExpressionTreeNode, Tuple<double, double>> CalculateImpactAndReplacementValues(ISymbolicExpressionTree tree); 197 protected virtual Dictionary<ISymbolicExpressionTreeNode, Tuple<double, double>> CalculateImpactAndReplacementValues(ISymbolicExpressionTree tree) { 198 var impactAndReplacementValues = new Dictionary<ISymbolicExpressionTreeNode, Tuple<double, double>>(); 199 foreach (var node in tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix()) { 200 double impactValue, replacementValue, newQualityForImpactsCalculation; 201 impactCalculator.CalculateImpactAndReplacementValues(Content.Model, node, Content.ProblemData, Content.ProblemData.TrainingIndices, out impactValue, out replacementValue, out newQualityForImpactsCalculation); 202 double newProgressValue = progress.ProgressValue + 1.0 / (tree.Length - 2); 203 progress.ProgressValue = Math.Min(newProgressValue, 1); 204 impactAndReplacementValues.Add(node, new Tuple<double, double>(impactValue, replacementValue)); 205 } 206 return impactAndReplacementValues; 207 } 208 186 209 protected abstract void UpdateModel(ISymbolicExpressionTree tree); 210 211 protected virtual ISymbolicExpressionTree OptimizeConstants(ISymbolicExpressionTree tree, IProgress progress) { 212 return tree; 213 } 187 214 188 215 private static ConstantTreeNode MakeConstantTreeNode(double value) { … … 270 297 } 271 298 272 protected abstract void btnOptimizeConstants_Click(object sender, EventArgs e); 299 private async void btnOptimizeConstants_Click(object sender, EventArgs e) { 300 progress.Start("Optimizing Constants ..."); 301 var tree = (ISymbolicExpressionTree)Content.Model.SymbolicExpressionTree.Clone(); 302 var newTree = await Task.Run(() => OptimizeConstants(tree, progress)); 303 await Task.Delay(500); // wait for progressbar to finish animation 304 UpdateModel(newTree); // UpdateModel calls Progress.Finish (via Content_Changed) 305 } 273 306 } 274 307 }
Note: See TracChangeset
for help on using the changeset viewer.