Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeEqualityComparer.cs @ 17847

Last change on this file since 17847 was 17097, checked in by mkommend, 5 years ago

#2520: Merged 16565 - 16579 into stable.

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