Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/17/11 14:07:47 (13 years ago)
Author:
mkommend
Message:

#1418: Corrected problem interfaces & unified naming of subtrees.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SubtreeCrossover.cs

    r5686 r5733  
    9393
    9494      // calculate the max length and depth that the inserted branch can have
    95       int maxInsertedBranchLength = maxTreeLength - (parent0.Length - crossoverPoint0.GetSubTree(replacedSubtreeIndex).GetLength());
     95      int maxInsertedBranchLength = maxTreeLength - (parent0.Length - crossoverPoint0.GetSubtree(replacedSubtreeIndex).GetLength());
    9696      int maxInsertedBranchDepth = maxTreeDepth - GetBranchLevel(parent0.Root, crossoverPoint0);
    9797
     
    111111        // manipulate the tree of parent0 in place
    112112        // replace the branch in tree0 with the selected branch from tree1
    113         crossoverPoint0.RemoveSubTree(replacedSubtreeIndex);
    114         crossoverPoint0.InsertSubTree(replacedSubtreeIndex, selectedBranch);
     113        crossoverPoint0.RemoveSubtree(replacedSubtreeIndex);
     114        crossoverPoint0.InsertSubtree(replacedSubtreeIndex, selectedBranch);
    115115        return parent0;
    116116      }
     
    139139      List<CutPoint> leafCrossoverPoints = new List<CutPoint>();
    140140      parent0.Root.ForEachNodePostfix((n) => {
    141         if (n.SubTrees.Any() && n != parent0.Root) {
    142           foreach (var child in n.SubTrees) {
     141        if (n.Subtrees.Any() && n != parent0.Root) {
     142          foreach (var child in n.Subtrees) {
    143143            if (child.GetLength() <= maxBranchLength &&
    144144                child.GetDepth() <= maxBranchDepth) {
    145               if (child.SubTrees.Any())
     145              if (child.Subtrees.Any())
    146146                internalCrossoverPoints.Add(new CutPoint(n, child));
    147147              else
     
    185185        // select internal node if possible
    186186        allowedInternalBranches = (from branch in branches
    187                                    where branch.SubTrees.Any()
     187                                   where branch.Subtrees.Any()
    188188                                   select branch).ToList();
    189189        if (allowedInternalBranches.Count > 0) {
     
    192192          // no internal nodes allowed => select leaf nodes
    193193          allowedLeafBranches = (from branch in branches
    194                                  where !branch.SubTrees.Any()
     194                                 where !branch.Subtrees.Any()
    195195                                 select branch).ToList();
    196196          return allowedLeafBranches.SelectRandom(random);
     
    199199        // select leaf node if possible
    200200        allowedLeafBranches = (from branch in branches
    201                                where !branch.SubTrees.Any()
     201                               where !branch.Subtrees.Any()
    202202                               select branch).ToList();
    203203        if (allowedLeafBranches.Count > 0) {
     
    205205        } else {
    206206          allowedInternalBranches = (from branch in branches
    207                                      where branch.SubTrees.Any()
     207                                     where branch.Subtrees.Any()
    208208                                     select branch).ToList();
    209209          return allowedInternalBranches.SelectRandom(random);
     
    214214    private static int GetBranchLevel(ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode point) {
    215215      if (root == point) return 0;
    216       foreach (var subtree in root.SubTrees) {
     216      foreach (var subtree in root.Subtrees) {
    217217        int branchLevel = GetBranchLevel(subtree, point);
    218218        if (branchLevel < int.MaxValue) return 1 + branchLevel;
Note: See TracChangeset for help on using the changeset viewer.