Changeset 1196 for branches/CEDMA-Refactoring-Ticket419/HeuristicLab.GP/Recombination/StandardCrossOver.cs
- Timestamp:
- 02/02/09 12:45:08 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.GP/Recombination/StandardCrossOver.cs
r1064 r1196 33 33 namespace HeuristicLab.GP { 34 34 public class StandardCrossOver : SizeConstrictedGPCrossoverBase { 35 private const int MAX_RECOMBINATION_TRIES = 20;35 private int MaxRecombinationTries { get { return 20; } } 36 36 37 37 public override string Description { … … 52 52 // select a random crossover point in the first parent tree0 53 53 parent0 = null; 54 while (parent0 == null) parent0 = gardener.GetRandomParentNode(tree0);54 while (parent0 == null) parent0 = gardener.GetRandomParentNode(tree0); 55 55 // select a random branch to replace 56 56 replacedChildIndex = random.Next(parent0.SubTrees.Count); … … 62 62 IList<IFunction> allowedFunctions = gardener.GetAllowedSubFunctions(parent0.Function, replacedChildIndex); 63 63 allowedCrossoverPoints = GetPossibleCrossoverPoints(gardener, tree1, maxInsertedBranchSize, maxInsertedBranchHeight, allowedFunctions); 64 } while (allowedCrossoverPoints.Count == 0 && tries++ < MAX_RECOMBINATION_TRIES);64 } while (allowedCrossoverPoints.Count == 0 && tries++ < MaxRecombinationTries); 65 65 66 if (allowedCrossoverPoints.Count > 0) {66 if (allowedCrossoverPoints.Count > 0) { 67 67 IFunctionTree branch1 = allowedCrossoverPoints[random.Next(allowedCrossoverPoints.Count)]; 68 68 … … 76 76 private List<IFunctionTree> GetPossibleCrossoverPoints(TreeGardener gardener, IFunctionTree tree, int maxInsertedBranchSize, int maxInsertedBranchHeight, IList<IFunction> allowedFunctions) { 77 77 List<IFunctionTree> crossoverPoints = new List<IFunctionTree>(); 78 foreach (IFunctionTree possiblePoint in gardener.GetAllSubTrees(tree)) {79 if (allowedFunctions.Contains(possiblePoint.Function) && possiblePoint.Size <= maxInsertedBranchSize && possiblePoint.Height <= maxInsertedBranchHeight)78 foreach (IFunctionTree possiblePoint in gardener.GetAllSubTrees(tree)) { 79 if (allowedFunctions.Contains(possiblePoint.Function) && possiblePoint.Size <= maxInsertedBranchSize && possiblePoint.Height <= maxInsertedBranchHeight) 80 80 crossoverPoints.Add(possiblePoint); 81 81 }
Note: See TracChangeset
for help on using the changeset viewer.