Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/09/18 15:32:44 (6 years ago)
Author:
lkammere
Message:

#2886: Refactor grammar enumeration alg.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2886_SymRegGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.SymRegGrammarEnumeration/GrammarEnumeration/Grammar.cs

    r15734 r15746  
    9090    }
    9191
    92     /*
    93     #region Memoize subtrees
    94 
    95     public void MemoizeSubtrees(SymbolString sentence) {
    96       Stack<TerminalSymbol> parseStack = new Stack<TerminalSymbol>(sentence.OfType<TerminalSymbol>());
    97 
    98       // Parse root symbol "+"
    99       MemoizeSubtreeExpression(parseStack);
    100     }
    101 
    102     private SymbolString MemoizeSubtreeExpression(Stack<TerminalSymbol> parseStack) {
    103       SymbolString subtree = new SymbolString();
    104 
    105       if (ReferenceEquals(parseStack.Peek(), Addition)) {
    106         subtree.Add(parseStack.Pop());
    107         subtree.InsertRange(0, MemoizeSubtreeExpression(parseStack));
    108         subtree.InsertRange(0, MemoizeSubtreeTerm(parseStack));
    109 
    110         Expr.Alternatives[0].GeneratedSentences.Add(subtree);
    111       } else {
    112         subtree.InsertRange(0, MemoizeSubtreeTerm(parseStack));
    113 
    114         Expr.Alternatives[1].GeneratedSentences.Add(subtree);
    115       }
    116 
    117       return subtree;
    118     }
    119 
    120     private SymbolString MemoizeSubtreeTerm(Stack<TerminalSymbol> parseStack) {
    121       SymbolString subtree = new SymbolString();
    122 
    123       if (ReferenceEquals(parseStack.Peek(), Multiplication)) {
    124         subtree.Add(parseStack.Pop());
    125         subtree.InsertRange(0, MemoizeSubtreeTerm(parseStack));
    126         subtree.InsertRange(0, MemoizeSubtreeFactor(parseStack));
    127 
    128         Term.Alternatives[0].GeneratedSentences.Add(subtree);
    129       } else {
    130         subtree.InsertRange(0, MemoizeSubtreeFactor(parseStack));
    131 
    132         Term.Alternatives[1].GeneratedSentences.Add(subtree);
    133       }
    134 
    135       return subtree;
    136     }
    137 
    138     private SymbolString MemoizeSubtreeFactor(Stack<TerminalSymbol> parseStack) {
    139       SymbolString subtree = new SymbolString(MemoizeSubtreeVar(parseStack));
    140 
    141       Factor.Alternatives[0].GeneratedSentences.Add(subtree);
    142       return subtree;
    143     }
    144 
    145     private SymbolString MemoizeSubtreeVar(Stack<TerminalSymbol> parseStack) {
    146       SymbolString subtree = new SymbolString(parseStack.Pop().ToEnumerable());
    147 
    148       // ... not really
    149       //Var.Alternatives[0].GeneratedSentences.Add(subtree);
    150       return subtree;
    151     }
    152 
    153 
    154     #endregion
    155     */
    156 
    15792    #region Hashing
    15893    public int CalcHashCode(SymbolString sentence) {
     
    221156      }
    222157
    223       // var
     158      // var or nonterminal symbol
    224159      return currentSymbol.StringRepresentation.GetHashCode().ToEnumerable().ToArray();
    225 
    226 
    227       // throw new ArgumentException("Trying to hash malformed sentence!");
    228160    }
    229161
Note: See TracChangeset for help on using the changeset viewer.