Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/17/11 10:56:23 (14 years ago)
Author:
mkommend
Message:

#1418: Adapted ProbabilisticTreeCreator.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/ProbabilisticTreeCreator.cs

    r5686 r5727  
    113113        if (targetTreeLength <= 1 || maxDepth <= 1) return;
    114114
    115         bool success = CreateFullTreeFromSeed(random, seedNode, seedNode.Grammar, targetTreeLength, maxDepth);
     115        bool success = TryCreateFullTreeFromSeed(random, seedNode, seedNode.Grammar, targetTreeLength, maxDepth);
    116116
    117117        // if successful => check constraints and return the tree if everything looks ok       
     
    127127    }
    128128
    129     private static bool CreateFullTreeFromSeed(IRandom random, ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeGrammar globalGrammar,
    130       int targetLength, int maxDepth) {
    131       try {
    132         TryCreateFullTreeFromSeed(random, root, globalGrammar, targetLength, maxDepth);
    133         return true;
    134       }
    135       catch (ArgumentException) { return false; }
    136     }
    137 
    138     private static void TryCreateFullTreeFromSeed(IRandom random, ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeGrammar globalGrammar,
     129    private static bool TryCreateFullTreeFromSeed(IRandom random, ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeGrammar globalGrammar,
    139130      int targetLength, int maxDepth) {
    140131      List<TreeExtensionPoint> extensionPoints = new List<TreeExtensionPoint>();
     
    142133      int totalListMinLength = globalGrammar.GetMinimumExpressionLength(root.Symbol) - 1;
    143134      int actualArity = SampleArity(random, root, targetLength);
     135      if (actualArity < 0) return false;
     136
    144137      for (int i = 0; i < actualArity; i++) {
    145138        // insert a dummy sub-tree and add the pending extension to the list
     
    180173
    181174          actualArity = SampleArity(random, newTree, targetLength - currentLength);
     175          if (actualArity < 0) return false;
    182176          for (int i = 0; i < actualArity; i++) {
    183177            // insert a dummy sub-tree and add the pending extension to the list
     
    199193        ReplaceWithMinimalTree(random, root, parent, a);
    200194      }
     195      return true;
    201196    }
    202197
     
    260255        }
    261256      }
    262       if (minArity > maxArity) throw new ArgumentException();
     257      if (minArity > maxArity) return -1;
    263258      return random.Next(minArity, maxArity + 1);
    264259    }
Note: See TracChangeset for help on using the changeset viewer.