Changeset 3338 for trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/SubroutineDuplicater.cs
- Timestamp:
- 04/13/10 20:44:31 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/SubroutineDuplicater.cs
r3294 r3338 65 65 // no function defining branches to duplicate or already reached the max number of ADFs 66 66 return false; 67 var selectedBranch = (DefunTreeNode)SelectRandomBranch(random, functionDefiningBranches);67 var selectedBranch = functionDefiningBranches.SelectRandom(random); 68 68 var clonedBranch = (DefunTreeNode)selectedBranch.Clone(); 69 69 clonedBranch.Name = allowedFunctionNames.Except(UsedFunctionNames(symbolicExpressionTree)).First(); … … 73 73 if (invokeFunctionNode != null && invokeFunctionNode.InvokedFunctionName == selectedBranch.Name) { 74 74 // add the new function name to the list of known functions in the branches that used the originating function 75 var branch = FindDefiningBranch(symbolicExpressionTree,invokeFunctionNode);75 var branch = symbolicExpressionTree.GetTopLevelBranchOf(invokeFunctionNode); 76 76 branch.AddDynamicSymbol(clonedBranch.Name, clonedBranch.NumberOfArguments); 77 77 // flip coin wether to replace with newly defined function … … 83 83 Debug.Assert(grammar.IsValidExpression(symbolicExpressionTree)); 84 84 return true; 85 }86 87 private static SymbolicExpressionTreeNode FindDefiningBranch(SymbolicExpressionTree tree, SymbolicExpressionTreeNode node) {88 foreach (var subtree in tree.Root.SubTrees) {89 if (ContainsNode(subtree, node)) return subtree;90 }91 return null;92 85 } 93 86 … … 106 99 } 107 100 108 private static SymbolicExpressionTreeNode SelectRandomBranch(IRandom random, IEnumerable<DefunTreeNode> branches) { 109 var list = branches.ToList(); 110 return list[random.Next(list.Count)]; 111 } 101 112 102 } 113 103 }
Note: See TracChangeset
for help on using the changeset viewer.