Free cookie consent management tool by TermsFeed Policy Generator

Changeset 199


Ignore:
Timestamp:
04/27/08 19:42:37 (16 years ago)
Author:
gkronber
Message:

fixed a bug in random-tree creation

File:
1 edited

Legend:

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

    r189 r199  
    421421        int maxSubTreeSize = maxTreeSize / actualArity;
    422422        for(int i = 0; i < actualArity; i++) {
    423           if(maxTreeHeight == 1 || maxSubTreeSize == 1) {
    424             IFunction[] possibleTerminals = GetAllowedSubFunctions(parent.Function, i).Where(f => IsTerminal(f)).ToArray();
    425             IFunction selectedTerminal = RandomSelect(possibleTerminals);
     423          // first try to find a function that fits into the maxHeight and maxSize limits
     424          IFunction[] possibleFunctions = GetAllowedSubFunctions(parent.Function, i).Where(
     425            f => GetMinimalTreeHeight(f) <= maxTreeHeight &&
     426            GetMinimalTreeSize(f) <= maxSubTreeSize &&
     427            !IsTerminal(f)).ToArray();
     428          // no possible function found => extend function set to terminals
     429          if(possibleFunctions.Length == 0) {
     430            possibleFunctions = GetAllowedSubFunctions(parent.Function, i).Where(f => IsTerminal(f)).ToArray();
     431            IFunction selectedTerminal = RandomSelect(possibleFunctions);
    426432            IFunctionTree newTree = selectedTerminal.GetTreeNode();
    427433            parent.InsertSubTree(i, newTree);
    428434          } else {
    429             IFunction[] possibleFunctions = GetAllowedSubFunctions(parent.Function, i).Where(
    430               f => GetMinimalTreeHeight(f) <= maxTreeHeight &&
    431               GetMinimalTreeSize(f) <= maxSubTreeSize &&
    432               !IsTerminal(f)).ToArray();
    433435            IFunction selectedFunction = RandomSelect(possibleFunctions);
    434436            IFunctionTree newTree = selectedFunction.GetTreeNode();
Note: See TracChangeset for help on using the changeset viewer.