Changeset 450 for trunk/sources
- Timestamp:
- 08/05/08 16:31:40 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.StructureIdentification
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.StructureIdentification/Recombination/SizeFairCrossOver.cs
r444 r450 240 240 if(allowedTrees.Count() == 0) { 241 241 var allowedFunctions = gardener.GetAllowedSubFunctions(parent.Function, slot); 242 selectedFunctionTrees[slot] = gardener.CreateRandomTree(allowedFunctions, 1, 1 , true);242 selectedFunctionTrees[slot] = gardener.CreateRandomTree(allowedFunctions, 1, 1); 243 243 newBranches.AddRange(gardener.GetAllSubTrees(selectedFunctionTrees[slot])); 244 244 } else { -
trunk/sources/HeuristicLab.StructureIdentification/TreeGardener.cs
r449 r450 180 180 /// <returns>New random unbalanced tree</returns> 181 181 internal IFunctionTree CreateRandomTree(ICollection<IFunction> allowedFunctions, int maxTreeSize, int maxTreeHeight) { 182 // default is non-balanced trees183 return CreateRandomTree(allowedFunctions, maxTreeSize, maxTreeHeight, false);184 }185 186 /// <summary>187 /// Selects a random function from allowedFunctions and creates a (un)balanced random tree with maximal size and height.188 /// Max-size and max-height are not accepted as hard constraints, if all functions in the set of allowed functions would189 /// lead to a bigger tree then the limits are automatically extended to guarantee that we can build a tree.190 /// </summary>191 /// <param name="allowedFunctions">Set of allowed functions.</param>192 /// <param name="maxTreeSize">Maximal size of the tree (number of nodes).</param>193 /// <param name="maxTreeHeight">Maximal height of the tree.</param>194 /// <param name="balanceTrees">Flag determining whether the tree should be balanced or not.</param>195 /// <returns>New random tree</returns>196 internal IFunctionTree CreateRandomTree(ICollection<IFunction> allowedFunctions, int maxTreeSize, int maxTreeHeight, bool balanceTrees) {197 182 // get the minimal needed height based on allowed functions and extend the max-height if necessary 198 183 int minTreeHeight = allowedFunctions.Select(f => GetMinimalTreeHeight(f)).Min(); … … 215 200 // build the tree 216 201 IFunctionTree root; 217 if(balanceTrees) { 218 root = PTC2(random, selectedFunction, maxTreeSize -1, maxTreeHeight - 1); 219 } else { 220 root = PTC2(random, selectedFunction, maxTreeSize - 1, maxTreeHeight - 1); 221 } 202 root = PTC2(random, selectedFunction, maxTreeSize - 1, maxTreeHeight - 1); 222 203 return root; 223 204 } … … 483 464 for(int i = 0; i < actualArity; i++) { 484 465 // first try to find a function that fits into the maxHeight limit 485 IFunction[] possibleFunctions = GetAllowedSubFunctions(parent, i).Where(f => GetMinimalTreeHeight(f) <= maxTreeHeight && 466 IFunction[] possibleFunctions = GetAllowedSubFunctions(parent, i).Where(f => GetMinimalTreeHeight(f) <= maxTreeHeight && 486 467 !IsTerminal(f)).ToArray(); 487 468 // no possible function found => extend function set to terminals
Note: See TracChangeset
for help on using the changeset viewer.