Changeset 2211 for branches/GP-Refactoring-713/sources/HeuristicLab.GP
- Timestamp:
- 07/29/09 19:07:21 (15 years ago)
- 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 30 30 public BinaryFunction() 31 31 : base() { 32 Min Arity = 2; MaxArity= 2;32 MinSubTrees = 2; MaxSubTrees = 2; 33 33 } 34 34 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/BaseClasses/FunctionBase.cs
r2210 r2211 49 49 } 50 50 51 public int Min Arity{51 public int MinSubTrees { 52 52 get { 53 53 return minArity; … … 59 59 } 60 60 61 public int Max Arity{61 public int MaxSubTrees { 62 62 get { 63 63 return maxArity; … … 128 128 129 129 public ICollection<IFunction> GetAllowedSubFunctions(int index) { 130 if (index < 0 || index > Max Arity) 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); 131 131 //if (allowedSubFunctions == null) { 132 132 // // first time: analyze the constraint and create a cached copy of the allowed sub-functions … … 140 140 141 141 public void AddAllowedSubFunction(IFunction function, int index) { 142 if (index < 0 || index > Max Arity) 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); 143 143 if (allowedSubFunctions[index] == null) { 144 144 allowedSubFunctions[index] = new List<IFunction>(); … … 150 150 151 151 public void RemoveAllowedSubFunction(IFunction function, int index) { 152 if (index < 0 || index > Max Arity) 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); 153 153 allowedSubFunctions[index].Add(function); 154 154 } … … 190 190 int sum = 1; 191 191 int minSize = int.MaxValue; 192 for (int i = 0; i < Min Arity; i++) {192 for (int i = 0; i < MinSubTrees; i++) { 193 193 foreach (IFunction subFun in GetAllowedSubFunctions(i)) { 194 194 minSize = Math.Min(minSize, subFun.MinTreeSize); … … 203 203 int height = 0; 204 204 int minHeight = int.MaxValue; 205 for (int i = 0; i < Min Arity; i++) {205 for (int i = 0; i < MinSubTrees; i++) { 206 206 foreach (IFunction subFun in GetAllowedSubFunctions(i)) { 207 207 minHeight = Math.Min(minHeight, subFun.MinTreeHeight); -
branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/BaseClasses/FunctionTreeBase.cs
r2210 r2211 31 31 private IFunction function; 32 32 33 public FunctionTreeBase() { 34 } 35 33 36 public FunctionTreeBase(IFunction function) { 34 37 subTrees = new List<IFunctionTree>(); … … 49 52 } 50 53 51 public IList<IFunctionTree> SubTrees {54 public virtual IList<IFunctionTree> SubTrees { 52 55 get { return subTrees; } 53 56 } … … 55 58 public IFunction Function { 56 59 get { return function; } 60 protected set { 61 function = value; 62 } 57 63 } 58 64 59 65 public int GetSize() { 60 66 int size = 1; 61 foreach (IFunctionTree tree in subTrees) size += tree.GetSize();67 foreach (IFunctionTree tree in SubTrees) size += tree.GetSize(); 62 68 return size; 63 69 } … … 65 71 public int GetHeight() { 66 72 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()); 68 74 return maxHeight + 1; 69 75 } … … 78 84 79 85 public void AddSubTree(IFunctionTree tree) { 80 subTrees.Add(tree);86 SubTrees.Add(tree); 81 87 } 82 88 83 public v oid InsertSubTree(int index, IFunctionTree tree) {84 subTrees.Insert(index, tree);89 public virtual void InsertSubTree(int index, IFunctionTree tree) { 90 SubTrees.Insert(index, tree); 85 91 } 86 92 87 public v oid RemoveSubTree(int index) {88 subTrees.RemoveAt(index);93 public virtual void RemoveSubTree(int index) { 94 SubTrees.RemoveAt(index); 89 95 } 90 96 -
branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/BaseClasses/Terminal.cs
r2210 r2211 30 30 public Terminal() 31 31 : base() { 32 Min Arity = 0; MaxArity= 0;32 MinSubTrees = 0; MaxSubTrees = 0; 33 33 } 34 34 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/BaseClasses/UnaryFunction.cs
r2210 r2211 30 30 public UnaryFunction() 31 31 : base() { 32 Min Arity = 1; MaxArity= 1;32 MinSubTrees = 1; MaxSubTrees = 1; 33 33 } 34 34 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/Manipulation/ChangeNodeTypeManipulation.cs
r2210 r2211 136 136 IFunction selectedFunction = allowedFunctions[random.Next(allowedFunctions.Count)]; 137 137 // arity of the selected operator 138 int minArity = selectedFunction.Min Arity;139 int maxArity = selectedFunction.Max Arity;138 int minArity = selectedFunction.MinSubTrees; 139 int maxArity = selectedFunction.MaxSubTrees; 140 140 // if the old child had too many sub-trees then the new child should keep as many sub-trees as possible 141 141 if (actualArity > maxArity) -
branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/Manipulation/DeleteSubTreeManipulation.cs
r2210 r2211 59 59 // select a branch to prune 60 60 int childIndex = random.Next(parent.SubTrees.Count); 61 if (parent.SubTrees.Count > parent.Function.Min Arity) {61 if (parent.SubTrees.Count > parent.Function.MinSubTrees) { 62 62 parent.RemoveSubTree(childIndex); 63 63 // 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 59 59 // init functions and terminals based on constraints 60 60 foreach(IFunction fun in funLibrary.Functions) { 61 if(fun.Max Arity== 0) {61 if(fun.MaxSubTrees == 0) { 62 62 terminals.Add(fun); 63 63 allFunctions.Add(fun); … … 107 107 int currentSize = 1; 108 108 int totalListMinSize = 0; 109 int minArity = root.Function.Min Arity;110 int maxArity = root.Function.Max Arity;109 int minArity = root.Function.MinSubTrees; 110 int maxArity = root.Function.MaxSubTrees; 111 111 if (maxArity >= size) { 112 112 maxArity = size; … … 142 142 totalListMinSize--; 143 143 144 minArity = selectedFunction.Min Arity;145 maxArity = selectedFunction.Max Arity;144 minArity = selectedFunction.MinSubTrees; 145 maxArity = selectedFunction.MaxSubTrees; 146 146 if (maxArity >= size) { 147 147 maxArity = size; … … 277 277 } 278 278 279 if(tree.SubTrees.Count < tree.Function.Min Arity || tree.SubTrees.Count > tree.Function.MaxArity)279 if(tree.SubTrees.Count < tree.Function.MinSubTrees || tree.SubTrees.Count > tree.Function.MaxSubTrees) 280 280 return false; 281 281 foreach(IFunctionTree subTree in tree.SubTrees) { … … 306 306 307 307 private bool IsPossibleParent(IFunction f, List<IFunction> children) { 308 int minArity = f.Min Arity;309 int maxArity = f.Max Arity;308 int minArity = f.MinSubTrees; 309 int maxArity = f.MaxSubTrees; 310 310 // note: we can't assume that the operators in the children list have different types! 311 311 … … 370 370 } 371 371 internal static bool IsTerminal(IFunction f) { 372 return f.Min Arity == 0 && f.MaxArity== 0;372 return f.MinSubTrees == 0 && f.MaxSubTrees == 0; 373 373 } 374 374 internal ICollection<IFunction> GetAllowedSubFunctions(IFunction f, int index) { … … 397 397 private IFunctionTree MakeUnbalancedTree(IFunction parent, int maxTreeHeight) { 398 398 if(maxTreeHeight == 0) return parent.GetTreeNode(); 399 int minArity = parent.Min Arity;400 int maxArity = parent.Max Arity;399 int minArity = parent.MinSubTrees; 400 int maxArity = parent.MaxSubTrees; 401 401 int actualArity = random.Next(minArity, maxArity + 1); 402 402 if(actualArity > 0) { … … 418 418 private IFunctionTree MakeBalancedTree(IFunction parent, int maxTreeHeight) { 419 419 if(maxTreeHeight == 0) return parent.GetTreeNode(); 420 int minArity = parent.Min Arity;421 int maxArity = parent.Max Arity;420 int minArity = parent.MinSubTrees; 421 int maxArity = parent.MaxSubTrees; 422 422 int actualArity = random.Next(minArity, maxArity + 1); 423 423 if(actualArity > 0) {
Note: See TracChangeset
for help on using the changeset viewer.