Changeset 526
- Timestamp:
- 08/20/08 11:06:11 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.StructureIdentification
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.StructureIdentification/Manipulation/ChangeNodeTypeManipulation.cs
r324 r526 152 152 // try to make a tree with the same arity as the old child. 153 153 int actualArity = child.SubTrees.Count; 154 // arity of the selected operator155 int minArity;156 int maxArity;157 154 // create a new tree-node for a randomly selected function 158 155 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; 160 159 // if the old child had too many sub-trees then the new child should keep as many sub-trees as possible 161 160 if (actualArity > maxArity) -
trunk/sources/HeuristicLab.StructureIdentification/Manipulation/DeleteSubTreeManipulation.cs
r324 r526 74 74 // select a branch to prune 75 75 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) { 80 77 parent.RemoveSubTree(childIndex); 81 78 // actually since the next sub-trees are shifted in the place of the removed branch -
trunk/sources/HeuristicLab.StructureIdentification/Recombination/SizeFairCrossOver.cs
r450 r526 214 214 IFunctionTree parent = possibleParents.ElementAt(random.Next(possibleParents.Count())).GetTreeNode(); 215 215 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); 220 217 // determine which slot can take which sub-trees 221 218 List<IFunctionTree>[] slots = new List<IFunctionTree>[nSlots]; -
trunk/sources/HeuristicLab.StructureIdentification/TreeGardener.cs
r525 r526 59 59 // init functions and terminals based on constraints 60 60 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) { 64 62 terminals.Add(fun); 65 63 allFunctions.Add(fun); … … 109 107 int currentSize = 1; 110 108 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; 114 111 if(maxArity >= size) { 115 112 maxArity = size; … … 145 142 totalListMinSize--; 146 143 147 GetMinMaxArity(selectedFunction, out minArity, out maxArity); 144 minArity = selectedFunction.MinArity; 145 maxArity = selectedFunction.MaxArity; 148 146 if(maxArity >= size) { 149 147 maxArity = size; … … 314 312 315 313 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; 320 316 // note: we can't assume that the operators in the children list have different types! 321 317 … … 380 376 } 381 377 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; 386 379 } 387 380 internal IList<IFunction> GetAllowedSubFunctions(IFunction f, int index) { … … 391 384 return f.AllowedSubFunctions(index); 392 385 } 393 }394 internal void GetMinMaxArity(IFunction f, out int minArity, out int maxArity) {395 minArity = f.MinArity;396 maxArity = f.MaxArity;397 386 } 398 387 #endregion … … 414 403 private IFunctionTree MakeUnbalancedTree(IFunction parent, int maxTreeHeight) { 415 404 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; 419 407 int actualArity = random.Next(minArity, maxArity + 1); 420 408 if(actualArity > 0) { … … 436 424 private IFunctionTree MakeBalancedTree(IFunction parent, int maxTreeHeight) { 437 425 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; 441 428 int actualArity = random.Next(minArity, maxArity + 1); 442 429 if(actualArity > 0) {
Note: See TracChangeset
for help on using the changeset viewer.