Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
4 | using HEAL.Attic;
|
---|
5 |
|
---|
6 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
|
---|
7 | [StorableType("535830d4-551e-4b53-97e3-9605bd7e785f")]
|
---|
8 | public class SymbolicExpressionTreeEqualityComparer : IEqualityComparer<ISymbolicExpressionTree> {
|
---|
9 | [Storable]
|
---|
10 | public SymbolicExpressionTreeNodeEqualityComparer SimilarityComparer { get; set; }
|
---|
11 |
|
---|
12 |
|
---|
13 | [StorableConstructor]
|
---|
14 | protected SymbolicExpressionTreeEqualityComparer(StorableConstructorFlag _) { }
|
---|
15 | public SymbolicExpressionTreeEqualityComparer() { }
|
---|
16 |
|
---|
17 | public bool Equals(ISymbolicExpressionTree a, ISymbolicExpressionTree b) {
|
---|
18 | if (SimilarityComparer == null) throw new Exception("SimilarityComparer needs to be initialized first.");
|
---|
19 | return a.Length == b.Length && SymbolicExpressionTreeMatching.Match(a.Root, b.Root, SimilarityComparer) == Math.Min(a.Length, b.Length);
|
---|
20 | }
|
---|
21 |
|
---|
22 | public int GetHashCode(ISymbolicExpressionTree tree) {
|
---|
23 | return (tree.Length << 8) % 12345;
|
---|
24 | }
|
---|
25 |
|
---|
26 | }
|
---|
27 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.