Index: branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks/3.3/Plugin.cs.frame
===================================================================
--- branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks/3.3/Plugin.cs.frame	(revision 12462)
+++ branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks/3.3/Plugin.cs.frame	(revision 12568)
@@ -47,5 +47,5 @@
   [PluginDependency("HeuristicLab.Problems.DataAnalysis.Symbolic", "3.4")]
   [PluginDependency("HeuristicLab.Problems.DataAnalysis", "3.4")]
-  [PluginDependency("HeuristicLab.Problems.Instances", "3.4")]
+  [PluginDependency("HeuristicLab.Problems.Instances", "3.3")]
   [PluginDependency("HeuristicLab.Encodings.SymbolicExpressionTreeEncoding", "3.4")]  
   public class Plugin : PluginBase {
Index: branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks/3.3/SymbolicDataAnalysisVariableImpactsAnalyzer.cs
===================================================================
--- branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks/3.3/SymbolicDataAnalysisVariableImpactsAnalyzer.cs	(revision 12462)
+++ branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks/3.3/SymbolicDataAnalysisVariableImpactsAnalyzer.cs	(revision 12568)
@@ -11,4 +11,5 @@
 using HeuristicLab.Problems.DataAnalysis.Symbolic;
 using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
+using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
 
 namespace HeuristicLab.VariableInteractionNetworks
@@ -33,8 +34,9 @@
         private const string LastGenerationsParameterName = "LastGenerations";
         private const string MaximumGenerationsParameterName = "MaximumGenerations";
-        private const string OptimizedConstantsParameterName = "OptimizedConstants";
-        
-        private readonly SymbolicDataAnalysisExpressionTreeSimplifier simplifier;
-        private readonly SymbolicRegressionSolutionImpactValuesCalculator impactsCalculator;
+        private const string OptimizeConstantsParameterName = "OptimizeConstants";
+        private const string PruneTreesParameterName = "PruneTrees";
+
+        private SymbolicDataAnalysisExpressionTreeSimplifier simplifier;
+        private SymbolicRegressionSolutionImpactValuesCalculator impactsCalculator;
 
         #region parameters
@@ -87,7 +89,11 @@
             get { return (IFixedValueParameter<IntValue>)Parameters[LastGenerationsParameterName]; }
         }
-        public IFixedValueParameter<BoolValue> OptimizedParameter
-        {
-            get { return (IFixedValueParameter<BoolValue>)Parameters[OptimizedConstantsParameterName]; }
+        public IFixedValueParameter<BoolValue> OptimizeConstantsParameter
+        {
+            get { return (IFixedValueParameter<BoolValue>)Parameters[OptimizeConstantsParameterName]; }
+        }
+        public IFixedValueParameter<BoolValue> PruneTreesParameter
+        {
+            get { return (IFixedValueParameter<BoolValue>)Parameters[PruneTreesParameterName]; }
         }
         private ILookupParameter<IntValue> MaximumGenerationsParameter
@@ -119,13 +125,14 @@
             Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName));
             Parameters.Add(new LookupParameter<DoubleLimit>(EstimationLimitsParameterName));
-            Parameters.Add(new FixedValueParameter<IntValue>(MaxCOIterationsParameterName));         
+            Parameters.Add(new FixedValueParameter<IntValue>(MaxCOIterationsParameterName));
             Parameters.Add(new LookupParameter<DataTable>(VariableImpactsParameterName, "The relative variable relevance calculated as the average relative variable frequency over the whole run."));
             Parameters.Add(new FixedValueParameter<PercentValue>(PercentageBestParameterName));
             Parameters.Add(new FixedValueParameter<IntValue>(LastGenerationsParameterName));
-            Parameters.Add(new FixedValueParameter<BoolValue>(OptimizedConstantsParameterName));
+            Parameters.Add(new FixedValueParameter<BoolValue>(OptimizeConstantsParameterName, new BoolValue(false)));
+            Parameters.Add(new FixedValueParameter<BoolValue>(PruneTreesParameterName, new BoolValue(false)));
             Parameters.Add(new LookupParameter<IntValue>(MaximumGenerationsParameterName, "The maximum number of generations which should be processed."));
 
+            impactsCalculator = new SymbolicRegressionSolutionImpactValuesCalculator();
             simplifier = new SymbolicDataAnalysisExpressionTreeSimplifier();
-            impactsCalculator = new SymbolicRegressionSolutionImpactValuesCalculator();
         }
 
@@ -133,7 +140,16 @@
         protected SymbolicRegressionVariableImpactsAnalyzer(bool deserializing) : base(deserializing) { }
 
+        [StorableHook(HookType.AfterDeserialization)]
+        private void AfterDeserialization()
+        {
+            impactsCalculator = new SymbolicRegressionSolutionImpactValuesCalculator();
+            simplifier = new SymbolicDataAnalysisExpressionTreeSimplifier();
+        }
+
         protected SymbolicRegressionVariableImpactsAnalyzer(SymbolicRegressionVariableImpactsAnalyzer original, Cloner cloner)
             : base(original, cloner)
         {
+            impactsCalculator = new SymbolicRegressionSolutionImpactValuesCalculator();
+            simplifier = new SymbolicDataAnalysisExpressionTreeSimplifier();
         }
 
@@ -158,7 +174,5 @@
             int lastGen = LastGenerationsParameter.Value.Value;
 
-            if (lastGen > maxGen)
-                lastGen = maxGen;
-            if (maxGen - gen < lastGen)
+            if (gen < maxGen - lastGen)
                 return base.Apply();
 
@@ -176,5 +190,6 @@
             var estimationLimits = EstimationLimitsParameter.ActualValue; // lookup parameter => ActualValue
             var percentageBest = PercentageBestParameter.Value.Value;
-            var optimizedConstants = OptimizedParameter.Value.Value;
+            var optimizeConstants = OptimizeConstantsParameter.Value.Value;
+            var pruneTrees = PruneTreesParameter.Value.Value;
 
             var allowedInputVariables = problemData.AllowedInputVariables.ToList();
@@ -188,5 +203,5 @@
                 VariableImpactsParameter.ActualValue = datatable;
                 results.Add(new Result("Average variable impacts", "The relative variable relevance calculated as the average relative variable frequency over the whole run.", new DataTable()));
-                
+
                 foreach (var v in allowedInputVariables)
                 {
@@ -197,14 +212,19 @@
             datatable = VariableImpactsParameter.ActualValue;
             int nTrees = (int)Math.Round(trees.Length * percentageBest);
-
-            // simplify trees
-            var simplifiedTrees = trees.Take(nTrees).Select(x => simplifier.Simplify(x));
+            var bestTrees = trees.Take(nTrees).Select(x => (ISymbolicExpressionTree)x.Clone()).ToList();
+
+            if (optimizeConstants)
+            {
+                foreach (var tree in bestTrees)
+                    SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, tree, problemData, problemData.TrainingIndices, applyLinearScaling, maxCOIterations, estimationLimits.Upper, estimationLimits.Lower);
+            }
+            var simplifiedTrees = bestTrees.Select(x => simplifier.Simplify(x)).ToList();
             var variableCounts = problemData.AllowedInputVariables.ToDictionary(x => x, x => simplifiedTrees.Count(t => t.IterateNodesPrefix().Any(n => n is VariableTreeNode && ((VariableTreeNode)n).VariableName == x)));
-            foreach (var simplifiedTree in simplifiedTrees)
-            {
-                if (optimizedConstants == true)
-                {
-                    SymbolicRegressionConstantOptimizationEvaluator.OptimizeConstants(interpreter, simplifiedTree, problemData, problemData.TrainingIndices, applyLinearScaling, maxCOIterations, estimationLimits.Upper, estimationLimits.Lower);
-                }
+            for (int i = 0; i < simplifiedTrees.Count; ++i)
+            {
+                var simplifiedTree = simplifiedTrees[i];
+
+                if (pruneTrees)
+                    simplifiedTree = SymbolicRegressionPruningOperator.Prune(simplifiedTree, impactsCalculator, interpreter, problemData, estimationLimits, problemData.TrainingIndices);
 
                 var quality = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate(interpreter, simplifiedTree, estimationLimits.Lower, estimationLimits.Upper, problemData, problemData.TrainingIndices, applyLinearScaling);
@@ -216,4 +236,6 @@
                 {
                     var avgImpact = g.Average(x => impactsCalculator.CalculateImpactValue(model, x, problemData, problemData.TrainingIndices, quality));
+                    if (double.IsNaN(avgImpact))
+                        avgImpact = 0;
                     variableImpacts[g.Key] += avgImpact;
                 }
@@ -222,5 +244,6 @@
             foreach (var pair in variableImpacts)
             {
-                datatable.Rows[pair.Key].Values.Add(pair.Value / variableCounts[pair.Key]);
+                var v = variableCounts[pair.Key] > 0 ? pair.Value / variableCounts[pair.Key] : 0;
+                datatable.Rows[pair.Key].Values.Add(v);
             }
             results["Average variable impacts"].Value = datatable;
