Changeset 11888
- Timestamp:
- 02/04/15 15:17:22 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators/MaxCommonSubtreeSimilarityCalculator.cs
r11239 r11888 31 31 [Item("MaxCommonSubtreeSimilarityCalculator", "A similarity calculator based on the size of the maximum common subtree between two trees")] 32 32 public class MaxCommonSubtreeSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator { 33 public MaxCommonSubtreeSimilarityCalculator() { } 33 [Storable] 34 private readonly SymbolicExpressionTreeNodeSimilarityComparer comparer; 35 public bool MatchVariableNames { 36 get { return comparer.MatchVariableNames; } 37 set { comparer.MatchVariableNames = value; } 38 } 39 40 public bool MatchVariableWeights { 41 get { return comparer.MatchVariableWeights; } 42 set { comparer.MatchVariableWeights = value; } 43 } 44 45 public bool MatchConstantValues { 46 get { return comparer.MatchConstantValues; } 47 set { comparer.MatchConstantValues = value; } 48 } 49 50 [StorableConstructor] 51 protected MaxCommonSubtreeSimilarityCalculator(bool deserializing) : base(deserializing) { } 52 53 public override IDeepCloneable Clone(Cloner cloner) { 54 return new MaxCommonSubtreeSimilarityCalculator(this, cloner); 55 } 34 56 35 57 protected MaxCommonSubtreeSimilarityCalculator(MaxCommonSubtreeSimilarityCalculator original, Cloner cloner) … … 37 59 } 38 60 39 public override IDeepCloneable Clone(Cloner cloner) { 40 return new MaxCommonSubtreeSimilarityCalculator(this, cloner); 61 public MaxCommonSubtreeSimilarityCalculator() { 62 comparer = new SymbolicExpressionTreeNodeSimilarityComparer { 63 MatchConstantValues = true, 64 MatchVariableNames = true, 65 MatchVariableWeights = true 66 }; 67 } 68 69 public MaxCommonSubtreeSimilarityCalculator(bool matchVariableNames, bool matchVariableWeights, bool matchConstantValues) { 70 comparer = new SymbolicExpressionTreeNodeSimilarityComparer { 71 MatchConstantValues = matchConstantValues, 72 MatchVariableNames = matchVariableNames, 73 MatchVariableWeights = matchVariableWeights 74 }; 75 } 76 77 public double CalculateSimilarity(ISymbolicExpressionTree t1, ISymbolicExpressionTree t2) { 78 return MaxCommonSubtreeSimilarity(t1, t2, comparer); 41 79 } 42 80 … … 47 85 if (t1 == null || t2 == null) 48 86 throw new ArgumentException("Cannot calculate similarity when one of the arguments is null."); 49 var comparer = new SymbolicExpressionTreeNodeSimilarityComparer {50 MatchConstantValues = true,51 MatchVariableNames = true,52 MatchVariableWeights = true53 };54 87 55 88 return MaxCommonSubtreeSimilarity(t1, t2, comparer); … … 67 100 if (lenB <= max) continue; 68 101 int matches = SymbolicExpressionTreeMatching.Match(aa, bb, comparer); 69 if (ma tches == lenB && max < matches)102 if (max < matches) 70 103 max = matches; 71 104 }
Note: See TracChangeset
for help on using the changeset viewer.