Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/28/11 17:18:49 (13 years ago)
Author:
bburlacu
Message:

#1682: Fixed a bug affecting the new crossovers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/gp-crossover/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Crossovers/SymbolicDataAnalysisExpressionContextAwareCrossover.cs

    r7075 r7089  
    3333
    3434  [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 {
    3736    [StorableConstructor]
    3837    private SymbolicDataAnalysisExpressionContextAwareCrossover(bool deserializing) : base(deserializing) { }
     
    4544    public override IDeepCloneable Clone(Cloner cloner) {
    4645      return new SymbolicDataAnalysisExpressionContextAwareCrossover<T>(this, cloner);
    47     } 
     46    }
    4847    protected override ISymbolicExpressionTree Cross(IRandom random, ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1) {
    4948      if (this.ExecutionContext == null)
     
    6362      List<CutPoint> crossoverPoints0 = new List<CutPoint>();
    6463      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)
    6766            crossoverPoints0.Add(new CutPoint(n, child));
    6867      });
     
    7372      List<ISymbolicExpressionTreeNode> allowedBranches = new List<ISymbolicExpressionTreeNode>();
    7473      parent1.Root.ForEachNodePostfix((n) => {
    75         if (n.Subtrees.Any() && n != parent1.Root) 
     74        if (n.Subtrees.Any() && n != parent1.Root)
    7675          foreach (var child in n.Subtrees)
    7776            if (crossoverPoint0.IsMatchingPointType(child) && (child.GetDepth() + level <= maxDepth) && (child.GetLength() + length <= maxLength))
    78               allowedBranches.Add(n);
     77              allowedBranches.Add(child);
    7978      });
    8079
     
    8281      if (crossoverPoint0.IsMatchingPointType(null)) allowedBranches.Add(null);
    8382
    84       if (allowedBranches.Count == 0) 
     83      if (allowedBranches.Count == 0)
    8584        return parent0;
    8685
     
    9089      ISymbolicExpressionTreeNode selectedBranch = null;
    9190
    92       var nodeQualities = new List<Tuple<ISymbolicExpressionTreeNode,double>>();
     91      var nodeQualities = new List<Tuple<ISymbolicExpressionTreeNode, double>>();
    9392
    9493      foreach (var node in allowedBranches) {
Note: See TracChangeset for help on using the changeset viewer.