Free cookie consent management tool by TermsFeed Policy Generator

Changeset 526


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

refactoring: removed method GetMinMaxArity in TreeGardener (#263 (List of allowed sub-functions for each function should be cached))

Location:
trunk/sources/HeuristicLab.StructureIdentification
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.StructureIdentification/Manipulation/ChangeNodeTypeManipulation.cs

    r324 r526  
    152152      // try to make a tree with the same arity as the old child.
    153153      int actualArity = child.SubTrees.Count;
    154       // arity of the selected operator
    155       int minArity;
    156       int maxArity;
    157154      // create a new tree-node for a randomly selected function
    158155      IFunction selectedFunction = allowedFunctions[random.Next(allowedFunctions.Count)];
    159       gardener.GetMinMaxArity(selectedFunction, out minArity, out maxArity);
     156      // arity of the selected operator
     157      int minArity = selectedFunction.MinArity;
     158      int maxArity = selectedFunction.MaxArity;
    160159      // if the old child had too many sub-trees then the new child should keep as many sub-trees as possible
    161160      if (actualArity > maxArity)
  • trunk/sources/HeuristicLab.StructureIdentification/Manipulation/DeleteSubTreeManipulation.cs

    r324 r526  
    7474      // select a branch to prune
    7575      int childIndex = random.Next(parent.SubTrees.Count);
    76       int min;
    77       int max;
    78       gardener.GetMinMaxArity(parent.Function, out min, out max);
    79       if(parent.SubTrees.Count > min) {
     76      if(parent.SubTrees.Count > parent.Function.MinArity) {
    8077        parent.RemoveSubTree(childIndex);
    8178        // actually since the next sub-trees are shifted in the place of the removed branch
  • trunk/sources/HeuristicLab.StructureIdentification/Recombination/SizeFairCrossOver.cs

    r450 r526  
    214214      IFunctionTree parent = possibleParents.ElementAt(random.Next(possibleParents.Count())).GetTreeNode();
    215215
    216       int minArity;
    217       int maxArity;
    218       gardener.GetMinMaxArity(parent.Function, out minArity, out maxArity);
    219       int nSlots = Math.Max(2, minArity);
     216      int nSlots = Math.Max(2, parent.Function.MinArity);
    220217      // determine which slot can take which sub-trees
    221218      List<IFunctionTree>[] slots = new List<IFunctionTree>[nSlots];
  • trunk/sources/HeuristicLab.StructureIdentification/TreeGardener.cs

    r525 r526  
    5959      // init functions and terminals based on constraints
    6060      foreach(IFunction fun in funLibrary.Group.Operators) {
    61         int maxA, minA;
    62         GetMinMaxArity(fun, out minA, out maxA);
    63         if(maxA == 0) {
     61        if(fun.MaxArity == 0) {
    6462          terminals.Add(fun);
    6563          allFunctions.Add(fun);
     
    109107      int currentSize = 1;
    110108      int totalListMinSize = 0;
    111       int minArity;
    112       int maxArity;
    113       GetMinMaxArity(root.Function, out minArity, out maxArity);
     109      int minArity = root.Function.MinArity;
     110      int maxArity = root.Function.MaxArity;
    114111      if(maxArity >= size) {
    115112        maxArity = size;
     
    145142          totalListMinSize--;
    146143
    147           GetMinMaxArity(selectedFunction, out minArity, out maxArity);
     144          minArity = selectedFunction.MinArity;
     145          maxArity = selectedFunction.MaxArity;
    148146          if(maxArity >= size) {
    149147            maxArity = size;
     
    314312
    315313    private bool IsPossibleParent(IFunction f, List<IFunction> children) {
    316       int minArity;
    317       int maxArity;
    318       GetMinMaxArity(f, out minArity, out maxArity);
    319 
     314      int minArity = f.MinArity;
     315      int maxArity = f.MaxArity;
    320316      // note: we can't assume that the operators in the children list have different types!
    321317
     
    380376    }
    381377    internal bool IsTerminal(IFunction f) {
    382       int minArity;
    383       int maxArity;
    384       GetMinMaxArity(f, out minArity, out maxArity);
    385       return minArity == 0 && maxArity == 0;
     378      return f.MinArity == 0 && f.MaxArity == 0;
    386379    }
    387380    internal IList<IFunction> GetAllowedSubFunctions(IFunction f, int index) {
     
    391384        return f.AllowedSubFunctions(index);
    392385      }
    393     }
    394     internal void GetMinMaxArity(IFunction f, out int minArity, out int maxArity) {
    395       minArity = f.MinArity;
    396       maxArity = f.MaxArity;
    397386    }
    398387    #endregion
     
    414403    private IFunctionTree MakeUnbalancedTree(IFunction parent, int maxTreeHeight) {
    415404      if(maxTreeHeight == 0) return parent.GetTreeNode();
    416       int minArity;
    417       int maxArity;
    418       GetMinMaxArity(parent, out minArity, out maxArity);
     405      int minArity = parent.MinArity;
     406      int maxArity = parent.MaxArity;
    419407      int actualArity = random.Next(minArity, maxArity + 1);
    420408      if(actualArity > 0) {
     
    436424    private IFunctionTree MakeBalancedTree(IFunction parent, int maxTreeHeight) {
    437425      if(maxTreeHeight == 0) return parent.GetTreeNode();
    438       int minArity;
    439       int maxArity;
    440       GetMinMaxArity(parent, out minArity, out maxArity);
     426      int minArity = parent.MinArity;
     427      int maxArity = parent.MaxArity;
    441428      int actualArity = random.Next(minArity, maxArity + 1);
    442429      if(actualArity > 0) {
Note: See TracChangeset for help on using the changeset viewer.