Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/26/10 16:18:45 (14 years ago)
Author:
gkronber
Message:

Fixed bugs in SubtreeCrossover, ArgumentCreater and ArgumentDuplicater and updated unit tests for symbolic expression tree operators. #1103

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureManipulators/ArgumentCreater.cs

    r4068 r4106  
    8383      selectedCutPoint.Parent.RemoveSubTree(selectedCutPoint.ReplacedChildIndex);
    8484      selectedCutPoint.Parent.InsertSubTree(selectedCutPoint.ReplacedChildIndex, newArgNode);
     85
    8586      // find all invocations of the selected ADF and attach a cloned version of the replaced branch (with all argument-nodes expanded)
    8687      var invocationNodes = from node in symbolicExpressionTree.IterateNodesPrefix().OfType<InvokeFunctionTreeNode>()
    8788                            where node.Symbol.FunctionName == selectedDefunBranch.FunctionName
     89                            where node.SubTrees.Count == selectedDefunBranch.NumberOfArguments
    8890                            select node;
    89       foreach (var invocationNode in invocationNodes) {
    90         // append a new argument branch after expanding all argument nodes
    91         var clonedBranch = (SymbolicExpressionTreeNode)replacedBranch.Clone();
    92         clonedBranch = ReplaceArgumentsInBranch(clonedBranch, invocationNode.SubTrees);
    93         invocationNode.InsertSubTree(newArgumentIndex, clonedBranch);
     91      // do this repeatedly until no matching invocations are found     
     92      while (invocationNodes.Count() > 0) {
     93        List<SymbolicExpressionTreeNode> newlyAddedBranches = new List<SymbolicExpressionTreeNode>();
     94        foreach (var invocationNode in invocationNodes) {
     95          // append a new argument branch after expanding all argument nodes
     96          var clonedBranch = (SymbolicExpressionTreeNode)replacedBranch.Clone();
     97          clonedBranch = ReplaceArgumentsInBranch(clonedBranch, invocationNode.SubTrees);
     98          invocationNode.InsertSubTree(newArgumentIndex, clonedBranch);
     99          newlyAddedBranches.Add(clonedBranch);
     100        }
     101        invocationNodes = from newlyAddedBranch in newlyAddedBranches
     102                          from node in newlyAddedBranch.IterateNodesPrefix().OfType<InvokeFunctionTreeNode>()
     103                          where node.Symbol.FunctionName == selectedDefunBranch.FunctionName
     104                          where node.SubTrees.Count == selectedDefunBranch.NumberOfArguments
     105                          select node;
    94106      }
    95107      // increase expected number of arguments of function defining branch
Note: See TracChangeset for help on using the changeset viewer.