Index: /branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Views-3.4.csproj
===================================================================
--- /branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Views-3.4.csproj	(revision 7421)
+++ /branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Views-3.4.csproj	(revision 7422)
@@ -217,12 +217,4 @@
     </BootstrapperPackage>
   </ItemGroup>
-  <ItemGroup>
-    <EmbeddedResource Include="InteractiveSymbolicDataAnalysisSolutionSimplifierView.resx">
-      <DependentUpon>InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs</DependentUpon>
-    </EmbeddedResource>
-    <EmbeddedResource Include="SymbolicExpressionTreeNodeChangeValueDialog.resx">
-      <DependentUpon>SymbolicExpressionTreeNodeChangeValueDialog.cs</DependentUpon>
-    </EmbeddedResource>
-  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
Index: /branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs
===================================================================
--- /branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs	(revision 7421)
+++ /branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs	(revision 7422)
@@ -37,5 +37,6 @@
     private Dictionary<ISymbolicExpressionTreeNode, double> originalValues;
     private bool updateInProgress = false;
-    private VisualSymbolicExpressionTreeNode visualTreeNode; // need some kind of state for correctly handling events 
+    private VisualSymbolicExpressionTreeNode visualTreeNode; // for correctly handling events when changing node values
+    private ISymbolicExpressionTree model;
 
     public InteractiveSymbolicDataAnalysisSolutionSimplifierView() {
@@ -71,48 +72,77 @@
 
     protected virtual void OnModelChanged() {
-      this.CalculateReplacementNodesAndNodeImpacts();
+      model = (model == null)
+                ? (ISymbolicExpressionTree)Content.Model.SymbolicExpressionTree.Clone()
+                : Content.Model.SymbolicExpressionTree;
+      this.CalculateReplacementNodesAndNodeImpacts(model);
+      this.PaintModel();
     }
 
     protected virtual void OnProblemDataChanged() {
       this.CalculateReplacementNodesAndNodeImpacts();
+      this.PaintModel();
     }
 
     protected override void OnContentChanged() {
+      model = (model == null)
+          ? (ISymbolicExpressionTree)Content.Model.SymbolicExpressionTree.Clone()
+          : Content.Model.SymbolicExpressionTree;
       base.OnContentChanged();
-      this.CalculateReplacementNodesAndNodeImpacts();
+      this.CalculateReplacementNodesAndNodeImpacts(model);
+      this.PaintModel();
       this.viewHost.Content = this.Content;
     }
 
     private void CalculateReplacementNodesAndNodeImpacts() {
-      if (Content != null && Content.Model != null && Content.ProblemData != null) {
-        var tree = Content.Model.SymbolicExpressionTree;
-        var replacementValues = CalculateReplacementValues(tree);
-        foreach (var pair in replacementValues) {
-          if (!(pair.Key is ConstantTreeNode)) {
-            replacementNodes[pair.Key] = MakeConstantTreeNode(pair.Value);
-          }
-        }
-        nodeImpacts = CalculateImpactValues(Content.Model.SymbolicExpressionTree);
-
-        if (!updateInProgress) {
-          // automatically fold all branches with impact = 0
-          List<ISymbolicExpressionTreeNode> nodeList = Content.Model.SymbolicExpressionTree.Root.GetSubtree(0).IterateNodesPrefix().ToList();
-          foreach (var parent in nodeList) {
-            for (int subTreeIndex = 0; subTreeIndex < parent.SubtreeCount; subTreeIndex++) {
-              var child = parent.GetSubtree(subTreeIndex);
-              if (!(child.Symbol is Constant) && nodeImpacts[child].IsAlmost(0.0)) {
-                SwitchNodeWithReplacementNode(parent, subTreeIndex);
-              }
+      if (Content == null || Content.Model == null || Content.ProblemData == null) return;
+      //var tree = Content.Model.SymbolicExpressionTree;
+      var tree = model;
+      var replacementValues = CalculateReplacementValues(tree);
+      foreach (var pair in replacementValues.Where(pair => !(pair.Key is ConstantTreeNode))) {
+        replacementNodes[pair.Key] = MakeConstantTreeNode(pair.Value);
+      }
+      nodeImpacts = CalculateImpactValues(tree);
+
+      if (!updateInProgress) {
+        // automatically fold all branches with impact = 0
+        List<ISymbolicExpressionTreeNode> nodeList = tree.Root.GetSubtree(0).IterateNodesPrefix().ToList();
+        foreach (var parent in nodeList) {
+          for (int subTreeIndex = 0; subTreeIndex < parent.SubtreeCount; subTreeIndex++) {
+            var child = parent.GetSubtree(subTreeIndex);
+            if (!(child.Symbol is Constant) && nodeImpacts[child].IsAlmost(0.0)) {
+              SwitchNodeWithReplacementNode(parent, subTreeIndex);
             }
           }
         }
-
-        // show only interesting part of solution 
-        if (tree.Root.SubtreeCount > 1)
-          this.treeChart.Tree = new SymbolicExpressionTree(tree.Root); // RPB + ADFs
-        else
-          this.treeChart.Tree = new SymbolicExpressionTree(tree.Root.GetSubtree(0).GetSubtree(0)); // 1st child of RPB
-        this.PaintNodeImpacts();
-      }
+      }
+      PaintModel();
+    }
+
+    private void CalculateReplacementNodesAndNodeImpacts(ISymbolicExpressionTree tree) {
+      var replacementValues = CalculateReplacementValues(tree);
+      foreach (var pair in replacementValues.Where(pair => !(pair.Key is ConstantTreeNode))) {
+        replacementNodes[pair.Key] = MakeConstantTreeNode(pair.Value);
+      }
+      nodeImpacts = CalculateImpactValues(tree);
+
+      if (!updateInProgress) {
+        // automatically fold all branches with impact = 0
+        List<ISymbolicExpressionTreeNode> nodeList = tree.Root.GetSubtree(0).IterateNodesPrefix().ToList();
+        foreach (var parent in nodeList) {
+          for (int subTreeIndex = 0; subTreeIndex < parent.SubtreeCount; subTreeIndex++) {
+            var child = parent.GetSubtree(subTreeIndex);
+            if (!(child.Symbol is Constant) && nodeImpacts[child].IsAlmost(0.0)) {
+              SwitchNodeWithReplacementNode(parent, subTreeIndex);
+            }
+          }
+        }
+      }
+      PaintModel();
+    }
+
+    private void PaintModel() {
+      // show only interesting part of solution 
+      this.treeChart.Tree = model.Root.SubtreeCount > 1 ? new SymbolicExpressionTree(model.Root) : new SymbolicExpressionTree(model.Root.GetSubtree(0).GetSubtree(0));
+      this.PaintNodeImpacts();
     }
 
@@ -132,5 +162,5 @@
     private void treeChart_SymbolicExpressionTreeNodeDoubleClicked(object sender, MouseEventArgs e) {
       visualTreeNode = (VisualSymbolicExpressionTreeNode)sender;
-      var tree = Content.Model.SymbolicExpressionTree;
+      var tree = model;
       // check if the node value/weight has been altered
       // if so, the first double click will return the node to its original value/weight
@@ -219,5 +249,4 @@
       var value = double.Parse(textBox.Text);
       var subTree = visualTreeNode.SymbolicExpressionTreeNode;
-      var tree = Content.Model.SymbolicExpressionTree;
 
       if (subTree.Symbol is Constant)
@@ -226,9 +255,5 @@
         (subTree as VariableTreeNode).Weight = value;
 
-      // show only interesting part of solution 
-      treeChart.Tree = tree.Root.SubtreeCount > 1 ? new SymbolicExpressionTree(tree.Root) : new SymbolicExpressionTree(tree.Root.GetSubtree(0).GetSubtree(0));
-      updateInProgress = true;
-      UpdateModel(tree);
-      updateInProgress = false;
+      PaintModel();
     }
 
@@ -249,5 +274,5 @@
       double max = impacts.Max();
       double min = impacts.Min();
-      foreach (ISymbolicExpressionTreeNode treeNode in Content.Model.SymbolicExpressionTree.IterateNodesPostfix()) {
+      foreach (ISymbolicExpressionTreeNode treeNode in model.IterateNodesPostfix()) {
         VisualSymbolicExpressionTreeNode visualTree = treeChart.GetVisualSymbolicExpressionTreeNode(treeNode);
         bool flag1 = replacementNodes.ContainsKey(treeNode);
@@ -287,5 +312,5 @@
 
     private void PaintCollapsedNodes() {
-      foreach (ISymbolicExpressionTreeNode treeNode in Content.Model.SymbolicExpressionTree.IterateNodesPostfix()) {
+      foreach (ISymbolicExpressionTreeNode treeNode in model.IterateNodesPostfix()) {
         bool flag1 = replacementNodes.ContainsKey(treeNode);
         bool flag2 = originalValues.ContainsKey(treeNode);
@@ -300,12 +325,48 @@
     private void btnSimplify_Click(object sender, EventArgs e) {
       SymbolicDataAnalysisExpressionTreeSimplifier simplifier = new SymbolicDataAnalysisExpressionTreeSimplifier();
-      var simplifiedExpressionTree = simplifier.Simplify(Content.Model.SymbolicExpressionTree);
+      var simplifiedExpressionTree = simplifier.Simplify(model);
       UpdateModel(simplifiedExpressionTree);
     }
 
+    protected abstract void btnOptimizeConstants_Click(object sender, EventArgs e);
+
     private void btnPrune_Click(object sender, EventArgs e) {
+      btnPrune.Enabled = false;
       backgroundWorker1.RunWorkerAsync();
     }
 
+    private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) {
+      var worker = sender as BackgroundWorker;
+      PruneTree(worker);
+    }
+
+    private void PruneTree(BackgroundWorker worker) {
+      var tree = model;
+      // get all tree nodes 
+      foreach (var node in GetNodesAtDepth(tree.Root, new Data.IntRange(2, tree.Depth))) {
+        if (worker.CancellationPending)
+          break; // pruning cancelled
+        if (!(node.Symbol is Constant) && nodeImpacts.ContainsKey(node) && nodeImpacts[node] < 0.001) {
+          SwitchNodeWithReplacementNode(node.Parent, node.Parent.IndexOfSubtree(node));
+          nodeImpacts = CalculateImpactValues(tree);
+          // we do not refresh the replacementValues because they won't change when folding nodes with such low impacts (<0.001)
+        }
+      }
+    }
+
+    private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
+      if (e.Cancelled) {
+        // The user canceled the operation.
+      } else if (e.Error != null) {
+        // There was an error during the operation.
+        // Error-handling
+      } else {
+        // The operation completed normally. We can update the model
+        UpdateModel(model);
+      }
+      btnPrune.Enabled = true;
+    }
+
+    #region helpers
     private static IEnumerable<ISymbolicExpressionTreeNode> GetNodesAtDepth(ISymbolicExpressionTreeNode root, Data.IntRange range) {
       var list = new List<Tuple<ISymbolicExpressionTreeNode, int>> { new Tuple<ISymbolicExpressionTreeNode, int>(root, 0) };
@@ -328,37 +389,5 @@
       }
     }
-
-    protected abstract void btnOptimizeConstants_Click(object sender, EventArgs e);
-
-    private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) {
-      BackgroundWorker worker = sender as BackgroundWorker;
-      PruneTree(worker);
-
-    }
-
-    private void PruneTree(BackgroundWorker worker) {
-      var tree = Content.Model.SymbolicExpressionTree;
-      // get all tree nodes 
-      foreach (var node in GetNodesAtDepth(tree.Root, new Data.IntRange(2, tree.Depth))) {
-        if (worker.CancellationPending)
-          break; // pruning cancelled
-        if (!(node.Symbol is Constant) && nodeImpacts.ContainsKey(node) && nodeImpacts[node] < 0.001) {
-          SwitchNodeWithReplacementNode(node.Parent, node.Parent.IndexOfSubtree(node));
-          CalculateReplacementNodesAndNodeImpacts();
-        }
-      }
-    }
-
-    private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
-      if (e.Cancelled) {
-        // The user canceled the operation.
-      } else if (e.Error != null) {
-        // There was an error during the operation.
-        // Error-handling
-      } else {
-        // The operation completed normally. We can update the model
-        UpdateModel(Content.Model.SymbolicExpressionTree);
-      }
-    }
+    #endregion
   }
 }
