Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/17/11 14:07:47 (14 years ago)
Author:
mkommend
Message:

#1418: Corrected problem interfaces & unified naming of subtrees.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/SubroutineCreater.cs

    r5686 r5733  
    9595
    9696      // select a random body (either the result producing branch or an ADF branch)
    97       var bodies = from node in symbolicExpressionTree.Root.SubTrees
     97      var bodies = from node in symbolicExpressionTree.Root.Subtrees
    9898                   select new { Tree = node, Length = node.GetLength() };
    9999      var totalNumberOfBodyNodes = bodies.Select(x => x.Length).Sum();
     
    111111      // select a random cut point in the selected branch
    112112      var allCutPoints = (from parent in selectedBody.IterateNodesPrefix()
    113                           from subtree in parent.SubTrees
     113                          from subtree in parent.Subtrees
    114114                          select new CutPoint(parent, subtree)).ToList();
    115115      if (allCutPoints.Count() == 0)
     
    122122      ISymbolicExpressionTreeNode functionBody = selectedCutPoint.Child;
    123123      // disconnect the function body from the tree
    124       selectedCutPoint.Parent.RemoveSubTree(selectedCutPoint.ChildIndex);
     124      selectedCutPoint.Parent.RemoveSubtree(selectedCutPoint.ChildIndex);
    125125      // disconnect the argument branches from the function
    126126      functionBody = DisconnectBranches(functionBody, argumentCutPoints);
    127127      // insert a function invocation symbol instead
    128128      var invokeNode = (InvokeFunctionTreeNode)(new InvokeFunction(newFunctionName)).CreateTreeNode();
    129       selectedCutPoint.Parent.InsertSubTree(selectedCutPoint.ChildIndex, invokeNode);
     129      selectedCutPoint.Parent.InsertSubtree(selectedCutPoint.ChildIndex, invokeNode);
    130130      // add the branches selected as argument as subtrees of the function invocation node
    131131      foreach (var argumentCutPoint in argumentCutPoints)
    132         invokeNode.AddSubTree(argumentCutPoint.Child);
     132        invokeNode.AddSubtree(argumentCutPoint.Child);
    133133
    134134      // insert a new function defining branch
    135135      var defunNode = (DefunTreeNode)(new Defun()).CreateTreeNode();
    136136      defunNode.FunctionName = newFunctionName;
    137       defunNode.AddSubTree(functionBody);
    138       symbolicExpressionTree.Root.AddSubTree(defunNode);
     137      defunNode.AddSubtree(functionBody);
     138      symbolicExpressionTree.Root.AddSubtree(defunNode);
    139139      // the grammar in the newly defined function is a clone of the grammar of the originating branch
    140140      defunNode.SetGrammar((ISymbolicExpressionTreeGrammar)selectedBody.Grammar.Clone());
     
    157157      if (selectedBody.Symbol is Defun) {
    158158        var originalFunctionDefinition = selectedBody as DefunTreeNode;
    159         foreach (var subtree in symbolicExpressionTree.Root.SubTrees) {
     159        foreach (var subtree in symbolicExpressionTree.Root.Subtrees) {
    160160          var originalBranchInvokeSymbol = (from symb in subtree.Grammar.Symbols.OfType<InvokeFunction>()
    161161                                            where symb.FunctionName == originalFunctionDefinition.FunctionName
     
    177177      }
    178178      // remove the subtrees so that we can clone only the root node
    179       List<ISymbolicExpressionTreeNode> subtrees = new List<ISymbolicExpressionTreeNode>(node.SubTrees);
    180       while (node.SubTrees.Count() > 0) node.RemoveSubTree(0);
     179      List<ISymbolicExpressionTreeNode> subtrees = new List<ISymbolicExpressionTreeNode>(node.Subtrees);
     180      while (node.Subtrees.Count() > 0) node.RemoveSubtree(0);
    181181      // recursively apply function for subtrees or append a argument terminal node
    182182      foreach (var subtree in subtrees) {
    183         node.AddSubTree(DisconnectBranches(subtree, argumentCutPoints));
     183        node.AddSubtree(DisconnectBranches(subtree, argumentCutPoints));
    184184      }
    185185      return node;
     
    198198      } else {
    199199        // get the number of argument nodes (which must be cut-off) in the sub-trees
    200         var numberOfArgumentsInSubtrees = (from subtree in selectedRoot.SubTrees
     200        var numberOfArgumentsInSubtrees = (from subtree in selectedRoot.Subtrees
    201201                                           let nArgumentsInTree = subtree.IterateNodesPrefix().OfType<ArgumentTreeNode>().Count()
    202202                                           select nArgumentsInTree).ToList();
     
    209209        }
    210210        // cut-off in the sub-trees in random order
    211         var randomIndexes = (from index in Enumerable.Range(0, selectedRoot.SubTrees.Count())
     211        var randomIndexes = (from index in Enumerable.Range(0, selectedRoot.Subtrees.Count())
    212212                             select new { Index = index, OrderValue = random.NextDouble() })
    213213                             .OrderBy(x => x.OrderValue)
    214214                             .Select(x => x.Index);
    215215        foreach (var subtreeIndex in randomIndexes) {
    216           var subtree = selectedRoot.GetSubTree(subtreeIndex);
     216          var subtree = selectedRoot.GetSubtree(subtreeIndex);
    217217          minNewArgumentsForSubtrees[subtreeIndex] = 0;
    218218          // => cut-off at 0..n points somewhere in the current sub-tree
Note: See TracChangeset for help on using the changeset viewer.