Index: trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisComplexityAnalyzer.cs
===================================================================
--- trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisComplexityAnalyzer.cs	(revision 7726)
+++ trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisComplexityAnalyzer.cs	(revision 7726)
@@ -0,0 +1,144 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using HeuristicLab.Analysis;
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
+using HeuristicLab.Optimization;
+using HeuristicLab.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+using HeuristicLab.PluginInfrastructure;
+using HeuristicLab.PluginInfrastructure.Manager;
+
+namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
+  /// <summary>
+  /// Calculates the complexity of all trees in the population.
+  /// </summary>
+  [Item("SymbolicDataAnalysisComplexityAnalyzer", "Calculates the complexity of all trees in the population.")]
+  [StorableClass]
+  public sealed class SymbolicDataAnalysisComplexityAnalyzer : SymbolicDataAnalysisAnalyzer {
+    private const string ComplexityParameterName = "Complexity";
+    private const string WeightsParameterName = "Weights";
+
+
+    #region parameter properties
+    public IScopeTreeLookupParameter<DoubleValue> ComplexityParameter {
+      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters[ComplexityParameterName]; }
+    }
+    public IValueParameter<ItemDictionary<StringValue, DoubleValue>> WeightsParameter {
+      get { return (IValueParameter<ItemDictionary<StringValue, DoubleValue>>)Parameters[WeightsParameterName]; }
+    }
+    #endregion
+
+    [StorableConstructor]
+    private SymbolicDataAnalysisComplexityAnalyzer(bool deserializing) : base(deserializing) { }
+    private SymbolicDataAnalysisComplexityAnalyzer(SymbolicDataAnalysisComplexityAnalyzer original, Cloner cloner)
+      : base(original, cloner) {
+    }
+    public SymbolicDataAnalysisComplexityAnalyzer()
+      : base() {
+      var defaultWeights = new Dictionary<string, double>()
+                             {
+                                { "StartSymbol", 0.0},
+                                { "ProgramRootSymbol", 0.0},
+                                { "Addition", 1.0 },
+                                { "AiryA", 10.0 },
+                                { "AiryB", 10.0 },
+                                { "And", 2.0 },
+                                { "Average", 2.0 },
+                                { "Bessel", 10.0 },
+                                { "Constant", 1.0 },
+                                { "Cosine", 5.0 },
+                                { "CosineIntegral", 10.0 },
+                                { "Dawson", 10.0 },
+                                { "Derivative", 5.0 },
+                                { "Division", 2.0 },
+                                { "Erf", 10.0 },
+                                { "Exponential", 5.0 },
+                                { "ExponentialIntegralEi", 10.0 },
+                                { "FresnelCosineIntegral", 10.0 },
+                                { "FresnelSineIntegral", 10.0 },
+                                { "Gamma", 10.0 },
+                                { "GreaterThan", 2.0 },
+                                { "HyperbolicCosineIntegral", 10.0 },
+                                { "HyperbolicSineIntegral", 10.0 },
+                                { "IfThenElse", 3.0 },
+                                { "Integral", 5.0},
+                                { "LaggedVariable", 2.0 },
+                                { "LessThan", 2.0 },
+                                { "Logarithm", 5.0 },
+                                { "Multiplication", 2.0 },
+                                { "Norm", 10.0 },
+                                { "Not", 2.0 },
+                                { "Or", 1.0 },
+                                { "Power", 5.0 },
+                                { "Psi", 10.0 },
+                                { "Root", 5.0 },
+                                { "Sine", 5.0 },
+                                { "SineIntegral", 10.0 },
+                                { "Square", 2.0 },
+                                { "SquareRoot", 2.0 },
+                                { "Subtraction", 1.0 },
+                                { "Tangent", 3.0 },
+                                { "TimeLag", 3.0 },
+                                { "Variable", 1.0 },
+                                { "Variable Condition", 5.0 },
+                             };
+
+      var defaultWeightsTable = new ItemDictionary<StringValue, DoubleValue>();
+      foreach (var p in defaultWeights) {
+        defaultWeightsTable.Add(new StringValue(p.Key), new DoubleValue(p.Value));
+      }
+      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>(ComplexityParameterName, "The complexity of the tree."));
+      Parameters.Add(new ValueParameter<ItemDictionary<StringValue, DoubleValue>>(WeightsParameterName, "A table with complexity weights for each symbol.", defaultWeightsTable));
+    }
+
+    public override IDeepCloneable Clone(Cloner cloner) {
+      return new SymbolicDataAnalysisComplexityAnalyzer(this, cloner);
+    }
+
+    public override IOperation Apply() {
+      ItemArray<ISymbolicExpressionTree> expressions = SymbolicExpressionTreeParameter.ActualValue;
+      var weightsTable = WeightsParameter.Value;
+      var weights = new Dictionary<string, double>();
+      foreach (var p in weightsTable)
+        weights.Add(p.Key.Value, p.Value.Value);
+      var complexities = from t in expressions
+                         select CalculateComplexity(t, weights);
+      ComplexityParameter.ActualValue = new ItemArray<DoubleValue>(complexities.Select(x => new DoubleValue(x)).ToArray());
+      return base.Apply();
+    }
+
+    private double CalculateComplexity(ISymbolicExpressionTree t, Dictionary<string, double> weights) {
+      double c = 0.0;
+      foreach (var n in t.Root.IterateNodesPrefix()) {
+        if (!weights.ContainsKey(n.Symbol.Name)) throw new ArgumentException("Weight for symbol " + n.Symbol.Name + " is not defined.");
+        c += weights[n.Symbol.Name];
+      }
+      return c;
+    }
+  }
+}
Index: trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectiveTrainingParetoBestSolutionAnalyzer.cs
===================================================================
--- trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectiveTrainingParetoBestSolutionAnalyzer.cs	(revision 7726)
+++ trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectiveTrainingParetoBestSolutionAnalyzer.cs	(revision 7726)
@@ -0,0 +1,172 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System.Collections.Generic;
+using System.Linq;
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Data;
+using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
+using HeuristicLab.Operators;
+using HeuristicLab.Optimization;
+using HeuristicLab.Parameters;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+using System;
+
+namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
+  /// <summary>
+  /// An operator that collects the Pareto-best symbolic data analysis solutions for single objective symbolic data analysis problems.
+  /// </summary>
+  [Item("SymbolicDataAnalysisSingleObjectiveTrainingBestSolutionAnalyzer", "An operator that analyzes the training best symbolic data analysis solution for multi objective symbolic data analysis problems.")]
+  [StorableClass]
+  public abstract class SymbolicDataAnalysisSingleObjectiveTrainingParetoBestSolutionAnalyzer<T> : SymbolicDataAnalysisSingleObjectiveAnalyzer
+    where T : class, ISymbolicDataAnalysisSolution {
+    private const string TrainingBestSolutionsParameterName = "Best training solutions";
+    private const string TrainingBestSolutionQualitiesParameterName = "Best training solution qualities";
+    private const string ComplexityParameterName = "Complexity";
+
+    #region parameter properties
+    public ILookupParameter<ItemList<T>> TrainingBestSolutionsParameter {
+      get { return (ILookupParameter<ItemList<T>>)Parameters[TrainingBestSolutionsParameterName]; }
+    }
+    public ILookupParameter<ItemList<DoubleArray>> TrainingBestSolutionQualitiesParameter {
+      get { return (ILookupParameter<ItemList<DoubleArray>>)Parameters[TrainingBestSolutionQualitiesParameterName]; }
+    }
+    public IScopeTreeLookupParameter<DoubleValue> ComplexityParameter {
+      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters[ComplexityParameterName]; }
+    }
+    #endregion
+    #region properties
+    public ItemList<T> TrainingBestSolutions {
+      get { return TrainingBestSolutionsParameter.ActualValue; }
+      set { TrainingBestSolutionsParameter.ActualValue = value; }
+    }
+    public ItemList<DoubleArray> TrainingBestSolutionQualities {
+      get { return TrainingBestSolutionQualitiesParameter.ActualValue; }
+      set { TrainingBestSolutionQualitiesParameter.ActualValue = value; }
+    }
+    #endregion
+
+    [StorableConstructor]
+    protected SymbolicDataAnalysisSingleObjectiveTrainingParetoBestSolutionAnalyzer(bool deserializing) : base(deserializing) { }
+    protected SymbolicDataAnalysisSingleObjectiveTrainingParetoBestSolutionAnalyzer(SymbolicDataAnalysisSingleObjectiveTrainingParetoBestSolutionAnalyzer<T> original, Cloner cloner) : base(original, cloner) { }
+    public SymbolicDataAnalysisSingleObjectiveTrainingParetoBestSolutionAnalyzer()
+      : base() {
+      Parameters.Add(new LookupParameter<ItemList<T>>(TrainingBestSolutionsParameterName, "The training best (Pareto-optimal) symbolic data analysis solutions."));
+      Parameters.Add(new LookupParameter<ItemList<DoubleArray>>(TrainingBestSolutionQualitiesParameterName, "The qualities of the training best (Pareto-optimal) solutions."));
+      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>(ComplexityParameterName, "The complexity of each tree."));
+    }
+
+    public override IOperation Apply() {
+      var results = ResultCollection;
+      // create empty parameter and result values
+      if (TrainingBestSolutions == null) {
+        TrainingBestSolutions = new ItemList<T>();
+        TrainingBestSolutionQualities = new ItemList<DoubleArray>();
+        results.Add(new Result(TrainingBestSolutionQualitiesParameter.Name, TrainingBestSolutionQualitiesParameter.Description, TrainingBestSolutionQualities));
+        results.Add(new Result(TrainingBestSolutionsParameter.Name, TrainingBestSolutionsParameter.Description, TrainingBestSolutions));
+      }
+
+      IList<Tuple<double, double>> trainingBestQualities = TrainingBestSolutionQualities
+        .Select(x => Tuple.Create(x[0], x[1]))
+        .ToList();
+
+      #region find best trees
+      IList<int> nonDominatedIndexes = new List<int>();
+      ISymbolicExpressionTree[] tree = SymbolicExpressionTree.ToArray();
+      List<double> qualities = Quality.Select(x => x.Value).ToList();
+
+      List<double> complexities;
+      if (ComplexityParameter.ActualValue != null) {
+        complexities = ComplexityParameter.ActualValue.Select(x => x.Value).ToList();
+      } else {
+        complexities = tree.Select(t => (double)t.Length).ToList();
+      }
+      List<Tuple<double, double>> fitness = new List<Tuple<double, double>>();
+      for (int i = 0; i < qualities.Count; i++)
+        fitness.Add(Tuple.Create(qualities[i], complexities[i]));
+      var maximization = Tuple.Create(Maximization.Value, false);// complexity must be minimized
+      List<Tuple<double, double>> newNonDominatedQualities = new List<Tuple<double, double>>();
+      for (int i = 0; i < tree.Length; i++) {
+        if (IsNonDominated(fitness[i], trainingBestQualities, maximization) &&
+          IsNonDominated(fitness[i], newNonDominatedQualities, maximization) &&
+          IsNonDominated(fitness[i], fitness.Skip(i + 1), maximization)) {
+          if (!newNonDominatedQualities.Contains(fitness[i])) {
+            newNonDominatedQualities.Add(fitness[i]);
+            nonDominatedIndexes.Add(i);
+          }
+        }
+      }
+      #endregion
+
+      #region update Pareto-optimal solution archive
+      if (nonDominatedIndexes.Count > 0) {
+        ItemList<DoubleArray> nonDominatedQualities = new ItemList<DoubleArray>();
+        ItemList<T> nonDominatedSolutions = new ItemList<T>();
+        // add all new non-dominated solutions to the archive
+        foreach (var index in nonDominatedIndexes) {
+          T solution = CreateSolution(tree[index]);
+          nonDominatedSolutions.Add(solution);
+          nonDominatedQualities.Add(new DoubleArray(new double[] { fitness[index].Item1, fitness[index].Item2 }));
+        }
+        // add old non-dominated solutions only if they are not dominated by one of the new solutions
+        for (int i = 0; i < trainingBestQualities.Count; i++) {
+          if (IsNonDominated(trainingBestQualities[i], newNonDominatedQualities, maximization)) {
+            if (!newNonDominatedQualities.Contains(trainingBestQualities[i])) {
+              nonDominatedSolutions.Add(TrainingBestSolutions[i]);
+              nonDominatedQualities.Add(TrainingBestSolutionQualities[i]);
+            }
+          }
+        }
+
+        // make sure solutions and qualities are ordered in the results
+        var orderedIndexes =
+          nonDominatedSolutions.Select((s, i) => i).OrderBy(i => nonDominatedQualities[i][0]).ToArray();
+
+        var orderedNonDominatedSolutions = new ItemList<T>();
+        var orderedNonDominatedQualities = new ItemList<DoubleArray>();
+        foreach (var i in orderedIndexes) {
+          orderedNonDominatedQualities.Add(nonDominatedQualities[i]);
+          orderedNonDominatedSolutions.Add(nonDominatedSolutions[i]);
+        }
+
+        TrainingBestSolutions = orderedNonDominatedSolutions;
+        TrainingBestSolutionQualities = orderedNonDominatedQualities;
+
+        results[TrainingBestSolutionsParameter.Name].Value = orderedNonDominatedSolutions;
+        results[TrainingBestSolutionQualitiesParameter.Name].Value = orderedNonDominatedQualities;
+      }
+      #endregion
+      return base.Apply();
+    }
+
+    protected abstract T CreateSolution(ISymbolicExpressionTree bestTree);
+
+    private bool IsNonDominated(Tuple<double, double> point, IEnumerable<Tuple<double, double>> points, Tuple<bool, bool> maximization) {
+      return !points.Any(p => IsBetterOrEqual(p.Item1, point.Item1, maximization.Item1) &&
+                             IsBetterOrEqual(p.Item2, point.Item2, maximization.Item2));
+    }
+    private bool IsBetterOrEqual(double lhs, double rhs, bool maximization) {
+      if (maximization) return lhs >= rhs;
+      else return lhs <= rhs;
+    }
+  }
+}
