Free cookie consent management tool by TermsFeed Policy Generator

Changeset 527


Ignore:
Timestamp:
08/20/08 11:36:42 (16 years ago)
Author:
gkronber
Message:

small improvement for crossover

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.StructureIdentification/TreeGardener.cs

    r526 r527  
    295295    internal IFunctionTree GetRandomBranch(IFunctionTree tree, int level) {
    296296      if(level == 0) return tree;
    297       List<IFunctionTree> branches = GetBranchesAtLevel(tree, level);
     297      List<IFunctionTree> branches = new List<IFunctionTree>();
     298      GetBranchesAtLevel(tree, level, branches);
    298299      return branches[random.Next(branches.Count)];
    299300    }
     
    465466    }
    466467
    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);
    471470      foreach(IFunctionTree subTree in tree.SubTrees) {
    472471        if(subTree.Height >= level - 1)
    473           branches.AddRange(GetBranchesAtLevel(subTree, level - 1));
    474       }
    475       return branches;
     472          GetBranchesAtLevel(subTree, level - 1, result);
     473      }
    476474    }
    477475
Note: See TracChangeset for help on using the changeset viewer.