Changeset 3369 for trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators
- Timestamp:
- 04/16/10 12:12:29 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/SubroutineDeleter.cs
r3360 r3369 68 68 69 69 // remove references to deleted function 70 foreach (var subtree in symbolicExpressionTree.Root.SubTrees ) {70 foreach (var subtree in symbolicExpressionTree.Root.SubTrees.OfType<SymbolicExpressionTreeTopLevelNode>()) { 71 71 var matchingInvokeSymbol = (from symb in subtree.Grammar.Symbols.OfType<InvokeFunction>() 72 72 where symb.FunctionName == selectedDefunBranch.FunctionName … … 99 99 int minPossibleHeight = invocationCutPoint.Parent.Grammar.GetMinExpressionDepth(selectedSymbol); 100 100 int maxHeight = Math.Max(minPossibleHeight, invocationCutPoint.ReplacedChild.GetHeight()); 101 102 replacementTree = ProbabilisticTreeCreator.PTC2(random, invocationCutPoint.Parent.Grammar, selectedSymbol, maxSize, maxHeight, 0, 0); 101 replacementTree = selectedSymbol.CreateTreeNode(); 103 102 invocationCutPoint.Parent.RemoveSubTree(invocationCutPoint.ReplacedChildIndex); 104 103 invocationCutPoint.Parent.InsertSubTree(invocationCutPoint.ReplacedChildIndex, replacementTree); 104 105 ProbabilisticTreeCreator.PTC2(random, replacementTree, maxSize, maxHeight, 0, 0); 105 106 106 107 invocationCutPoint = (from node in symbolicExpressionTree.IterateNodesPrefix() -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/SubroutineDuplicater.cs
r3360 r3369 72 72 duplicatedDefunBranch.Grammar = (ISymbolicExpressionGrammar)selectedBranch.Grammar.Clone(); 73 73 // add an invoke symbol for each branch that is allowed to invoke the original function 74 foreach (var subtree in symbolicExpressionTree.Root.SubTrees ) {74 foreach (var subtree in symbolicExpressionTree.Root.SubTrees.OfType<SymbolicExpressionTreeTopLevelNode>()) { 75 75 var matchingInvokeSymbol = (from symb in subtree.Grammar.Symbols.OfType<InvokeFunction>() 76 76 where symb.FunctionName == selectedBranch.FunctionName … … 79 79 GrammarModifier.AddDynamicSymbol(subtree.Grammar, subtree.Symbol, duplicatedDefunBranch.FunctionName, duplicatedDefunBranch.NumberOfArguments); 80 80 } 81 } 82 // for all invoke nodes of the original function replace the invoke of the original function with an invoke of the new function randomly 83 var originalFunctionInvocations = from node in symbolicExpressionTree.IterateNodesPrefix().OfType<InvokeFunctionTreeNode>() 84 where node.Symbol.FunctionName == selectedBranch.FunctionName 85 select node; 86 foreach (var originalFunctionInvokeNode in originalFunctionInvocations) { 87 var newInvokeSymbol = (from symb in originalFunctionInvokeNode.Grammar.Symbols.OfType<InvokeFunction>() 88 where symb.FunctionName == duplicatedDefunBranch.FunctionName 89 select symb).Single(); 90 // flip coin wether to replace with newly defined function 91 if (random.NextDouble() < 0.5) { 92 originalFunctionInvokeNode.Symbol = newInvokeSymbol; 81 // in the current subtree: 82 // for all invoke nodes of the original function replace the invoke of the original function with an invoke of the new function randomly 83 var originalFunctionInvocations = from node in subtree.IterateNodesPrefix().OfType<InvokeFunctionTreeNode>() 84 where node.Symbol.FunctionName == selectedBranch.FunctionName 85 select node; 86 foreach (var originalFunctionInvokeNode in originalFunctionInvocations) { 87 var newInvokeSymbol = (from symb in subtree.Grammar.Symbols.OfType<InvokeFunction>() 88 where symb.FunctionName == duplicatedDefunBranch.FunctionName 89 select symb).Single(); 90 // flip coin wether to replace with newly defined function 91 if (random.NextDouble() < 0.5) { 92 originalFunctionInvokeNode.Symbol = newInvokeSymbol; 93 } 93 94 } 94 95 }
Note: See TracChangeset
for help on using the changeset viewer.