Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/16/11 15:07:36 (12 years ago)
Author:
ascheibe
Message:

#1659 updated branch from trunk

Location:
branches/Benchmarking
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/Benchmarking

  • branches/Benchmarking/sources

  • branches/Benchmarking/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/FullTreeCreator.cs

    r6888 r7000  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.ComponentModel;
    2523using System.Linq;
    2624using HeuristicLab.Common;
     
    133131        throw new ArgumentException("Cannot create trees of depth " + maxDepth + " or smaller because of grammar constraints.", "maxDepth");
    134132
    135       var possibleSymbols = seedNode.Grammar.GetAllowedChildSymbols(seedNode.Symbol).Where(s => s.InitialFrequency > 0.0 && seedNode.Grammar.GetMaximumSubtreeCount(s) > 0).ToList();
    136133
    137134      int arity = seedNode.Grammar.GetMaximumSubtreeCount(seedNode.Symbol);
    138135      // Throw an exception if the seedNode happens to be a terminal, since in this case we cannot grow a tree.
    139136      if (arity <= 0)
    140         throw new ArgumentException("Cannot grow tree. Seed node shouldn't have arity zero."); 
     137        throw new ArgumentException("Cannot grow tree. Seed node shouldn't have arity zero.");
    141138
    142139      for (var i = 0; i != arity; ++i) {
     140        var possibleSymbols = seedNode.Grammar.GetAllowedChildSymbols(seedNode.Symbol,i).Where(s => s.InitialFrequency > 0.0 && seedNode.Grammar.GetMaximumSubtreeCount(s) > 0);
    143141        var selectedSymbol = possibleSymbols.SelectRandom(random);
    144142        var tree = selectedSymbol.CreateTreeNode();
     
    149147      // Only iterate over the non-terminal nodes (those which have arity > 0)
    150148      // Start from depth 2 since the first two levels are formed by the rootNode and the seedNode
    151       foreach (var subTree in seedNode.Subtrees.Where(subTree => subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) != 0)) 
     149      foreach (var subTree in seedNode.Subtrees.Where(subTree => subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) != 0))
    152150        RecursiveGrowFull(random, subTree, 2, maxDepth);
    153151    }
     
    159157        throw new ArgumentException("Cannot grow node of arity zero. Expected a function node.");
    160158
    161       var possibleSymbols = currentDepth < maxDepth ?
    162         root.Grammar.GetAllowedChildSymbols(root.Symbol).Where(s => s.InitialFrequency > 0.0 && root.Grammar.GetMaximumSubtreeCount(s) > 0).ToList() :
    163         root.Grammar.GetAllowedChildSymbols(root.Symbol).Where(s => s.InitialFrequency > 0.0 && root.Grammar.GetMaximumSubtreeCount(s) == 0).ToList();
    164159
    165160      for (var i = 0; i != arity; ++i) {
     161        var possibleSymbols = currentDepth < maxDepth ?
     162          root.Grammar.GetAllowedChildSymbols(root.Symbol,i).Where(s => s.InitialFrequency > 0.0 && root.Grammar.GetMaximumSubtreeCount(s) > 0) :
     163          root.Grammar.GetAllowedChildSymbols(root.Symbol,i).Where(s => s.InitialFrequency > 0.0 && root.Grammar.GetMaximumSubtreeCount(s) == 0);
    166164        var selectedSymbol = possibleSymbols.SelectRandom(random);
    167165        var tree = selectedSymbol.CreateTreeNode();
Note: See TracChangeset for help on using the changeset viewer.