Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15817


Ignore:
Timestamp:
02/26/18 14:13:38 (7 years ago)
Author:
lkammere
Message:

#2886: Add cosine to grammar.

File:
1 edited

Legend:

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

    r15812 r15817  
    2222    public NonterminalSymbol ExpFactor;
    2323    public NonterminalSymbol SinFactor;
     24    public NonterminalSymbol CosFactor;
    2425
    2526    public NonterminalSymbol SimpleExpr;
     
    3435    public TerminalSymbol Exp;
    3536    public TerminalSymbol Sin;
     37    public TerminalSymbol Cos;
    3638    public TerminalSymbol Inv;
    3739
     
    5456    private ISymbol divSy;
    5557    private ISymbol sinSy;
    56 
     58    private ISymbol cosSy;
     59   
    5760    private ISymbol rootSy;
    5861    private ISymbol startSy;
     
    6972      ExpFactor = new NonterminalSymbol("ExpFactor");
    7073      SinFactor = new NonterminalSymbol("SinFactor");
    71 
     74      CosFactor = new NonterminalSymbol("CosFactor");
     75         
    7276      SimpleExpr = new NonterminalSymbol("SimpleExpr");
    7377      SimpleTerm = new NonterminalSymbol("SimpleTerm");
     
    8185      Exp = new TerminalSymbol("exp");
    8286      Sin = new TerminalSymbol("sin");
     87      Cos = new TerminalSymbol("cos");
    8388      Inv = new TerminalSymbol("inv");
    8489
     
    101106      Factor.AddProduction(ExpFactor);
    102107      Factor.AddProduction(SinFactor);
     108      Factor.AddProduction(CosFactor);
    103109
    104110      LogFactor.AddProduction(SimpleExpr, Log);
    105111      ExpFactor.AddProduction(SimpleTerm, Exp);
    106112      SinFactor.AddProduction(SimpleExpr, Sin);
     113      CosFactor.AddProduction(SimpleExpr, Cos);
    107114
    108115      SimpleExpr.AddProduction(SimpleTerm, SimpleExpr, Addition);
     
    131138      divSy = symbolicExpressionGrammar.Symbols.OfType<Division>().First();
    132139      sinSy = symbolicExpressionGrammar.Symbols.OfType<Sine>().First();
     140      cosSy = symbolicExpressionGrammar.Symbols.OfType<Cosine>().First();
    133141
    134142      rootSy = symbolicExpressionGrammar.Symbols.OfType<ProgramRootSymbol>().First();
     
    223231      // LOG, EXP, SIN, INV
    224232      if (ReferenceEquals(currentSymbol, Log) || ReferenceEquals(currentSymbol, Exp) ||
    225           ReferenceEquals(currentSymbol, Sin) || ReferenceEquals(currentSymbol, Inv)) {
     233          ReferenceEquals(currentSymbol, Sin) || ReferenceEquals(currentSymbol, Cos) ||
     234          ReferenceEquals(currentSymbol, Inv)) {
    226235        return new[] { aggregateHashes(parseStack.Peek(), GetSubtreeHashes(parseStack, aggregateHashes)) };
    227236      }
     
    308317        parsedSubTree.AddSubtree(ParseSymbolicExpressionTree(parseStack));
    309318
     319      } else if (ReferenceEquals(currentSymbol, Cos)) {
     320        parsedSubTree = cosSy.CreateTreeNode();
     321        parsedSubTree.AddSubtree(ParseSymbolicExpressionTree(parseStack));
     322
    310323      } else if (ReferenceEquals(currentSymbol, Inv)) {
    311324        parsedSubTree = divSy.CreateTreeNode();
     
    350363
    351364      } else if (ReferenceEquals(head, Log) || ReferenceEquals(head, Exp)
    352               || ReferenceEquals(head, Sin) || ReferenceEquals(head, Inv)) {
     365              || ReferenceEquals(head, Sin) || ReferenceEquals(head, Cos)
     366              || ReferenceEquals(head, Inv)) {
    353367        result.Add(head);
    354368        result.Add(OpeningBracket);
Note: See TracChangeset for help on using the changeset viewer.