Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/18/08 16:20:26 (17 years ago)
Author:
gkronber
Message:

added Size and Height properties to interface IFunctionTree and removed the helper methods from TreeGardener (specific implementations of size and height properties in classes implementing IFunctionTree can be more efficient than the general functions in TreeGardener)

Location:
trunk/sources/HeuristicLab.Functions
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Functions/BakedFunctionTree.cs

    r323 r324  
    132132    }
    133133
     134    public int Size {
     135      get {
     136        if(treesExpanded) {
     137          int size = 1;
     138          foreach(BakedFunctionTree tree in subTrees) {
     139            size += tree.Size;
     140          }
     141          return size;
     142        } else
     143        return linearRepresentation.Count;
     144      }
     145    }
     146
     147    public int Height {
     148      get {
     149        if(treesExpanded) {
     150          int height = 0;
     151          foreach(IFunctionTree subTree in subTrees) {
     152            int curHeight = subTree.Height;
     153            if(curHeight > height) height = curHeight;
     154          }
     155          return height+1;
     156        } else {
     157          int nextBranchStart;
     158          return BranchHeight(0, out nextBranchStart);
     159        }
     160      }
     161    }
     162
     163    private int BranchHeight(int branchStart, out int nextBranchStart) {
     164      LightWeightFunction f = linearRepresentation[branchStart];
     165      int height = 0;
     166      branchStart++;
     167      for(int i = 0; i < f.arity; i++) {
     168        int curHeight = BranchHeight(branchStart, out nextBranchStart);
     169        if(curHeight > height) height = curHeight;
     170        branchStart = nextBranchStart;
     171      }
     172      nextBranchStart = branchStart;
     173      return height + 1;
     174    }
     175
    134176    public IList<IFunctionTree> SubTrees {
    135177      get {
     
    142184            int length = BranchLength(branchIndex);
    143185            for(int j = branchIndex; j < branchIndex + length; j++) {
    144               subTree.linearRepresentation.Add(linearRepresentation[j].Clone());
     186              subTree.linearRepresentation.Add(linearRepresentation[j]);
    145187            }
    146188            branchIndex += length;
  • trunk/sources/HeuristicLab.Functions/IFunctionTree.cs

    r155 r324  
    2828namespace HeuristicLab.Functions {
    2929  public interface IFunctionTree : IItem {
     30    int Size { get; }
     31    int Height { get; }
    3032    IList<IFunctionTree> SubTrees { get; }
    3133    ICollection<IVariable> LocalVariables { get; }
Note: See TracChangeset for help on using the changeset viewer.