Index: /branches/DataAnalysis.PopulationDiversityAnalysis/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/FineGrainedStructuralPopulationDiversityAnalyzer.cs
===================================================================
--- /branches/DataAnalysis.PopulationDiversityAnalysis/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/FineGrainedStructuralPopulationDiversityAnalyzer.cs	(revision 4940)
+++ /branches/DataAnalysis.PopulationDiversityAnalysis/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/FineGrainedStructuralPopulationDiversityAnalyzer.cs	(revision 4941)
@@ -68,9 +68,9 @@
 
     protected override double[,] CalculateSimilarities(SymbolicExpressionTree[] solutions) {
-      Constant c = null;
+      Constant constant = null;
       foreach (Symbol symbol in FunctionTreeGrammar.Symbols) {
         if (symbol is Constant) {
-          if (c != null) throw new InvalidProgramException("There are more and one constnat definitions in the given function tree grammar.");
-          c = (Constant)symbol;
+          if (constant != null) throw new InvalidProgramException("There are more and one constnat definitions in the given function tree grammar.");
+          constant = (Constant)symbol;
         }
       }
@@ -81,7 +81,8 @@
       }
       variableNames.Add(ProblemData.TargetVariable.Value);
-      IList<GeneticInformationItem>[] geneticInformationItemsList = new List<GeneticInformationItem>[n];
+      IList<GeneticInformationItem>[] geneticInformationItemsLists = new List<GeneticInformationItem>[n];
       for (int i = 0; i < n; i++) {
-        geneticInformationItemsList[i] = GeneticInformationItem.getGeneticInformationItems(solutions[i].Root, variableNames, 0, int.MaxValue);
+        // geneticInformationItemsList[i] = GeneticInformationItem.getGeneticInformationItems(solutions[i].Root, variableNames, MinimumLEvelDelta, MaximumLevelDelta);
+        geneticInformationItemsLists[i] = GeneticInformationItem.getGeneticInformationItems(solutions[i].Root, variableNames, 0, int.MaxValue);
       }
       double[,] result = new double[n, n];
@@ -90,6 +91,26 @@
           if (i == j)
             result[i, j] = 1;
-          else
-            result[i, j] = 0;
+          else {
+            IList<GeneticInformationItem> solution1GeneticItems = GeneticInformationItem.CopyList(geneticInformationItemsLists[i]);
+            IList<GeneticInformationItem> solution2GeneticItems = GeneticInformationItem.CopyList(geneticInformationItemsLists[j]);
+            double similarity = 0;
+            for (int k = 0; k < solution1GeneticItems.Count; k++) {
+              double bestPendantSimilarity;
+              // GeneticInformationItem bestPendant = GeneticInformationItem.FindBestPendant(solution1GeneticItems[k],
+              //   ConstantMinimum, ConstantMaximum, VariableWeightSigma, MaximumTreeHeight, MaximumTimeOffset,
+              //   LevelDifferenceCoefficient, AncestorIndexCoefficient, ConstantValueCoefficient, VariableWeightSigma, TimeOffsetCoefficient,
+              //   VariableWeightCoefficient, AdditiveSimilarityCalculation, out bestPendantSimilarity);
+              GeneticInformationItem bestPendant = GeneticInformationItem.FindBestPendant(solution1GeneticItems[k], solution2GeneticItems,
+                -10, 10, 1, 100, 10,
+                1, 1, 1, 1, 1, 1, true, out bestPendantSimilarity);
+              if (bestPendant != null) {
+                similarity += bestPendantSimilarity;
+                // if (PreventMultipleComparisonContribution)
+                if (true)
+                  solution2GeneticItems.Remove(bestPendant);
+              }
+            }
+            result[i, j] = similarity / solution1GeneticItems.Count;
+          }
         }
       }
@@ -151,13 +172,23 @@
       }
 
-      /*
-      public static GeneticInformationItem FindBestPendant(GeneticInformationItem Item, List<GeneticInformationItem> ComparisonItems,
-          StructuralSimilarityAnalysisParameters Parameters,
-          int MaxTreeHeight, int MaxTimeOffset,
+      public static IList<GeneticInformationItem> CopyList(IList<GeneticInformationItem> GeneticInformationItemsList) {
+        List<GeneticInformationItem> list = new List<GeneticInformationItem>(GeneticInformationItemsList.Count);
+        list.AddRange(GeneticInformationItemsList);
+        return list;
+      }
+
+      public static GeneticInformationItem FindBestPendant(GeneticInformationItem Item, IList<GeneticInformationItem> ComparisonItems,
+          double ConstantMinimum, double ConstantMaximum, double VariableWeightSigma,
+          int MaximumTreeHeight, int MaximumTimeOffset,
+          double LevelDifferenceCoefficient, double AncestorIndexCoefficient,
+          double ConstantValueCoefficient, double VariableWeightCoefficient, double TimeOffsetCoefficient, double VariableIndexCoefficient,
+          bool AdditiveSimilarityCalculation,
           out double BestPendantSimilarity) {
         int maxSimilarityIndex = -1;
         double similarity, maxSimilarity = -double.MaxValue;
         for (int i = 0; i < ComparisonItems.Count; i++) {
-          similarity = Similarity(Item, ComparisonItems[i], Parameters, MaxTreeHeight, MaxTimeOffset);
+          similarity = Similarity(Item, ComparisonItems[i], ConstantMinimum, ConstantMaximum, VariableWeightSigma, MaximumTreeHeight, MaximumTimeOffset,
+            LevelDifferenceCoefficient, AncestorIndexCoefficient, ConstantValueCoefficient, VariableWeightSigma, TimeOffsetCoefficient,
+            VariableWeightCoefficient, AdditiveSimilarityCalculation);
           if (!double.IsNaN(similarity) && similarity > maxSimilarity) {
             maxSimilarity = similarity;
@@ -170,18 +201,12 @@
         else
           return null;
-      }*/
+      }
 
       public static double Similarity(GeneticInformationItem Item1, GeneticInformationItem Item2,
-          GlobalSymbolicExpressionGrammar ExpressionGrammar, double ConstantMinimum, double ConstantMaximum, double VariableWeightSigma,
+          double ConstantMinimum, double ConstantMaximum, double VariableWeightSigma,
           int MaximumTreeHeight, int MaximumTimeOffset,
-          // StructuralSimilarityAnalysisParameters Parameters,
-          double LevelDifferenceCoefficient,
-          double AncestorIndexCoefficient,
-          double ConstantValueCoefficient,
-          double VariableWeightCoefficient,
-          double TimeOffsetCoefficient,
-          double VariableIndexCoefficient,
-          bool AdditiveSimilarityCalculation
-        ) {
+          double LevelDifferenceCoefficient, double AncestorIndexCoefficient,
+          double ConstantValueCoefficient, double VariableWeightCoefficient, double TimeOffsetCoefficient, double VariableIndexCoefficient,
+          bool AdditiveSimilarityCalculation) {
 
         if (Item1.AncestorDefinition != Item2.AncestorDefinition || Item1.DescendantDefinition != Item2.DescendantDefinition)
