Free cookie consent management tool by TermsFeed Policy Generator

source: branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeEqualityComparer.cs @ 12328

Last change on this file since 12328 was 12028, checked in by bburlacu, 10 years ago

#2326: Branched HeuristicLab.Problems.DataAnalysis.Symbolic, initial commit.

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