Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/22/11 19:04:54 (13 years ago)
Author:
gkronber
Message:

#1418 unified size/height vs. length/depth terminology and adapted unit tests for symbolic expression tree encoding version 3.4

File:
1 edited

Legend:

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

    r5510 r5549  
    8686    public static ISymbolicExpressionTree Cross(IRandom random,
    8787      ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1,
    88       double internalCrossoverPointProbability, int maxTreeSize, int maxTreeHeight) {
     88      double internalCrossoverPointProbability, int maxTreeLength, int maxTreeDepth) {
    8989      // select a random crossover point in the first parent
    9090      ISymbolicExpressionTreeNode crossoverPoint0;
    9191      int replacedSubtreeIndex;
    92       SelectCrossoverPoint(random, parent0, internalCrossoverPointProbability, maxTreeSize, maxTreeHeight, out crossoverPoint0, out replacedSubtreeIndex);
    93 
    94       // calculate the max size and height that the inserted branch can have
    95       int maxInsertedBranchSize = maxTreeSize - (parent0.Size - crossoverPoint0.GetSubTree(replacedSubtreeIndex).GetSize());
    96       int maxInsertedBranchHeight = maxTreeHeight - GetBranchLevel(parent0.Root, crossoverPoint0);
     92      SelectCrossoverPoint(random, parent0, internalCrossoverPointProbability, maxTreeLength, maxTreeDepth, out crossoverPoint0, out replacedSubtreeIndex);
     93
     94      // calculate the max length and depth that the inserted branch can have
     95      int maxInsertedBranchLength = maxTreeLength - (parent0.Length - crossoverPoint0.GetSubTree(replacedSubtreeIndex).GetLength());
     96      int maxInsertedBranchDepth = maxTreeDepth - GetBranchLevel(parent0.Root, crossoverPoint0);
    9797
    9898      List<ISymbolicExpressionTreeNode> allowedBranches = new List<ISymbolicExpressionTreeNode>();
    9999      parent1.Root.ForEachNodePostfix((n) => {
    100         if (n.GetSize() <= maxInsertedBranchSize &&
    101           n.GetHeight() <= maxInsertedBranchHeight &&
     100        if (n.GetLength() <= maxInsertedBranchLength &&
     101          n.GetDepth() <= maxInsertedBranchDepth &&
    102102          IsMatchingPointType(crossoverPoint0, replacedSubtreeIndex, n))
    103103          allowedBranches.Add(n);
     
    134134    }
    135135
    136     private static void SelectCrossoverPoint(IRandom random, ISymbolicExpressionTree parent0, double internalNodeProbability, int maxBranchSize, int maxBranchHeight, out ISymbolicExpressionTreeNode crossoverPoint, out int subtreeIndex) {
     136    private static void SelectCrossoverPoint(IRandom random, ISymbolicExpressionTree parent0, double internalNodeProbability, int maxBranchLength, int maxBranchDepth, out ISymbolicExpressionTreeNode crossoverPoint, out int subtreeIndex) {
    137137      if (internalNodeProbability < 0.0 || internalNodeProbability > 1.0) throw new ArgumentException("internalNodeProbability");
    138138      List<CrossoverPoint> internalCrossoverPoints = new List<CrossoverPoint>();
     
    141141        if (n.SubTrees.Count() > 0 && n != parent0.Root) {
    142142          foreach (var child in n.SubTrees) {
    143             if (child.GetSize() <= maxBranchSize &&
    144                 child.GetHeight() <= maxBranchHeight) {
     143            if (child.GetLength() <= maxBranchLength &&
     144                child.GetDepth() <= maxBranchDepth) {
    145145              if (child.SubTrees.Count() > 0)
    146146                internalCrossoverPoints.Add(new CrossoverPoint(n, child));
Note: See TracChangeset for help on using the changeset viewer.