Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2520_PersistenceReintegration/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeEqualityComparer.cs @ 16476

Last change on this file since 16476 was 16476, checked in by gkronber, 5 years ago

#2520: checked and added StorableType attribute in projects up to HeuristicLab.Problems.GraphColoring

File size: 923 bytes
Line 
1using System;
2using System.Collections.Generic;
3using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
4using HEAL.Fossil;
5
6namespace 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    public bool Equals(ISymbolicExpressionTree a, ISymbolicExpressionTree b) {
13      if (SimilarityComparer == null) throw new Exception("SimilarityComparer needs to be initialized first.");
14      return a.Length == b.Length && SymbolicExpressionTreeMatching.Match(a.Root, b.Root, SimilarityComparer) == Math.Min(a.Length, b.Length);
15    }
16
17    public int GetHashCode(ISymbolicExpressionTree tree) {
18      return (tree.Length << 8) % 12345;
19    }
20  }
21}
Note: See TracBrowser for help on using the repository browser.