Changeset 1212 for trunk/sources/HeuristicLab.GP/Recombination
- Timestamp:
- 02/10/09 12:59:37 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.GP/Recombination
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/sources/HeuristicLab.GP/Recombination/SizeConstrictedGPCrossoverBase.cs ¶
r1197 r1212 50 50 int tries = 0; 51 51 do { 52 if (tries++ > MaxRecombinationTries) 53 // if after so many tries it was not possible to create a solution within the given size constraints just return the tree without changes. 54 return tree0; 52 55 if (tree0.SubTrees.Count > 0) { 53 56 newTree = Cross(gardener, random, (IFunctionTree)tree0.Clone(), (IFunctionTree)tree1.Clone(), maxTreeSize, maxTreeHeight); … … 55 58 newTree = Cross(gardener, random, (IFunctionTree)tree1.Clone(), (IFunctionTree)tree0.Clone(), maxTreeSize, maxTreeHeight); 56 59 } else newTree = tree0; 57 if (tries++ > MaxRecombinationTries)58 throw new InvalidOperationException("Couldn't recombine parents to create a valid child not larger than " + maxTreeSize + " and not higher than " + maxTreeHeight + ".");59 60 } while (newTree.Size > maxTreeSize || newTree.Height > maxTreeHeight); 60 61 return newTree; -
TabularUnified trunk/sources/HeuristicLab.GP/Recombination/SizeFairCrossOver.cs ¶
r1197 r1212 83 83 if (shorterBranches.Count > 0 && longerBranches.Count > 0) { 84 84 double pEqualLength = equalLengthBranches.Count > 0 ? 1.0 / removedBranchSize : 0.0; 85 double pLonger = (1.0 - pEqualLength) / (longerBranches.Count * (1.0 + longerBranches.Average(p => p.branchSize) / shorterBranches.Average(p => p.branchSize))); 85 double pLonger; 86 if (parent.Size == maxTreeSize) { 87 pLonger = 0.0; 88 } else { 89 pLonger = (1.0 - pEqualLength) / (longerBranches.Count * (1.0 + longerBranches.Average(p => p.branchSize) / shorterBranches.Average(p => p.branchSize))); 90 } 86 91 double pShorter = (1.0 - pEqualLength - pLonger); 87 92
Note: See TracChangeset
for help on using the changeset viewer.