Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/03/10 14:11:02 (14 years ago)
Author:
mkommend
Message:

Corrected SubTreeCrossover and ReplaceBranchManipulation to handle MaxExpressionDepth correctly. Additionally MaxExpressionDepth < 3 is not allowed.
(ticket #1315).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Manipulators/ReplaceBranchManipulation.cs

    r4722 r5014  
    5353                               from subtree in parent.SubTrees
    5454                               select new { Parent = parent, Node = subtree, Index = parent.SubTrees.IndexOf(subtree) }).SelectRandom(random);
     55
     56      int maxSize = maxTreeSize - symbolicExpressionTree.Size + manipulationPoint.Node.GetSize();
     57      int maxHeight = maxTreeHeight - symbolicExpressionTree.Height + manipulationPoint.Node.GetHeight();
    5558      // find possible symbols for the node (also considering the existing branches below it)
    56       var allowedSymbols = from symbol in manipulationPoint.Parent.GetAllowedSymbols(manipulationPoint.Index)
     59      var allowedSymbols = from symbol in manipulationPoint.Parent.GetAllowedSymbols(manipulationPoint.Index, maxHeight)
    5760                           select symbol;
     61      if (allowedSymbols.Count() <= 1) return;
    5862
    59       if (allowedSymbols.Count() <= 1) {
    60         return;
    61       }
    62       var oldBranch = manipulationPoint.Node;
    63       int oldBranchSize = manipulationPoint.Node.GetSize();
    64 
    65       var seedSymbol = SelectRandomSymbol(random, allowedSymbols);
    66 
    67       // replace the old node with the new node
     63      var seedSymbol = SelectRandomSymbol(random, allowedSymbols);  // replace the old node with the new node
    6864      var seedNode = seedSymbol.CreateTreeNode();
    6965      if (seedNode.HasLocalParameters)
     
    7268      manipulationPoint.Parent.RemoveSubTree(manipulationPoint.Index);
    7369      manipulationPoint.Parent.InsertSubTree(manipulationPoint.Index, seedNode);
    74       int maxSize = Math.Max(oldBranchSize, seedNode.Grammar.GetMinExpressionLength(seedNode.Symbol)) * 2;
    75       var bla = ProbabilisticTreeCreator.PTC2(random, seedNode, maxSize, maxSize, 0, 0);
     70      seedNode = ProbabilisticTreeCreator.PTC2(random, seedNode, maxSize, maxHeight, 0, 0);
    7671      success = true;
    7772    }
Note: See TracChangeset for help on using the changeset viewer.