Changeset 5549 for branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SubtreeCrossover.cs
- Timestamp:
- 02/22/11 19:04:54 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SubtreeCrossover.cs
r5510 r5549 86 86 public static ISymbolicExpressionTree Cross(IRandom random, 87 87 ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1, 88 double internalCrossoverPointProbability, int maxTree Size, int maxTreeHeight) {88 double internalCrossoverPointProbability, int maxTreeLength, int maxTreeDepth) { 89 89 // select a random crossover point in the first parent 90 90 ISymbolicExpressionTreeNode crossoverPoint0; 91 91 int replacedSubtreeIndex; 92 SelectCrossoverPoint(random, parent0, internalCrossoverPointProbability, maxTree Size, maxTreeHeight, out crossoverPoint0, out replacedSubtreeIndex);93 94 // calculate the max size and heightthat the inserted branch can have95 int maxInsertedBranch Size = maxTreeSize - (parent0.Size - crossoverPoint0.GetSubTree(replacedSubtreeIndex).GetSize());96 int maxInsertedBranch Height = maxTreeHeight- GetBranchLevel(parent0.Root, crossoverPoint0);92 SelectCrossoverPoint(random, parent0, internalCrossoverPointProbability, maxTreeLength, maxTreeDepth, out crossoverPoint0, out replacedSubtreeIndex); 93 94 // calculate the max length and depth that the inserted branch can have 95 int maxInsertedBranchLength = maxTreeLength - (parent0.Length - crossoverPoint0.GetSubTree(replacedSubtreeIndex).GetLength()); 96 int maxInsertedBranchDepth = maxTreeDepth - GetBranchLevel(parent0.Root, crossoverPoint0); 97 97 98 98 List<ISymbolicExpressionTreeNode> allowedBranches = new List<ISymbolicExpressionTreeNode>(); 99 99 parent1.Root.ForEachNodePostfix((n) => { 100 if (n.Get Size() <= maxInsertedBranchSize&&101 n.Get Height() <= maxInsertedBranchHeight&&100 if (n.GetLength() <= maxInsertedBranchLength && 101 n.GetDepth() <= maxInsertedBranchDepth && 102 102 IsMatchingPointType(crossoverPoint0, replacedSubtreeIndex, n)) 103 103 allowedBranches.Add(n); … … 134 134 } 135 135 136 private static void SelectCrossoverPoint(IRandom random, ISymbolicExpressionTree parent0, double internalNodeProbability, int maxBranch Size, int maxBranchHeight, out ISymbolicExpressionTreeNode crossoverPoint, out int subtreeIndex) {136 private static void SelectCrossoverPoint(IRandom random, ISymbolicExpressionTree parent0, double internalNodeProbability, int maxBranchLength, int maxBranchDepth, out ISymbolicExpressionTreeNode crossoverPoint, out int subtreeIndex) { 137 137 if (internalNodeProbability < 0.0 || internalNodeProbability > 1.0) throw new ArgumentException("internalNodeProbability"); 138 138 List<CrossoverPoint> internalCrossoverPoints = new List<CrossoverPoint>(); … … 141 141 if (n.SubTrees.Count() > 0 && n != parent0.Root) { 142 142 foreach (var child in n.SubTrees) { 143 if (child.Get Size() <= maxBranchSize&&144 child.Get Height() <= maxBranchHeight) {143 if (child.GetLength() <= maxBranchLength && 144 child.GetDepth() <= maxBranchDepth) { 145 145 if (child.SubTrees.Count() > 0) 146 146 internalCrossoverPoints.Add(new CrossoverPoint(n, child));
Note: See TracChangeset
for help on using the changeset viewer.