Changeset 16306


Ignore:
Timestamp:
11/19/18 15:37:48 (2 years ago)
Author:
lkammere
Message:

#2915: Merge changes from trunk.

Location:
branches/2915-AbsoluteSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/2915-AbsoluteSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic

  • branches/2915-AbsoluteSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Hashing/HashExtensions.cs

    r16304 r16306  
    3535      public ulong CalculatedHashValue; // the calculated hash value (taking into account the children hash values)
    3636
    37       public Action<HashNode<T>[], int> Simplify;
     37      public delegate void SimplifyAction(ref HashNode<T>[] nodes, int i);
     38      public SimplifyAction Simplify;
     39
    3840      public IComparer<T> Comparer;
    3941
     
    108110          continue;
    109111        }
    110         node.Simplify?.Invoke(reduced, i);
     112        node.Simplify?.Invoke(ref reduced, i);
    111113      }
    112114      // detect if anything was simplified
  • branches/2915-AbsoluteSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Hashing/SymbolicExpressionTreeHash.cs

    r16304 r16306  
    227227    }
    228228
    229     public static void SimplifyAddition(HashNode<ISymbolicExpressionTreeNode>[] nodes, int i) {
     229    public static void SimplifyAddition(ref HashNode<ISymbolicExpressionTreeNode>[] nodes, int i) {
    230230      // simplify additions of terms by eliminating terms with the same symbol and hash
    231231      var children = nodes.IterateChildren(i);
    232232
     233      // we always assume the child nodes are sorted
    233234      var curr = children[0];
    234235      var node = nodes[i];
     
    236237      foreach (var j in children.Skip(1)) {
    237238        if (nodes[j] == nodes[curr]) {
    238           for (int k = j - nodes[j].Size; k <= j; ++k) {
    239             nodes[k].Enabled = false;
    240           }
     239          nodes.SetEnabled(j, false);
    241240          node.Arity--;
    242241        } else {
     
    250249
    251250    // simplify multiplications by reducing constants and div terms 
    252     public static void SimplifyMultiplication(HashNode<ISymbolicExpressionTreeNode>[] nodes, int i) {
     251    public static void SimplifyMultiplication(ref HashNode<ISymbolicExpressionTreeNode>[] nodes, int i) {
    253252      var node = nodes[i];
    254253      var children = nodes.IterateChildren(i);
     
    298297    }
    299298
    300     public static void SimplifyDivision(HashNode<ISymbolicExpressionTreeNode>[] nodes, int i) {
     299    public static void SimplifyDivision(ref HashNode<ISymbolicExpressionTreeNode>[] nodes, int i) {
    301300      var node = nodes[i];
    302301      var children = nodes.IterateChildren(i);
    303302
    304       if (children.All(x => nodes[x].Data.Symbol is Constant)) {
     303      var tmp = nodes;
     304
     305      if (children.All(x => tmp[x].Data.Symbol is Constant)) {
    305306        var v = ((ConstantTreeNode)nodes[children.First()].Data).Value;
    306307        if (node.Arity == 1) {
     
    333334    }
    334335
    335     public static void SimplifyUnaryNode(HashNode<ISymbolicExpressionTreeNode>[] nodes, int i) {
     336    public static void SimplifyUnaryNode(ref HashNode<ISymbolicExpressionTreeNode>[] nodes, int i) {
    336337      // check if the child of the unary node is a constant, then the whole node can be simplified
    337338      var parent = nodes[i];
     
    348349    }
    349350
    350     public static void SimplifyBinaryNode(HashNode<ISymbolicExpressionTreeNode>[] nodes, int i) {
     351    public static void SimplifyBinaryNode(ref HashNode<ISymbolicExpressionTreeNode>[] nodes, int i) {
    351352      var children = nodes.IterateChildren(i);
    352       if (children.All(x => nodes[x].Data.Symbol is Constant)) {
     353      var tmp = nodes;
     354      if (children.All(x => tmp[x].Data.Symbol is Constant)) {
    353355        foreach (var j in children) {
    354356          nodes[j].Enabled = false;
Note: See TracChangeset for help on using the changeset viewer.