Changeset 5733 for branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/SubroutineCreater.cs
- Timestamp:
- 03/17/11 14:07:47 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/SubroutineCreater.cs
r5686 r5733 95 95 96 96 // select a random body (either the result producing branch or an ADF branch) 97 var bodies = from node in symbolicExpressionTree.Root.Sub Trees97 var bodies = from node in symbolicExpressionTree.Root.Subtrees 98 98 select new { Tree = node, Length = node.GetLength() }; 99 99 var totalNumberOfBodyNodes = bodies.Select(x => x.Length).Sum(); … … 111 111 // select a random cut point in the selected branch 112 112 var allCutPoints = (from parent in selectedBody.IterateNodesPrefix() 113 from subtree in parent.Sub Trees113 from subtree in parent.Subtrees 114 114 select new CutPoint(parent, subtree)).ToList(); 115 115 if (allCutPoints.Count() == 0) … … 122 122 ISymbolicExpressionTreeNode functionBody = selectedCutPoint.Child; 123 123 // disconnect the function body from the tree 124 selectedCutPoint.Parent.RemoveSub Tree(selectedCutPoint.ChildIndex);124 selectedCutPoint.Parent.RemoveSubtree(selectedCutPoint.ChildIndex); 125 125 // disconnect the argument branches from the function 126 126 functionBody = DisconnectBranches(functionBody, argumentCutPoints); 127 127 // insert a function invocation symbol instead 128 128 var invokeNode = (InvokeFunctionTreeNode)(new InvokeFunction(newFunctionName)).CreateTreeNode(); 129 selectedCutPoint.Parent.InsertSub Tree(selectedCutPoint.ChildIndex, invokeNode);129 selectedCutPoint.Parent.InsertSubtree(selectedCutPoint.ChildIndex, invokeNode); 130 130 // add the branches selected as argument as subtrees of the function invocation node 131 131 foreach (var argumentCutPoint in argumentCutPoints) 132 invokeNode.AddSub Tree(argumentCutPoint.Child);132 invokeNode.AddSubtree(argumentCutPoint.Child); 133 133 134 134 // insert a new function defining branch 135 135 var defunNode = (DefunTreeNode)(new Defun()).CreateTreeNode(); 136 136 defunNode.FunctionName = newFunctionName; 137 defunNode.AddSub Tree(functionBody);138 symbolicExpressionTree.Root.AddSub Tree(defunNode);137 defunNode.AddSubtree(functionBody); 138 symbolicExpressionTree.Root.AddSubtree(defunNode); 139 139 // the grammar in the newly defined function is a clone of the grammar of the originating branch 140 140 defunNode.SetGrammar((ISymbolicExpressionTreeGrammar)selectedBody.Grammar.Clone()); … … 157 157 if (selectedBody.Symbol is Defun) { 158 158 var originalFunctionDefinition = selectedBody as DefunTreeNode; 159 foreach (var subtree in symbolicExpressionTree.Root.Sub Trees) {159 foreach (var subtree in symbolicExpressionTree.Root.Subtrees) { 160 160 var originalBranchInvokeSymbol = (from symb in subtree.Grammar.Symbols.OfType<InvokeFunction>() 161 161 where symb.FunctionName == originalFunctionDefinition.FunctionName … … 177 177 } 178 178 // remove the subtrees so that we can clone only the root node 179 List<ISymbolicExpressionTreeNode> subtrees = new List<ISymbolicExpressionTreeNode>(node.Sub Trees);180 while (node.Sub Trees.Count() > 0) node.RemoveSubTree(0);179 List<ISymbolicExpressionTreeNode> subtrees = new List<ISymbolicExpressionTreeNode>(node.Subtrees); 180 while (node.Subtrees.Count() > 0) node.RemoveSubtree(0); 181 181 // recursively apply function for subtrees or append a argument terminal node 182 182 foreach (var subtree in subtrees) { 183 node.AddSub Tree(DisconnectBranches(subtree, argumentCutPoints));183 node.AddSubtree(DisconnectBranches(subtree, argumentCutPoints)); 184 184 } 185 185 return node; … … 198 198 } else { 199 199 // get the number of argument nodes (which must be cut-off) in the sub-trees 200 var numberOfArgumentsInSubtrees = (from subtree in selectedRoot.Sub Trees200 var numberOfArgumentsInSubtrees = (from subtree in selectedRoot.Subtrees 201 201 let nArgumentsInTree = subtree.IterateNodesPrefix().OfType<ArgumentTreeNode>().Count() 202 202 select nArgumentsInTree).ToList(); … … 209 209 } 210 210 // cut-off in the sub-trees in random order 211 var randomIndexes = (from index in Enumerable.Range(0, selectedRoot.Sub Trees.Count())211 var randomIndexes = (from index in Enumerable.Range(0, selectedRoot.Subtrees.Count()) 212 212 select new { Index = index, OrderValue = random.NextDouble() }) 213 213 .OrderBy(x => x.OrderValue) 214 214 .Select(x => x.Index); 215 215 foreach (var subtreeIndex in randomIndexes) { 216 var subtree = selectedRoot.GetSub Tree(subtreeIndex);216 var subtree = selectedRoot.GetSubtree(subtreeIndex); 217 217 minNewArgumentsForSubtrees[subtreeIndex] = 0; 218 218 // => cut-off at 0..n points somewhere in the current sub-tree
Note: See TracChangeset
for help on using the changeset viewer.