Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/18/15 13:01:38 (8 years ago)
Author:
ascheibe
Message:

#2510 merged r13227, r13235, r13236 into stable

Location:
stable
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding

  • stable/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/ProbabilisticTreeCreator.cs

    r12706 r13246  
    7474    }
    7575
     76    public static ISymbolicExpressionTree CreateExpressionTree(IRandom random, ISymbolicExpressionGrammar grammar, int targetLength,
     77      int maxTreeDepth) {
     78      SymbolicExpressionTree tree = new SymbolicExpressionTree();
     79      var rootNode = (SymbolicExpressionTreeTopLevelNode)grammar.ProgramRootSymbol.CreateTreeNode();
     80      if (rootNode.HasLocalParameters) rootNode.ResetLocalParameters(random);
     81      rootNode.SetGrammar(grammar.CreateExpressionTreeGrammar());
     82
     83      var startNode = (SymbolicExpressionTreeTopLevelNode)grammar.StartSymbol.CreateTreeNode();
     84      if (startNode.HasLocalParameters) startNode.ResetLocalParameters(random);
     85      startNode.SetGrammar(grammar.CreateExpressionTreeGrammar());
     86
     87      rootNode.AddSubtree(startNode);
     88      bool success = TryCreateFullTreeFromSeed(random, startNode, targetLength - 2, maxTreeDepth - 1);
     89      if (!success) throw new InvalidOperationException(string.Format("Could not create a tree with target length {0} and max depth {1}", targetLength, maxTreeDepth));
     90
     91      tree.Root = rootNode;
     92      return tree;
     93
     94    }
     95
    7696    private class TreeExtensionPoint {
    7797      public ISymbolicExpressionTreeNode Parent { get; set; }
     
    107127        } else {
    108128          // clean seedNode
    109           while (seedNode.Subtrees.Count() > 0) seedNode.RemoveSubtree(0);
     129          while (seedNode.Subtrees.Any()) seedNode.RemoveSubtree(0);
    110130        }
    111131        // try a different length MAX_TRIES times
Note: See TracChangeset for help on using the changeset viewer.