Changeset 5510 for branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/SubroutineDeleter.cs
- Timestamp:
- 02/17/11 13:51:04 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/SubroutineDeleter.cs
r5499 r5510 33 33 /// As described in Koza, Bennett, Andre, Keane, Genetic Programming III - Darwinian Invention and Problem Solving, 1999, pp. 108 34 34 /// </summary> 35 [Item("SubroutineDeleter", "Manipulates a symbolic expression by deleting a preexisting function-defining branch. ")]35 [Item("SubroutineDeleter", "Manipulates a symbolic expression by deleting a preexisting function-defining branch. As described in Koza, Bennett, Andre, Keane, Genetic Programming III - Darwinian Invention and Problem Solving, 1999, pp. 108")] 36 36 [StorableClass] 37 37 public sealed class SubroutineDeleter : SymbolicExpressionTreeArchitectureManipulator { … … 47 47 public override sealed void ModifyArchitecture( 48 48 IRandom random, 49 SymbolicExpressionTree symbolicExpressionTree, 50 ISymbolicExpressionGrammar grammar, 51 IntValue maxTreeSize, IntValue maxTreeHeight, 52 IntValue maxFunctionDefiningBranches, IntValue maxFunctionArguments, 53 out bool success) { 54 success = DeleteSubroutine(random, symbolicExpressionTree, grammar, maxTreeSize.Value, maxTreeHeight.Value, maxFunctionDefiningBranches.Value, maxFunctionArguments.Value); 49 ISymbolicExpressionTree symbolicExpressionTree, 50 IntValue maxFunctionDefinitions, IntValue maxFunctionArguments) { 51 DeleteSubroutine(random, symbolicExpressionTree, maxFunctionDefinitions.Value, maxFunctionArguments.Value); 55 52 } 56 53 57 54 public static bool DeleteSubroutine( 58 55 IRandom random, 59 SymbolicExpressionTree symbolicExpressionTree, 60 ISymbolicExpressionGrammar grammar, 61 int maxTreeSize, int maxTreeHeight, 62 int maxFunctionDefiningBranches, int maxFunctionArguments) { 56 ISymbolicExpressionTree symbolicExpressionTree, 57 int maxFunctionDefinitions, int maxFunctionArguments) { 63 58 var functionDefiningBranches = symbolicExpressionTree.IterateNodesPrefix().OfType<DefunTreeNode>(); 64 59 … … 68 63 var selectedDefunBranch = functionDefiningBranches.SelectRandom(random); 69 64 // remove the selected defun 70 int defunSubtreeIndex = symbolicExpressionTree.Root. SubTrees.IndexOf(selectedDefunBranch);65 int defunSubtreeIndex = symbolicExpressionTree.Root.IndexOfSubTree(selectedDefunBranch); 71 66 symbolicExpressionTree.Root.RemoveSubTree(defunSubtreeIndex); 72 67 … … 85 80 } 86 81 87 private static void DeletionByRandomRegeneration(IRandom random, SymbolicExpressionTree symbolicExpressionTree, DefunTreeNode selectedDefunBranch) {82 private static void DeletionByRandomRegeneration(IRandom random, ISymbolicExpressionTree symbolicExpressionTree, DefunTreeNode selectedDefunBranch) { 88 83 // find first invocation and replace it with a randomly generated tree 89 84 // can't find all invocations in one step because once we replaced a top level invocation … … 92 87 from subtree in node.SubTrees.OfType<InvokeFunctionTreeNode>() 93 88 where subtree.Symbol.FunctionName == selectedDefunBranch.FunctionName 94 select new { Parent = node, ReplacedChildIndex = node. SubTrees.IndexOf(subtree), ReplacedChild = subtree }).FirstOrDefault();89 select new { Parent = node, ReplacedChildIndex = node.IndexOfSubTree(subtree), ReplacedChild = subtree }).FirstOrDefault(); 95 90 while (invocationCutPoint != null) { 96 91 // deletion by random regeneration 97 SymbolicExpressionTreeNode replacementTree = null;92 ISymbolicExpressionTreeNode replacementTree = null; 98 93 var allowedSymbolsList = invocationCutPoint.Parent.GetAllowedSymbols(invocationCutPoint.ReplacedChildIndex).ToList(); 99 94 var weights = allowedSymbolsList.Select(s => s.InitialFrequency); … … 115 110 from subtree in node.SubTrees.OfType<InvokeFunctionTreeNode>() 116 111 where subtree.Symbol.FunctionName == selectedDefunBranch.FunctionName 117 select new { Parent = node, ReplacedChildIndex = node. SubTrees.IndexOf(subtree), ReplacedChild = subtree }).FirstOrDefault();112 select new { Parent = node, ReplacedChildIndex = node.IndexOfSubTree(subtree), ReplacedChild = subtree }).FirstOrDefault(); 118 113 } 119 114 }
Note: See TracChangeset
for help on using the changeset viewer.