Changeset 17005 for branches/2994-AutoDiffForIntervals/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Hashing
- Timestamp:
- 06/11/19 20:59:44 (6 years ago)
- Location:
- branches/2994-AutoDiffForIntervals
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2994-AutoDiffForIntervals
- Property svn:mergeinfo changed
/trunk merged: 16944-16945,16978-16983,16992,16997
- Property svn:mergeinfo changed
-
branches/2994-AutoDiffForIntervals/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis.Symbolic merged: 16978-16981,16983
- Property svn:mergeinfo changed
-
branches/2994-AutoDiffForIntervals/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Hashing/HashExtensions.cs
r16565 r17005 21 21 22 22 using System; 23 using System. Collections.Generic;23 using System.Linq; 24 24 25 25 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { … … 38 38 public SimplifyAction Simplify; 39 39 40 public IComparer<T> Comparer;40 //public IComparer<T> Comparer; 41 41 42 42 public bool IsLeaf => Arity == 0; 43 43 44 public HashNode(IComparer<T> comparer) {45 Comparer = comparer;46 }47 48 privateHashNode() { }44 //public HashNode(IComparer<T> comparer) { 45 // Comparer = comparer; 46 //} 47 48 //public HashNode() { } 49 49 50 50 public int CompareTo(HashNode<T> other) { 51 var res = Comparer.Compare(Data, other.Data); 52 return res == 0 ? CalculatedHashValue.CompareTo(other.CalculatedHashValue) : res; 51 return CalculatedHashValue.CompareTo(other.CalculatedHashValue); 53 52 } 54 53 … … 103 102 104 103 public static HashNode<T>[] Simplify<T>(this HashNode<T>[] nodes, Func<byte[], ulong> hashFunction) where T : class { 105 var reduced = nodes.UpdateNodeSizes().Reduce().Sort(hashFunction); 106 107 for (int i = 0; i < reduced.Length; ++i) { 108 var node = reduced[i]; 109 if (node.IsLeaf) { 110 continue; 111 } 112 node.Simplify?.Invoke(ref reduced, i); 113 } 114 // detect if anything was simplified 115 var count = 0; 116 foreach (var node in reduced) { 117 if (!node.Enabled) { ++count; } 118 } 119 if (count == 0) { 120 return reduced; 121 } 122 123 var simplified = new HashNode<T>[reduced.Length - count]; 124 int j = 0; 125 foreach (var node in reduced) { 126 if (node.Enabled) { 127 simplified[j++] = node; 128 } 129 } 130 return simplified.UpdateNodeSizes().Reduce().Sort(hashFunction); 104 bool simplified = false; 105 nodes = nodes.UpdateNodeSizes().Reduce().Sort(hashFunction); 106 do { 107 if (simplified) { 108 simplified = false; 109 nodes = nodes.Where(x => x.Enabled).ToArray().UpdateNodeSizes().Reduce().Sort(hashFunction); 110 } 111 112 for (int i = 0; i < nodes.Length; ++i) { 113 var node = nodes[i]; 114 if (node.IsLeaf) { 115 continue; 116 } 117 node.Simplify?.Invoke(ref nodes, i); 118 for (int j = i - node.Size; j < i; ++j) { 119 // detect if anything was simplified 120 if (!nodes[j].Enabled) { 121 simplified = true; 122 break; 123 } 124 } 125 } 126 } while (simplified); 127 return nodes.UpdateNodeSizes().Sort(hashFunction); 131 128 } 132 129 … … 207 204 } 208 205 209 p rivatestatic HashNode<T>[] Reduce<T>(this HashNode<T>[] nodes) where T : class {206 public static HashNode<T>[] Reduce<T>(this HashNode<T>[] nodes) where T : class { 210 207 int count = 0; 211 208 for (int i = 0; i < nodes.Length; ++i) { -
branches/2994-AutoDiffForIntervals/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Hashing/SymbolicExpressionTreeHash.cs
r16478 r17005 38 38 private static readonly Constant constant = new Constant(); 39 39 40 private static readonly ISymbolicExpressionTreeNodeComparer comparer = new SymbolicExpressionTreeNodeComparer();41 40 private static ISymbolicExpressionTreeNode ActualRoot(this ISymbolicExpressionTree tree) => tree.Root.GetSubtree(0).GetSubtree(0); 42 41 … … 74 73 } 75 74 var hash = (ulong)name.GetHashCode(); 76 var hashNode = new HashNode<ISymbolicExpressionTreeNode> (comparer){75 var hashNode = new HashNode<ISymbolicExpressionTreeNode> { 77 76 Data = node, 78 77 Arity = node.SubtreeCount,
Note: See TracChangeset
for help on using the changeset viewer.