Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataAnalysis.IslandAlgorithms/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Matching/SymbolicExpressionTreeEqualityComparer.cs @ 16377

Last change on this file since 16377 was 10562, checked in by bburlacu, 11 years ago

#2164: Committed initial version of the tree matching functionality.

File size: 845 bytes
Line 
1using System;
2using System.Collections.Generic;
3using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
4
5namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
6  public class SymbolicExpressionTreeEqualityComparer : IEqualityComparer<ISymbolicExpressionTree> {
7    public SymbolicExpressionTreeNodeSimilarityComparer SimilarityComparer { get; set; }
8
9    public bool Equals(ISymbolicExpressionTree a, ISymbolicExpressionTree b) {
10      if (SimilarityComparer == null) throw new Exception("SimilarityComparer needs to be initialized first.");
11      return a.Length == b.Length &&
12             SymbolicExpressionTreeMatching.Match(a.Root, b.Root, SimilarityComparer) == Math.Min(a.Length, b.Length);
13    }
14
15    public int GetHashCode(ISymbolicExpressionTree tree) {
16      return (tree.Length << 8) % 12345;
17    }
18  }
19}
Note: See TracBrowser for help on using the repository browser.