Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/20/18 13:49:19 (7 years ago)
Author:
lkammere
Message:

#2886: Add constants to grammar.

File:
1 edited

Legend:

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

    r15834 r15849  
    4242    public TerminalSymbol Inv;
    4343
    44     // For infix notation
    45     public TerminalSymbol OpeningBracket;
    46     public TerminalSymbol ClosingBracket;
     44    public TerminalSymbol Const;
    4745
    4846    #endregion
     
    9391      Inv = new TerminalSymbol("inv");
    9492
    95       OpeningBracket = new TerminalSymbol("(");
    96       ClosingBracket = new TerminalSymbol(")");
     93      Const = new TerminalSymbol("c");
    9794      #endregion
    9895
     
    107104
    108105      productions[Expr] = new[] {
    109         new Production(Term, Expr, Addition),
    110         new Production(Term)
     106        new Production(Const, Term, Multiplication, Expr, Addition),
     107        new Production(Const, Term, Multiplication, Const, Addition)
    111108      };
    112109
     
    126123
    127124      productions[LogFactor] = new[] { new Production(SimpleExpr, Log) };
    128       productions[ExpFactor] = new[] { new Production(SimpleTerm, Exp) };
     125      productions[ExpFactor] = new[] { new Production(Const, SimpleTerm, Multiplication, Exp) };
    129126      productions[SinFactor] = new[] { new Production(SimpleExpr, Sin) };
    130127      productions[CosFactor] = new[] { new Production(SimpleExpr, Cos) };
    131128
    132129      productions[SimpleExpr] = new[] {
    133         new Production(SimpleTerm, SimpleExpr, Addition),
    134         new Production(SimpleTerm)
     130        new Production(Const, SimpleTerm, Multiplication, SimpleExpr, Addition),
     131        new Production(Const, SimpleTerm, Multiplication, Const, Addition)
    135132      };
    136133
     
    141138
    142139      productions[InvExpr] = new[] {
    143         new Production(InvTerm, InvExpr, Addition),
    144         new Production(InvTerm)
     140        new Production(Const, InvTerm, Multiplication, InvExpr, Addition),
     141        new Production(Const, InvTerm, Multiplication, Const, Addition)
    145142      };
    146143
     
    206203      if (currentSymbol == Addition) {
    207204        parsedSubTree = addSy.CreateTreeNode();
    208         parsedSubTree.AddSubtree(ParseSymbolicExpressionTree(parseStack)); // left part
    209         parsedSubTree.AddSubtree(ParseSymbolicExpressionTree(parseStack)); // right part
     205        ISymbolicExpressionTreeNode rightSubtree = ParseSymbolicExpressionTree(parseStack);
     206        if (rightSubtree is ConstantTreeNode) {
     207          ((ConstantTreeNode)rightSubtree).Value = 0.0;
     208        }
     209        parsedSubTree.AddSubtree(rightSubtree); // left part
     210
     211        ISymbolicExpressionTreeNode leftSubtree = ParseSymbolicExpressionTree(parseStack);
     212        if (leftSubtree is ConstantTreeNode) {
     213          ((ConstantTreeNode)leftSubtree).Value = 0.0;
     214        }
     215        parsedSubTree.AddSubtree(leftSubtree); // right part
    210216
    211217      } else if (currentSymbol == Multiplication) {
     
    236242        parsedSubTree.AddSubtree(dividend);
    237243        parsedSubTree.AddSubtree(ParseSymbolicExpressionTree(parseStack));
     244
     245      } else if (currentSymbol == Const) {
     246        ConstantTreeNode constNode = (ConstantTreeNode)constSy.CreateTreeNode();
     247        constNode.Value = 1.0;
     248        parsedSubTree = constNode;
    238249
    239250      } else if (currentSymbol is VariableTerminalSymbol) {
Note: See TracChangeset for help on using the changeset viewer.