Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/29/09 19:07:21 (15 years ago)
Author:
gkronber
Message:

#713

  • renamed MinArity and MaxArity properties
  • fixed a caching bug in the Dataset
  • renamed BakedTreeEvaluator to HL3TreeEvaluator
  • deleted class BakedFunctionTree
Location:
branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3
Files:
1 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/BaseClasses/BinaryFunction.cs

    r2210 r2211  
    3030    public BinaryFunction()
    3131      : base() {
    32       MinArity = 2; MaxArity = 2;
     32      MinSubTrees = 2; MaxSubTrees = 2;
    3333    }
    3434  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/BaseClasses/FunctionBase.cs

    r2210 r2211  
    4949    }
    5050
    51     public int MinArity {
     51    public int MinSubTrees {
    5252      get {
    5353        return minArity;
     
    5959    }
    6060
    61     public int MaxArity {
     61    public int MaxSubTrees {
    6262      get {
    6363        return maxArity;
     
    128128
    129129    public ICollection<IFunction> GetAllowedSubFunctions(int index) {
    130       if (index < 0 || index > MaxArity) throw new ArgumentException("Index outside of allowed range. index = " + index);
     130      if (index < 0 || index > MaxSubTrees) throw new ArgumentException("Index outside of allowed range. index = " + index);
    131131      //if (allowedSubFunctions == null) {
    132132      //  // first time: analyze the constraint and create a cached copy of the allowed sub-functions
     
    140140
    141141    public void AddAllowedSubFunction(IFunction function, int index) {
    142       if (index < 0 || index > MaxArity) throw new ArgumentException("Index outside of allowed range. index = " + index);
     142      if (index < 0 || index > MaxSubTrees) throw new ArgumentException("Index outside of allowed range. index = " + index);
    143143      if (allowedSubFunctions[index] == null) {
    144144        allowedSubFunctions[index] = new List<IFunction>();
     
    150150
    151151    public void RemoveAllowedSubFunction(IFunction function, int index) {
    152       if (index < 0 || index > MaxArity) throw new ArgumentException("Index outside of allowed range. index = " + index);
     152      if (index < 0 || index > MaxSubTrees) throw new ArgumentException("Index outside of allowed range. index = " + index);
    153153      allowedSubFunctions[index].Add(function);
    154154    }
     
    190190      int sum = 1;
    191191      int minSize = int.MaxValue;
    192       for (int i = 0; i < MinArity; i++) {
     192      for (int i = 0; i < MinSubTrees; i++) {
    193193        foreach (IFunction subFun in GetAllowedSubFunctions(i)) {
    194194          minSize = Math.Min(minSize, subFun.MinTreeSize);
     
    203203      int height = 0;
    204204      int minHeight = int.MaxValue;
    205       for (int i = 0; i < MinArity; i++) {
     205      for (int i = 0; i < MinSubTrees; i++) {
    206206        foreach (IFunction subFun in GetAllowedSubFunctions(i)) {
    207207          minHeight = Math.Min(minHeight, subFun.MinTreeHeight);
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/BaseClasses/FunctionTreeBase.cs

    r2210 r2211  
    3131    private IFunction function;
    3232
     33    public FunctionTreeBase() {
     34    }
     35
    3336    public FunctionTreeBase(IFunction function) {
    3437      subTrees = new List<IFunctionTree>();
     
    4952    }
    5053
    51     public IList<IFunctionTree> SubTrees {
     54    public virtual IList<IFunctionTree> SubTrees {
    5255      get { return subTrees; }
    5356    }
     
    5558    public IFunction Function {
    5659      get { return function; }
     60      protected set {
     61        function = value;
     62      }
    5763    }
    5864
    5965    public int GetSize() {
    6066      int size = 1;
    61       foreach (IFunctionTree tree in subTrees) size += tree.GetSize();
     67      foreach (IFunctionTree tree in SubTrees) size += tree.GetSize();
    6268      return size;
    6369    }
     
    6571    public int GetHeight() {
    6672      int maxHeight = 0;
    67       foreach (IFunctionTree tree in subTrees) maxHeight = Math.Max(maxHeight, tree.GetHeight());
     73      foreach (IFunctionTree tree in SubTrees) maxHeight = Math.Max(maxHeight, tree.GetHeight());
    6874      return maxHeight + 1;
    6975    }
     
    7884
    7985    public void AddSubTree(IFunctionTree tree) {
    80       subTrees.Add(tree);
     86      SubTrees.Add(tree);
    8187    }
    8288
    83     public void InsertSubTree(int index, IFunctionTree tree) {
    84       subTrees.Insert(index, tree);
     89    public virtual void InsertSubTree(int index, IFunctionTree tree) {
     90      SubTrees.Insert(index, tree);
    8591    }
    8692
    87     public void RemoveSubTree(int index) {
    88       subTrees.RemoveAt(index);
     93    public virtual void RemoveSubTree(int index) {
     94      SubTrees.RemoveAt(index);
    8995    }
    9096
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/BaseClasses/Terminal.cs

    r2210 r2211  
    3030    public Terminal()
    3131      : base() {
    32       MinArity = 0; MaxArity = 0;
     32      MinSubTrees = 0; MaxSubTrees = 0;
    3333    }
    3434  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/BaseClasses/UnaryFunction.cs

    r2210 r2211  
    3030    public UnaryFunction()
    3131      : base() {
    32       MinArity = 1; MaxArity = 1;
     32      MinSubTrees = 1; MaxSubTrees = 1;
    3333    }
    3434  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/Manipulation/ChangeNodeTypeManipulation.cs

    r2210 r2211  
    136136      IFunction selectedFunction = allowedFunctions[random.Next(allowedFunctions.Count)];
    137137      // arity of the selected operator
    138       int minArity = selectedFunction.MinArity;
    139       int maxArity = selectedFunction.MaxArity;
     138      int minArity = selectedFunction.MinSubTrees;
     139      int maxArity = selectedFunction.MaxSubTrees;
    140140      // if the old child had too many sub-trees then the new child should keep as many sub-trees as possible
    141141      if (actualArity > maxArity)
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/Manipulation/DeleteSubTreeManipulation.cs

    r2210 r2211  
    5959      // select a branch to prune
    6060      int childIndex = random.Next(parent.SubTrees.Count);
    61       if (parent.SubTrees.Count > parent.Function.MinArity) {
     61      if (parent.SubTrees.Count > parent.Function.MinSubTrees) {
    6262        parent.RemoveSubTree(childIndex);
    6363        // actually since the next sub-trees are shifted in the place of the removed branch
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/TreeGardener.cs

    r2210 r2211  
    5959      // init functions and terminals based on constraints
    6060      foreach(IFunction fun in funLibrary.Functions) {
    61         if(fun.MaxArity == 0) {
     61        if(fun.MaxSubTrees == 0) {
    6262          terminals.Add(fun);
    6363          allFunctions.Add(fun);
     
    107107      int currentSize = 1;
    108108      int totalListMinSize = 0;
    109       int minArity = root.Function.MinArity;
    110       int maxArity = root.Function.MaxArity;
     109      int minArity = root.Function.MinSubTrees;
     110      int maxArity = root.Function.MaxSubTrees;
    111111      if (maxArity >= size) {
    112112        maxArity = size;
     
    142142          totalListMinSize--;
    143143
    144           minArity = selectedFunction.MinArity;
    145           maxArity = selectedFunction.MaxArity;
     144          minArity = selectedFunction.MinSubTrees;
     145          maxArity = selectedFunction.MaxSubTrees;
    146146          if (maxArity >= size) {
    147147            maxArity = size;
     
    277277      }
    278278
    279       if(tree.SubTrees.Count < tree.Function.MinArity || tree.SubTrees.Count > tree.Function.MaxArity)
     279      if(tree.SubTrees.Count < tree.Function.MinSubTrees || tree.SubTrees.Count > tree.Function.MaxSubTrees)
    280280        return false;
    281281      foreach(IFunctionTree subTree in tree.SubTrees) {
     
    306306
    307307    private bool IsPossibleParent(IFunction f, List<IFunction> children) {
    308       int minArity = f.MinArity;
    309       int maxArity = f.MaxArity;
     308      int minArity = f.MinSubTrees;
     309      int maxArity = f.MaxSubTrees;
    310310      // note: we can't assume that the operators in the children list have different types!
    311311
     
    370370    }
    371371    internal static bool IsTerminal(IFunction f) {
    372       return f.MinArity == 0 && f.MaxArity == 0;
     372      return f.MinSubTrees == 0 && f.MaxSubTrees == 0;
    373373    }
    374374    internal ICollection<IFunction> GetAllowedSubFunctions(IFunction f, int index) {
     
    397397    private IFunctionTree MakeUnbalancedTree(IFunction parent, int maxTreeHeight) {
    398398      if(maxTreeHeight == 0) return parent.GetTreeNode();
    399       int minArity = parent.MinArity;
    400       int maxArity = parent.MaxArity;
     399      int minArity = parent.MinSubTrees;
     400      int maxArity = parent.MaxSubTrees;
    401401      int actualArity = random.Next(minArity, maxArity + 1);
    402402      if(actualArity > 0) {
     
    418418    private IFunctionTree MakeBalancedTree(IFunction parent, int maxTreeHeight) {
    419419      if(maxTreeHeight == 0) return parent.GetTreeNode();
    420       int minArity = parent.MinArity;
    421       int maxArity = parent.MaxArity;
     420      int minArity = parent.MinSubTrees;
     421      int maxArity = parent.MaxSubTrees;
    422422      int actualArity = random.Next(minArity, maxArity + 1);
    423423      if(actualArity > 0) {
Note: See TracChangeset for help on using the changeset viewer.