Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/30/18 13:08:01 (5 years ago)
Author:
bburlacu
Message:

#2950: Refactor hashing to use unsigned long for hashes. Implement new DiversityPreservingCrossover which prevents subtrees with the same hash value from being swapped.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Hashing/SymbolicExpressionTreeHash.cs

    r16255 r16263  
    3939    private static readonly ISymbolicExpressionTreeNodeComparer comparer = new SymbolicExpressionTreeNodeComparer();
    4040
    41     public static int ComputeHash(this ISymbolicExpressionTree tree) {
     41    public static ulong ComputeHash(this ISymbolicExpressionTree tree) {
    4242      return ComputeHash(tree.Root.GetSubtree(0).GetSubtree(0));
    4343    }
    4444
    4545    // compute node hashes without sorting the arguments
    46     public static Dictionary<ISymbolicExpressionTreeNode, int> ComputeNodeHashes(this ISymbolicExpressionTree tree) {
     46    public static Dictionary<ISymbolicExpressionTreeNode, ulong> ComputeNodeHashes(this ISymbolicExpressionTree tree) {
    4747      var root = tree.Root.GetSubtree(0).GetSubtree(0);
    4848      var nodes = root.MakeNodes();
     
    5757    }
    5858
    59     public static int ComputeHash(this ISymbolicExpressionTreeNode treeNode) {
     59    public static ulong ComputeHash(this ISymbolicExpressionTreeNode treeNode) {
    6060      var hashNodes = treeNode.MakeNodes();
    6161      var simplified = hashNodes.Simplify();
    62       return ComputeHash(simplified);
    63     }
    64 
    65     public static int ComputeHash(this HashNode<ISymbolicExpressionTreeNode>[] nodes) {
    66       int hash = 1315423911;
    67       foreach (var node in nodes)
    68         hash ^= (hash << 5) + node.CalculatedHashValue + (hash >> 2);
    69       return hash;
    70     }
     62      //return ComputeHash(simplified);
     63      return simplified.Last().CalculatedHashValue;
     64    }
     65
     66    //public static int ComputeHash(this HashNode<ISymbolicExpressionTreeNode>[] nodes) {
     67    //  int hash = 1315423911;
     68    //  foreach (var node in nodes)
     69    //    hash ^= (hash << 5) + node.CalculatedHashValue + (hash >> 2);
     70    //  return hash;
     71    //}
    7172
    7273    public static HashNode<ISymbolicExpressionTreeNode> ToHashNode(this ISymbolicExpressionTreeNode node) {
     
    7778        name = variableTreeNode.VariableName;
    7879      }
    79       var hash = name.GetHashCode();
     80      var hash = (ulong)name.GetHashCode();
    8081      var hashNode = new HashNode<ISymbolicExpressionTreeNode>(comparer) {
    8182        Data = node,
Note: See TracChangeset for help on using the changeset viewer.