Changeset 527
- Timestamp:
- 08/20/08 11:36:42 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.StructureIdentification/TreeGardener.cs
r526 r527 295 295 internal IFunctionTree GetRandomBranch(IFunctionTree tree, int level) { 296 296 if(level == 0) return tree; 297 List<IFunctionTree> branches = GetBranchesAtLevel(tree, level); 297 List<IFunctionTree> branches = new List<IFunctionTree>(); 298 GetBranchesAtLevel(tree, level, branches); 298 299 return branches[random.Next(branches.Count)]; 299 300 } … … 465 466 } 466 467 467 private List<IFunctionTree> GetBranchesAtLevel(IFunctionTree tree, int level) { 468 if(level == 1) return new List<IFunctionTree>(tree.SubTrees); 469 470 List<IFunctionTree> branches = new List<IFunctionTree>(); 468 private void GetBranchesAtLevel(IFunctionTree tree, int level, List<IFunctionTree> result) { 469 if(level == 1) result.AddRange(tree.SubTrees); 471 470 foreach(IFunctionTree subTree in tree.SubTrees) { 472 471 if(subTree.Height >= level - 1) 473 branches.AddRange(GetBranchesAtLevel(subTree, level - 1)); 474 } 475 return branches; 472 GetBranchesAtLevel(subTree, level - 1, result); 473 } 476 474 } 477 475
Note: See TracChangeset
for help on using the changeset viewer.