コード例 #1
0
        public static double MaxCommonSubtreeSimilarity(ISymbolicExpressionTree a, ISymbolicExpressionTree b, ISymbolicExpressionTreeNodeSimilarityComparer comparer)
        {
            int max   = 0;
            var rootA = a.Root.GetSubtree(0).GetSubtree(0);
            var rootB = b.Root.GetSubtree(0).GetSubtree(0);

            foreach (var aa in rootA.IterateNodesBreadth())
            {
                int lenA = aa.GetLength();
                if (lenA <= max)
                {
                    continue;
                }
                foreach (var bb in rootB.IterateNodesBreadth())
                {
                    int lenB = bb.GetLength();
                    if (lenB <= max)
                    {
                        continue;
                    }
                    int matches = SymbolicExpressionTreeMatching.Match(aa, bb, comparer);
                    if (max < matches)
                    {
                        max = matches;
                    }
                }
            }
            return(2.0 * max / (rootA.GetLength() + rootB.GetLength()));
        }
 public bool Equals(ISymbolicExpressionTree a, ISymbolicExpressionTree b)
 {
     if (SimilarityComparer == null)
     {
         throw new Exception("SimilarityComparer needs to be initialized first.");
     }
     return(a.Length == b.Length && SymbolicExpressionTreeMatching.Match(a.Root, b.Root, SimilarityComparer) == Math.Min(a.Length, b.Length));
 }