Changeset 5733 for branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers
- Timestamp:
- 03/17/11 14:07:47 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SubtreeCrossover.cs
r5686 r5733 93 93 94 94 // calculate the max length and depth that the inserted branch can have 95 int maxInsertedBranchLength = maxTreeLength - (parent0.Length - crossoverPoint0.GetSub Tree(replacedSubtreeIndex).GetLength());95 int maxInsertedBranchLength = maxTreeLength - (parent0.Length - crossoverPoint0.GetSubtree(replacedSubtreeIndex).GetLength()); 96 96 int maxInsertedBranchDepth = maxTreeDepth - GetBranchLevel(parent0.Root, crossoverPoint0); 97 97 … … 111 111 // manipulate the tree of parent0 in place 112 112 // replace the branch in tree0 with the selected branch from tree1 113 crossoverPoint0.RemoveSub Tree(replacedSubtreeIndex);114 crossoverPoint0.InsertSub Tree(replacedSubtreeIndex, selectedBranch);113 crossoverPoint0.RemoveSubtree(replacedSubtreeIndex); 114 crossoverPoint0.InsertSubtree(replacedSubtreeIndex, selectedBranch); 115 115 return parent0; 116 116 } … … 139 139 List<CutPoint> leafCrossoverPoints = new List<CutPoint>(); 140 140 parent0.Root.ForEachNodePostfix((n) => { 141 if (n.Sub Trees.Any() && n != parent0.Root) {142 foreach (var child in n.Sub Trees) {141 if (n.Subtrees.Any() && n != parent0.Root) { 142 foreach (var child in n.Subtrees) { 143 143 if (child.GetLength() <= maxBranchLength && 144 144 child.GetDepth() <= maxBranchDepth) { 145 if (child.Sub Trees.Any())145 if (child.Subtrees.Any()) 146 146 internalCrossoverPoints.Add(new CutPoint(n, child)); 147 147 else … … 185 185 // select internal node if possible 186 186 allowedInternalBranches = (from branch in branches 187 where branch.Sub Trees.Any()187 where branch.Subtrees.Any() 188 188 select branch).ToList(); 189 189 if (allowedInternalBranches.Count > 0) { … … 192 192 // no internal nodes allowed => select leaf nodes 193 193 allowedLeafBranches = (from branch in branches 194 where !branch.Sub Trees.Any()194 where !branch.Subtrees.Any() 195 195 select branch).ToList(); 196 196 return allowedLeafBranches.SelectRandom(random); … … 199 199 // select leaf node if possible 200 200 allowedLeafBranches = (from branch in branches 201 where !branch.Sub Trees.Any()201 where !branch.Subtrees.Any() 202 202 select branch).ToList(); 203 203 if (allowedLeafBranches.Count > 0) { … … 205 205 } else { 206 206 allowedInternalBranches = (from branch in branches 207 where branch.Sub Trees.Any()207 where branch.Subtrees.Any() 208 208 select branch).ToList(); 209 209 return allowedInternalBranches.SelectRandom(random); … … 214 214 private static int GetBranchLevel(ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode point) { 215 215 if (root == point) return 0; 216 foreach (var subtree in root.Sub Trees) {216 foreach (var subtree in root.Subtrees) { 217 217 int branchLevel = GetBranchLevel(subtree, point); 218 218 if (branchLevel < int.MaxValue) return 1 + branchLevel;
Note: See TracChangeset
for help on using the changeset viewer.