Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5529


Ignore:
Timestamp:
02/21/11 17:49:23 (13 years ago)
Author:
gkronber
Message:

#1418 Removed grammar specific members from ISymbolicExpressionTreeNode interface.

Location:
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/ArgumentCreater.cs

    r5510 r5529  
    180180          subtree.Grammar.SetMinSubtreeCount(matchingSymbol, defunBranch.NumberOfArguments);
    181181          subtree.Grammar.SetMaxSubtreeCount(matchingSymbol, defunBranch.NumberOfArguments);
    182           foreach (var child in subtree.GetAllowedSymbols(0)) {
     182          foreach (var child in subtree.Grammar.GetAllowedSymbols(subtree.Symbol, 0)) {
    183183            for (int i = 0; i < subtree.Grammar.GetMaxSubtreeCount(matchingSymbol); i++) {
    184184              subtree.Grammar.SetAllowedChild(matchingSymbol, child, i);
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/ArgumentDuplicater.cs

    r5510 r5529  
    124124          subtree.Grammar.SetMinSubtreeCount(matchingInvokeSymbol, selectedDefunBranch.NumberOfArguments);
    125125          subtree.Grammar.SetMaxSubtreeCount(matchingInvokeSymbol, selectedDefunBranch.NumberOfArguments);
    126           foreach (var child in subtree.GetAllowedSymbols(0)) {
     126          foreach (var child in subtree.Grammar.GetAllowedSymbols(subtree.Symbol, 0)) {
    127127            for (int i = 0; i < subtree.Grammar.GetMaxSubtreeCount(matchingInvokeSymbol); i++) {
    128128              subtree.Grammar.SetAllowedChild(matchingInvokeSymbol, child, i);
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/SubroutineDeleter.cs

    r5510 r5529  
    9191        // deletion by random regeneration
    9292        ISymbolicExpressionTreeNode replacementTree = null;
    93         var allowedSymbolsList = invocationCutPoint.Parent.GetAllowedSymbols(invocationCutPoint.ReplacedChildIndex).ToList();
     93        var allowedSymbolsList = invocationCutPoint.Parent.Grammar.GetAllowedSymbols(invocationCutPoint.Parent.Symbol, invocationCutPoint.ReplacedChildIndex).ToList();
    9494        var weights = allowedSymbolsList.Select(s => s.InitialFrequency);
    9595        var selectedSymbol = allowedSymbolsList.SelectRandom(weights, random);
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/ProbabilisticTreeCreator.cs

    r5521 r5529  
    216216      int argumentIndex, int maxFunctionDefinitions, int maxFunctionArguments) {
    217217      // determine possible symbols that will lead to the smallest possible tree
    218       var possibleSymbols = (from s in parent.GetAllowedSymbols(argumentIndex)
     218      var possibleSymbols = (from s in parent.Grammar.GetAllowedSymbols(parent.Symbol, argumentIndex)
    219219                             group s by parent.Grammar.GetMinExpressionLength(s) into g
    220220                             orderby g.Key
     
    227227      parent.InsertSubTree(argumentIndex, tree);
    228228      InitializeNewTreeNode(random, root, tree, maxFunctionDefinitions, maxFunctionArguments);
    229       for (int i = 0; i < tree.GetMinSubtreeCount(); i++) {
     229      for (int i = 0; i < tree.Grammar.GetMinSubtreeCount(tree.Symbol); i++) {
    230230        // insert a dummy sub-tree and add the pending extension to the list
    231231        var dummy = new SymbolicExpressionTreeNode();
     
    285285    private static int SampleArity(IRandom random, ISymbolicExpressionTreeNode node, int targetSize) {
    286286      // select actualArity randomly with the constraint that the sub-trees in the minimal arity can become large enough
    287       int minArity = node.GetMinSubtreeCount();
    288       int maxArity = node.GetMaxSubtreeCount();
     287      int minArity = node.Grammar.GetMinSubtreeCount(node.Symbol);
     288      int maxArity = node.Grammar.GetMaxSubtreeCount(node.Symbol);
    289289      if (maxArity > targetSize) {
    290290        maxArity = targetSize;
     
    294294      long aggregatedLongestExpressionLength = 0;
    295295      for (int i = 0; i < maxArity; i++) {
    296         aggregatedLongestExpressionLength += (from s in node.GetAllowedSymbols(i)
     296        aggregatedLongestExpressionLength += (from s in node.Grammar.GetAllowedSymbols(node.Symbol, i)
    297297                                              select node.Grammar.GetMaxExpressionLength(s)).Max();
    298298        if (aggregatedLongestExpressionLength < targetSize) minArity = i;
     
    304304      long aggregatedShortestExpressionLength = 0;
    305305      for (int i = 0; i < maxArity; i++) {
    306         aggregatedShortestExpressionLength += (from s in node.GetAllowedSymbols(i)
     306        aggregatedShortestExpressionLength += (from s in node.Grammar.GetAllowedSymbols(node.Symbol, i)
    307307                                               select node.Grammar.GetMinExpressionLength(s)).Min();
    308308        if (aggregatedShortestExpressionLength > targetSize) {
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/DefaultSymbolicExpressionGrammar.cs

    r5510 r5529  
    229229    }
    230230
     231    public IEnumerable<ISymbol> GetAllowedSymbols(ISymbol parent, int argumentIndex) {
     232      return allowedChildSymbols[parent.Name][argumentIndex].Select(x => allSymbols[x]);
     233    }
     234
    231235    private Dictionary<string, int> cachedMinExpressionLength;
    232236    public int GetMinExpressionLength(ISymbol symbol) {
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionTreeGrammar.cs

    r5519 r5529  
    3434    bool IsAllowedChild(ISymbol parent, ISymbol child, int argumentIndex);
    3535
     36    IEnumerable<ISymbol> GetAllowedSymbols(ISymbol parent, int argumentIndex);
     37
    3638    int GetMinExpressionLength(ISymbol start);
    3739    int GetMaxExpressionLength(ISymbol start);
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionTreeNode.cs

    r5510 r5529  
    2929    ISymbol Symbol { get; }
    3030    bool HasLocalParameters { get; }
    31     IEnumerable<ISymbol> GetAllowedSymbols(int argumentIndex);
    3231
    3332    int GetHeight();
    3433    int GetSize();
    35     int GetMinSubtreeCount();
    36     int GetMaxSubtreeCount();
    3734
    3835    IEnumerable<ISymbolicExpressionTreeNode> IterateNodesPostfix();
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/ChangeNodeTypeManipulation.cs

    r5510 r5529  
    5454      int subTreeCount = manipulationPoint.Node.SubTrees.Count();
    5555      // find possible symbols for the node (also considering the existing branches below it)
    56       var allowedSymbols = from symbol in manipulationPoint.Parent.GetAllowedSymbols(manipulationPoint.Index)
     56      var allowedSymbols = from symbol in manipulationPoint.Parent.Grammar.GetAllowedSymbols(manipulationPoint.Parent.Symbol, manipulationPoint.Index)
    5757                           where subTreeCount <= manipulationPoint.Node.Grammar.GetMaxSubtreeCount(symbol)
    5858                           where subTreeCount >= manipulationPoint.Node.Grammar.GetMinSubtreeCount(symbol)
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Manipulators/ReplaceBranchManipulation.cs

    r5499 r5529  
    7979      int maxDepth = maxTreeDepth - symbolicExpressionTree.Height + manipulationPoint.Node.GetHeight();
    8080      // find possible symbols for the node (also considering the existing branches below it)
    81       var allowedSymbols = (from symbol in manipulationPoint.Parent.GetAllowedSymbols(manipulationPoint.Index)
     81      var allowedSymbols = (from symbol in manipulationPoint.Parent.Grammar.GetAllowedSymbols(manipulationPoint.Parent.Symbol, manipulationPoint.Index)
    8282                            where manipulationPoint.Node.Grammar.GetMinExpressionDepth(symbol) <= maxDepth
    8383                            where manipulationPoint.Node.Grammar.GetMinExpressionLength(symbol) <= maxLength
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeNode.cs

    r5510 r5529  
    178178    }
    179179
    180     public IEnumerable<ISymbol> GetAllowedSymbols(int argumentIndex) {
    181       return Grammar.Symbols.Where(s => Grammar.IsAllowedChild(Symbol, s, argumentIndex));
    182     }
    183 
    184     public int GetMinSubtreeCount() {
    185       return Grammar.GetMinSubtreeCount(Symbol);
    186     }
    187     public int GetMaxSubtreeCount() {
    188       return Grammar.GetMaxSubtreeCount(Symbol);
    189     }
    190180    public override string ToString() {
    191181      return Symbol.Name;
Note: See TracChangeset for help on using the changeset viewer.