Changeset 7089 for branches/gp-crossover/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionContextAwareCrossover.cs
- Timestamp:
- 11/28/11 17:18:49 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/gp-crossover/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionContextAwareCrossover.cs
r7075 r7089 33 33 34 34 [Item("ContextAwareCrossover", "An operator which performs subtree swapping in a deterministic way: it checks all possible cross points in the second parent with the aim of creating the best possible offspring.")] 35 public sealed class SymbolicDataAnalysisExpressionContextAwareCrossover<T> : SymbolicDataAnalysisExpressionCrossover<T> where T : class, IDataAnalysisProblemData 36 { 35 public sealed class SymbolicDataAnalysisExpressionContextAwareCrossover<T> : SymbolicDataAnalysisExpressionCrossover<T> where T : class, IDataAnalysisProblemData { 37 36 [StorableConstructor] 38 37 private SymbolicDataAnalysisExpressionContextAwareCrossover(bool deserializing) : base(deserializing) { } … … 45 44 public override IDeepCloneable Clone(Cloner cloner) { 46 45 return new SymbolicDataAnalysisExpressionContextAwareCrossover<T>(this, cloner); 47 } 46 } 48 47 protected override ISymbolicExpressionTree Cross(IRandom random, ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1) { 49 48 if (this.ExecutionContext == null) … … 63 62 List<CutPoint> crossoverPoints0 = new List<CutPoint>(); 64 63 parent0.Root.ForEachNodePostfix((n) => { 65 if (n.Subtrees.Any() && n != parent0.Root) 66 foreach (var child in n.Subtrees) 64 if (n.Subtrees.Any() && n != parent0.Root) 65 foreach (var child in n.Subtrees) 67 66 crossoverPoints0.Add(new CutPoint(n, child)); 68 67 }); … … 73 72 List<ISymbolicExpressionTreeNode> allowedBranches = new List<ISymbolicExpressionTreeNode>(); 74 73 parent1.Root.ForEachNodePostfix((n) => { 75 if (n.Subtrees.Any() && n != parent1.Root) 74 if (n.Subtrees.Any() && n != parent1.Root) 76 75 foreach (var child in n.Subtrees) 77 76 if (crossoverPoint0.IsMatchingPointType(child) && (child.GetDepth() + level <= maxDepth) && (child.GetLength() + length <= maxLength)) 78 allowedBranches.Add( n);77 allowedBranches.Add(child); 79 78 }); 80 79 … … 82 81 if (crossoverPoint0.IsMatchingPointType(null)) allowedBranches.Add(null); 83 82 84 if (allowedBranches.Count == 0) 83 if (allowedBranches.Count == 0) 85 84 return parent0; 86 85 … … 90 89 ISymbolicExpressionTreeNode selectedBranch = null; 91 90 92 var nodeQualities = new List<Tuple<ISymbolicExpressionTreeNode, double>>();91 var nodeQualities = new List<Tuple<ISymbolicExpressionTreeNode, double>>(); 93 92 94 93 foreach (var node in allowedBranches) {
Note: See TracChangeset
for help on using the changeset viewer.