Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/05/15 07:03:15 (10 years ago)
Author:
gkronber
Message:

#2283: constant opt, expressioncompiler, autodiff, fixes in GP solvers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Problems.GrammaticalOptimization/ExpressionInterpreter.cs

    r11848 r11895  
    1717    // interprets sentences from L(G(Expr)):
    1818    // Expr -> Term { ('+' | '-' | '^' ) Term }
    19     // Term -> Fact { ('*' | '/') Fact }
     19    // Term -> Fact { ('*' | '%') Fact }
    2020    // Fact -> '!' Expr | '(' Expr ')' | Var | const
    2121    // Var -> 'a'..'z'
    2222    // const -> '0' .. '9'
    2323
     24    // uses protected division symbol %
    2425    // constants are Koza-style ephemeral random constants (ERC). for now we only allow up to 10 constants.
    2526    // The constant symbols '0' .. '9' are treated as ERC indices
     
    3536      var d = new double[vars.Length];
    3637      for (int i = 0; i < vars.Length; i++) d[i] = vars[i] ? 1.0 : 0.0;
    37       return ! DoubleExtensions.IsAlmost(Expr(d, erc), 0);
     38      return !DoubleExtensions.IsAlmost(Expr(d, erc), 0);
    3839    }
    3940
     
    7374        if (curSy == '+') {
    7475          NewSy();
    75           r += Expr(d, erc);
     76          r += Term(d, erc);
    7677        } else if (curSy == '-') {
    7778          NewSy();
    78           r -= Expr(d, erc);
     79          r -= Term(d, erc);
    7980        } else {
    8081          NewSy();
    81           var e = Expr(d, erc);
    82           r = Not(r) * e + r * Not(e); // xor = (!x AND y) OR (x AND !y)
     82          throw new NotImplementedException();
     83          // var e = Expr(d, erc);
     84          // r = Not(r) * e + r * Not(e); // xor = (!x AND y) OR (x AND !y)
    8385        }
    8486        curSy = CurSy();
     
    9193      r = Fact(d, erc);
    9294      var curSy = CurSy();
    93       while (curSy == '*' || curSy == '/') {
     95      while (curSy == '*' || curSy == '%') {
    9496        if (curSy == '*') {
    9597          NewSy();
    96           r *= Term(d, erc);
     98          r *= Fact(d, erc);
    9799        } else {
    98100          NewSy();
    99           r /= Term(d, erc);
     101          var nom = Fact(d, erc);
     102          if (HeuristicLab.Common.Extensions.IsAlmost(nom, 0.0)) nom = 1.0;
     103          r /= nom;
    100104        }
    101105        curSy = CurSy();
Note: See TracChangeset for help on using the changeset viewer.