Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/15/10 19:58:42 (14 years ago)
Author:
gkronber
Message:

Fixed bugs in ADF operators and added test classes for ADF operators. #290 (Implement ADFs)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/ArgumentDeleter.cs

    r3338 r3360  
    6565        // argument deletion by consolidation is not possible => abort
    6666        return false;
     67      // the argument to be removed is always the one with the largest index
     68      // (otherwise we would have to decrement the index of the larger argument symbols)
    6769      var removedArgument = (from sym in selectedDefunBranch.Grammar.Symbols.OfType<Argument>()
    68                              select sym.ArgumentIndex).Distinct().SelectRandom(random);
     70                             select sym.ArgumentIndex).Distinct().OrderBy(x => x).Last();
    6971      // find invocations of the manipulated funcion and remove the specified argument tree
    70       var invocationNodes = from node in symbolicExpressionTree.IterateNodesPrefix().OfType<InvokeFunctionTreeNode>()
    71                             where node.Symbol.FunctionName == selectedDefunBranch.FunctionName
    72                             select node;
     72      var invocationNodes = (from node in symbolicExpressionTree.IterateNodesPrefix().OfType<InvokeFunctionTreeNode>()
     73                             where node.Symbol.FunctionName == selectedDefunBranch.FunctionName
     74                             select node).ToList();
    7375      foreach (var invokeNode in invocationNodes) {
    7476        invokeNode.RemoveSubTree(removedArgument);
     
    7880
    7981      // delete the dynamic argument symbol that matches the argument to be removed
    80       var matchingSymbol = selectedDefunBranch.Grammar.Symbols.OfType<Argument>().Where(s => s.ArgumentIndex == removedArgument).First();
     82      var matchingSymbol = selectedDefunBranch.Grammar.Symbols.OfType<Argument>().Where(s => s.ArgumentIndex == removedArgument).Single();
    8183      selectedDefunBranch.Grammar.RemoveSymbol(matchingSymbol);
     84      selectedDefunBranch.NumberOfArguments--;
    8285      // reduce arity in known functions of all root branches
    8386      foreach (var subtree in symbolicExpressionTree.Root.SubTrees) {
    84         var matchingInvokeSymbol = subtree.Grammar.Symbols.OfType<InvokeFunction>().Where(s => s.FunctionName == selectedDefunBranch.FunctionName).FirstOrDefault();
     87        var matchingInvokeSymbol = subtree.Grammar.Symbols.OfType<InvokeFunction>().Where(s => s.FunctionName == selectedDefunBranch.FunctionName).SingleOrDefault();
    8588        if (matchingInvokeSymbol != null) {
    86           subtree.Grammar.SetMinSubtreeCount(matchingInvokeSymbol, selectedDefunBranch.NumberOfArguments - 1);
    87           subtree.Grammar.SetMaxSubtreeCount(matchingInvokeSymbol, selectedDefunBranch.NumberOfArguments - 1);
     89          subtree.Grammar.SetMinSubtreeCount(matchingInvokeSymbol, selectedDefunBranch.NumberOfArguments);
     90          subtree.Grammar.SetMaxSubtreeCount(matchingInvokeSymbol, selectedDefunBranch.NumberOfArguments);
    8891        }
    8992      }
    90       selectedDefunBranch.NumberOfArguments--;
    9193      return true;
    9294    }
Note: See TracChangeset for help on using the changeset viewer.