- Timestamp:
- 06/30/10 15:26:36 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Crossovers/SubtreeCrossover.cs
r3462 r3989 67 67 int maxInsertedBranchHeight = maxTreeHeight - GetBranchLevel(parent0.Root, crossoverPoint0); 68 68 69 var allowedBranches = (from branch in parent1.Root.IterateNodesP refix()69 var allowedBranches = (from branch in parent1.Root.IterateNodesPostfix() 70 70 where branch.GetSize() < maxInsertedBranchSize 71 71 where branch.GetHeight() < maxInsertedBranchHeight … … 103 103 104 104 private static void SelectCrossoverPoint(IRandom random, SymbolicExpressionTree parent0, double internalNodeProbability, int maxBranchSize, int maxBranchHeight, out SymbolicExpressionTreeNode crossoverPoint, out int subtreeIndex) { 105 var crossoverPoints = from branch in parent0.Root.IterateNodesPrefix()106 where branch.SubTrees.Count > 0107 where branch != parent0.Root108 where branch.GetSize() < maxBranchSize109 where branch.GetHeight() < maxBranchHeight110 from index in Enumerable.Range(0, branch.SubTrees.Count)111 let p = new { CrossoverPoint = branch, SubtreeIndex = index, IsLeaf = branch.SubTrees[index].SubTrees.Count == 0 }112 select p;105 var crossoverPoints = (from branch in parent0.Root.IterateNodesPostfix() 106 where branch.SubTrees.Count > 0 107 where branch != parent0.Root 108 where branch.GetSize() < maxBranchSize 109 where branch.GetHeight() < maxBranchHeight 110 from index in Enumerable.Range(0, branch.SubTrees.Count) 111 let p = new { CrossoverPoint = branch, SubtreeIndex = index, IsLeaf = branch.SubTrees[index].SubTrees.Count == 0 } 112 select p).ToList(); 113 113 var internalCrossoverPoints = (from p in crossoverPoints 114 114 where !p.IsLeaf … … 139 139 private static SymbolicExpressionTreeNode SelectRandomBranch(IRandom random, IEnumerable<SymbolicExpressionTreeNode> branches, double internalNodeProbability) { 140 140 if (internalNodeProbability < 0.0 || internalNodeProbability > 1.0) throw new ArgumentException("internalNodeProbability"); 141 var groupedBranches = (from branch in branches 142 group branch by branch.SubTrees.Count into g 143 select g).ToList(); 144 var allowedInternalBranches = (from g in groupedBranches 145 where g.Key > 0 146 from branch in g 141 var allowedInternalBranches = (from branch in branches 142 where branch.SubTrees.Count > 0 147 143 select branch).ToList(); 148 var allowedLeafBranches = (from g in groupedBranches 149 where g.Key == 0 150 from leaf in g 151 select leaf).ToList(); 144 var allowedLeafBranches = (from branch in branches 145 where branch.SubTrees.Count == 0 146 select branch).ToList(); 152 147 if (allowedInternalBranches.Count == 0) { 153 148 return allowedLeafBranches.SelectRandom(random);
Note: See TracChangeset
for help on using the changeset viewer.